如何在Android中的视频之上添加叠加图像或文字? [英] How can I add overlay images or text on top of videos in Android?
问题描述
我正在尝试在Android应用程序的mp4视频之上添加叠加图像/文字。
大多数解决方案指向FFmpeg(或appunits AndroidFFmpeg),但不稳定,维护非常复杂。
是否有一种原生的方法来使用Android SDK? (MediaCodec?MediaMuxer?)
谢谢,
Ori
有两种方式可以了解您的问题:
- 您想暂时将视频与附加信息叠加。
这可以使用标准布局流程来完成:
使用内置的 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_horizontal
android:orientation = 水平 >
< TextView
android:id =@ + id / txt
android:layout_width =wrap_content
android:layout_height =wrap_content
android:文本= 文本/>
< / LinearLayout>
更新:正如此回答, 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:
- 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>
- 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屋!