androidandroid-ndkffmpegmp4video-watermarking

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


I am stuck in this area which I am not comfortable at all to work in.

Here is what I did so far:

enter image description here

I have created a new android project and made a jni folder and this is how far I went... Even this, with all the struggle being new to linux and compiling took me almost a week to reach.

Adding a watermark in ffmpeg I believe it is done on libavfilter ? I have to dig on this matter, however the original ffmpeg I need to translate into my project is:

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

As far as I am studying now I need to do inside jni:

I really need help on continuing, so every answer is received with great attention and pleasure.

Later Edit: Would it be possible to somehow build ffmpeg.exe as a library and call its main with the exact same parameters as the original exe ? I do not want to run ffmpeg as a standalone executable, but have it integrated within the project. Something like http://www.roman10.net/how-to-port-ffmpeg-the-program-to-androidideas-and-thoughts/ What downsides would this approach have ?

Later edit 2: if this is possible by using MediaMuxer or other APIs added in android 4.3 I am open to it you sample codes are provided. I did look over the MediaCodec and MediaMuxer samples also Grafik and haven't found a proper way to do what I wanted. I prefer ffmpeg approach better if it works


Solution

  • 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:

    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:

    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"