Adding Watermark Bitmap Over Video in Android: 4.3's Mediamuxer or Ffmpeg

Adding watermark bitmap over video in android: 4.3's MediaMuxer or 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.

E.g.

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

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

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.

Adding a image resource over video file from sd card using ffmpeg or MediaMuxer for android

I've successfully achieved what you need. While the theory is quite simple, implementation details make it very hard to get something running.

Your solution starts here:
Download halfninja's project here: https://github.com/halfninja/android-ffmpeg-x264
and follow the instructions to the letter.

Some notes:

  • it won't work with newer versions of ffmpeg, e.g. you must use the ffmpeg version the git submodule points to.
  • it won't work with newer ndks. You must install the one he's listing there (r5c).

Once you successfully compile, you'll end up with an .so lib that has a "run" method, which you can call to run ffmpeg with the same parameters it gets on the command line.

Also:

  • The code above contains a ffmpeg.c file which runs the "main" method, but uses global variables. this means that your code won't be re-entrant. Calling ffmpeg::main twice won't work. You'll have to add initialization code yourself when done, OR create a second library that dynamically loads this library in C and unloads it when done.
  • The resulting library will be big as it includes all ffmpeg component, and will bloat your apk. You'll have to change the build file to include only the ffmpeg components you need. e.g. change configure_ffmpeg to work with minimal_featureset, and --enable only the codecs you need.

EDIT:
For mp4 w/ aac use the following configure_ffmpeg file:

--enable-muxer=mp4 --enable-encoder=libx264 --enable-libx264 \
--enable-encoder=h264 --enable-decoder=h264 --enable-demuxer=h264 --enable-muxer=h264 --enable-parser=h264 \
--enable-protocol=file \
--enable-hwaccels \
--enable-demuxer=mov --enable-decoder=aac --enable-decoder=aac_latm --enable-encoder=aac --enable-parser=aac --enable-demuxer=aac --enable-bsf=aac_adtstoasc \
--enable-encoder=aac --enable-parser=aac \
--enable-decoder=mpeg4 --enable-encoder=mpeg4 --enable-parser=mpeg4video --enable-demuxer=m4v"


Related Topics



Leave a reply



Submit