如何在Android中的视频之上添加叠加图像或文字? [英] How can I add overlay images or text on top of videos in Android?

查看:2296
本文介绍了如何在Android中的视频之上添加叠加图像或文字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Android应用程序的mp4视频之上添加叠加图像/文字。
大多数解决方案指向FFmpeg(或appunits AndroidFFmpeg),但不稳定,维护非常复杂。
是否有一种原生的方法来使用Android SDK? (MediaCodec?MediaMuxer?)



谢谢,
Ori

解决方案>

有两种方式可以了解您的问题:


  1. 您想暂时将视频与附加信息叠加
    这可以使用标准布局流程来完成:

使用内置的 VideoView 。您可能需要将textView / imageView包装在其他布局中,以将其推送到正面:

 < VideoView 
android:layout_width =match_parent
android:layout_height =match_parent
android:id =@ + id / videoView
android:background =#00000000/>
< LinearLayout
android:layout_width =wrap_content
android:layout_height =wrap_content
android:layout_gravity =bottom | center_horizo​​ntal
android:orientation = 水平 >
< TextView
android:id =@ + id / txt
android:layout_width =wrap_content
android:layout_height =wrap_content
android:文本= 文本/>
< / LinearLayout>




  1. 您要添加额外的信息到视频本身。
    这显然要困难得多。您可以为此使用 OpenCV 。有关OpenCV + Android的信息,请访问他们的网站

更新:正如此回答 ExtractMpegFramesTest 可能对您而言很有趣


I'm trying to add overlay images/text on top of mp4 videos inside an Android application. Most solutions point to FFmpeg (or appunits AndroidFFmpeg) but isn't stable and very complicated to maintain. Is there a native way to do this using the Android SDK? (MediaCodec? MediaMuxer?)

Thank you, Ori

解决方案

There are two ways to understand your question:

  1. You want to temporarily superimpose video with additional information. This can be done using the standard layout procedure:

Use the built-in VideoView. You might need to wrap the textView /imageView in an additional layout to push it to the front:

 <VideoView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/videoView"
    android:background="#00000000"/>
 <LinearLayout
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_gravity="bottom|center_horizontal"
     android:orientation="horizontal">
     <TextView
         android:id="@+id/txt"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="Text"/>
 </LinearLayout>

  1. You want to add the additional information to the video itself. This is obviously much more difficult. You could use OpenCV for this. For information on OpenCV+Android visit their website.

Update: As pointed out in this answer, the ExtractMpegFramesTest might be interesting for you

这篇关于如何在Android中的视频之上添加叠加图像或文字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆