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

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

问题描述

在我的应用程式中,我录制了一部影片,我想在影片右下方叠加我公司的网址。我用MediaRecorder录制视频,这部分没有问题,但是为视频添加文本,我不成功。我搜索并找到一些库,如ffmpeg和javaCV,让用户覆盖的视频上的文本,但我发现在Android中使用他们硬。之后找到OnPreviewFrame,返回camerapreivew的每个帧。我想在用户触摸录制按钮后获取所有帧,并使用画布绘制文本到每个帧,然后将所有这些帧保存在一起,直到录制视频停止,视频持续时间是固定和15秒。这是一个很好的解决方案吗?如果是,我应该如何实现OnPreviewFrame函数?我知道如何绘制画布,但我不知道如何将数据[]转换为位图。

解决方案

将相当重的性能明智。
我肯定建议你对ffmeg进行更深入的研究。我相信它不是那么难使用,并有简单的libs ffmeg没有喧闹与NDK。请查看此,并检查是否有您需要的功能。

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



此命令将是您要查找的内容。



要使用除ffmeg以外的其他内容,我建议您查看 MediaMetadataRetriever

  public Bitmap getFrameAtTime(long timeUs)

这个方法是可以使用的。它给你的位图来画。但仍然会是慢的地狱。我尝试使用这种方法创建gifs,一段时间后回到ffmeg。



希望它有帮助。


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 wiht this part but for adding text to the video, I wasn't successful. I searched and found some library like ffmpeg and javaCV which let user overlay a text on the video but I found using them in the android hard. 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.

解决方案

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.

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)

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.

Hope it helps.

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

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