如何在android中为视频添加文字? [英] how to add text to the video in android?

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

问题描述

在我的应用程序中,我录制了一个视频,我想在该视频的右下角覆盖我公司的网址.我用MediaRecorder录制视频,录制没有问题,但是在视频中添加文字我没有成功.我搜索并找到了一些库,如 FFmpeg 和 JavaCV,它们允许用户在视频上叠加文本,但我不知道是否有任何方法可以在 Android 中使用它们.之后找到 OnPreviewFrame ,它返回相机预览的每一帧.我想在用户触摸录制按钮并使用画布将文本绘制到每一帧后获取所有帧,然后将所有这些帧保存在一起,直到录制视频停止,并且视频持续时间固定为 15 秒.这是一个好的解决方案吗?如果是,我应该如何实现 OnPreviewFrame 功能?我知道如何画画布,但我不知道如何将 data[] 转换为位图.

In my app I record a video and I wanna overlay the url of my company on the right bottom of that video. I record video with MediaRecorder and there is no problem with the recording, but for adding text to the video I haven't been successful. I searched and found some library like FFmpeg and JavaCV which let user overlay a text on the video but I don't know if there is any way for using them in Android. after that found OnPreviewFrame which returns each frame of the camerapreivew. I want to get all frames after user touch record button and draw text using canvas to each frame and then save all those frame together until recording video stops, and videos duration are fix and 15 seconds. Is it a good solution? if it is, how should I implement OnPreviewFrame function? I know how to draw canvas but I don't know how to convert data[] to the bitmap.

推荐答案

使用该方法对性能的影响会很大.我绝对建议您更深入地研究 ffmeg.我相信它并没有那么难使用,而且 ffmeg 有简单的库,而无需使用 NDK.看看这个并检查是否有您需要的功能可用.

Using that method will be pretty heavy performance wise. I would definitely suggest you to take a deeper look into ffmeg. I believe that it is not that hard to use, and there are simple libs for ffmeg without hustle with NDK. Take a look at this library and check if there is function that you need available.

ffmpeg -i movie.mp4 -i logo.png -filter_complex overlay output.mp4

这个命令就是你要找的东西.

This command would be something that you are looking for.

如果你还想使用 ffmeg 以外的东西,我建议你看看 MediaMetadataRetriever

If you still want to use something else than ffmeg I would suggest you to take a look at MediaMetadataRetriever

public Bitmap getFrameAtTime (long timeUs)

您可以使用这种方法.它为您提供了可绘制的位图.但它仍然会像地狱一样缓慢.我尝试使用这种方法创建 gif,一段时间后又回到 ffmeg.

This method would be something that you could use. It gives you bitmap to draw on. But still it is going to be slow as hell. I tried do create gifs using this method, and after some time went back to ffmeg.

希望有帮助.

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

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