在Android:4.3的MediaMuxer或ffmpeg中为视频添加水印位图 [英] Adding watermark bitmap over video in android: 4.3's MediaMuxer or ffmpeg

查看:1865
本文介绍了在Android:4.3的MediaMuxer或ffmpeg中为视频添加水印位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的方案:


  • 从网络下载avi电影

  • 打开位图资源

  • 在背景中的所有框架上覆盖电影底部的该位图

  • 将视频保存在extarnal存储上

  • 视频长度通常为15秒

  • Download an avi movie from the web
  • Open a bitmap resource
  • Overlay this bitmap at the bottom of the movie on all frames in the background
  • Save the video on extarnal storage
  • The video length is 15 seconds usually

是否可以实现使用MediaMuxer?任何关于此事的信息都很高兴收到

Is this possible to achieve using MediaMuxer ? Any info on the matter is gladly received

我一直在寻找 http://bigflake.com/mediacodec/#DecodeEditEncodeTest (感谢@fadden),它说:

I've been looking to http://bigflake.com/mediacodec/#DecodeEditEncodeTest (Thanks @fadden) and it says there:


解码框架并将其复制到带有
的ByteBuffer中,glReadPixels()在Nexus 5上大约需要8ms,速度足够快到
跟踪30fps的输入速度,但将
作为PNG保存到磁盘所需的其他步骤是昂贵的(约半秒钟)

"Decoding the frame and copying it into a ByteBuffer with glReadPixels() takes about 8ms on the Nexus 5, easily fast enough to keep pace with 30fps input, but the additional steps required to save it to disk as a PNG are expensive (about half a second)"

所以几乎1秒/帧是不能接受的。从我所想的一个方法来说,将每个框架保存为PNG,打开它,添加位图叠加层,然后保存。然而,这将需要巨大的时间来完成。

So having almost 1 sec/frame is not acceptable. From what I am thinking one way would be to save each frame as PNG, open it, add the bitmap overlay on it and then save it. However this would take an enormous time to accomplish.

我想知道是否有办法做这样的事情:

I wonder if there is a way to do things like this:


  1. 从外部存储打开视频文件

  2. 开始解码

  3. 每个解码的帧将被内存中的位图叠加层更改

  4. 框架发送到编码器。

  1. Open video file from external storage
  2. Start decoding it
  3. Each decoded frame will be altered with the bitmap overlay in memory
  4. The frame is sent to an encoder.

在iOS上,我看到有一种方法可以获取原始音频+原始视频+一个图像,并将它们添加到容器中,然后编码整个事物...

On iOS I saw that there a way to take the original audio + original video + an image and add them in a container and then just encode the whole thing...

我应该切换到ffmpeg吗? ffmpeg如何稳定和兼容?我有冒险与Android 4.0+设备的兼容性问题吗?有没有办法使用ffmpeg来修饰这个?我是新来的这个领域,仍然在研究。

Should I switch to ffmpeg ? How stable and compatible is ffmpeg ? Am I risking compatibility issues with android 4.0+ devices ? Is there a way to use ffmpeg to acomplish this ? I am new to this domain and still doing research.

几年后编辑: >
自从问题结束以来已经过去了,ffmpeg在许可证方面不太容易添加到商业软件中。这是如何演变的?更新版本的Android在这个版本上能够使用默认的sdk?

Years later edit:
Years have passed since the question and ffmpeg isn't really easy to add to a commercial software in terms of license. How did this evolved? Newer versions of android are more capable on this with the default sdk?

推荐答案

我不太了解MediaMuxer,但是ffmpeg确实支持重叠功能。 FFMPEG有各种过滤器,其中一个是覆盖过滤器。我所理解的是,你想覆盖一个图像(即png)在视频上,ffmpeg肯定是一个有用的框架来完成这项工作。您可以设置输出格式,您可以设置要显示的图像的坐标。

I don't know much about the MediaMuxer but ffmpeg does support overlaying functionality. FFMPEG has various filters one of them is overlay filter. What I understand is you want to overlay an image (i.e. png) on the video, ffmpeg surely is a useful framework to do this job. You can set the output format you can set the co-ordinates of the image which is to be overplayed.

例如

ffmpeg -i input.avi -i logo.png -filter_complex 'overlay=10:main_h-overlay_h-10' output.avi

以上命令添加了overlay

Above command adds overlays logo.png on the input.avi video file in bottom left corner.

有关过滤器的更多信息,请访问以下网站,

More information about the filters is available at following website,

https://www.ffmpeg.org/ffmpeg-filters.html#overlay- 1

如果这是您的问题的解决方案,您需要等同于上述命令的C代码。您还需要看到ffmpeg的性能,因为它是一个纯软件框架。

If this is a solution to your problem you need the C code equivalent to the above command. You also need to see the performance of the ffmpeg because it a pure software framework.

希望我已经正确理解了您的问题,这有助于您。

Hope I have understood your question correctly and this helps.

这篇关于在Android:4.3的MediaMuxer或ffmpeg中为视频添加水印位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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