Adding watermark bitmap over video in android: 4.3's MediaMuxer or ffmpeg

后端 未结 4 1634
伪装坚强ぢ
伪装坚强ぢ 2020-11-29 03:05

Here is my scenario:

  • Download an avi movie from the web
  • Open a bitmap resource
  • Overlay this bitmap at the bottom of the movie on all frames
相关标签:
4条回答
  • 2020-11-29 03:28

    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.

    0 讨论(0)
  • 2020-11-29 03:28

    If you need do this without ffmpeg on Android device:

    Start from : https://github.com/google/grafika

    The answer on your question between Play video (PlayMovieActivity.java) and Record Gl App (RecordFBOActivity.java) examples.

    Steps:

    1. Setup mInputWindowSurface as Video Encoder Input Surface.

    2. Decode frame from video stream using MoviePlayer as video (external) texture.

    3. Draw this video texture on Surface.

    4. Draw watermark on the same Surface over video texture.

    5. Notify MediaCodec that surface ready for encoding:

      mVideoEncoder.frameAvailableSoon(); 
      mInputWindowSurface.setPresentationTime(timeStampNanos);
      

      and then goto Step 2.

    Don't forget to adjust speed of decoding. Just remove SpeedControlCallback which in example set to decode 60 FPS video.

    Advantages of this way:

    1. Media Codec use hardware decoder/encoder for video processing.

    2. You can change bit rate of result video.

    0 讨论(0)
  • 2020-11-29 03:30

    This is what worked for me:

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

    ffmpeg recommended the usage -strict -2 inorder to allow the usage of experimental codecs. without the inclusion, the accepted answer above fails to work.

    0 讨论(0)
  • 2020-11-29 03:40

    You can try INDE Media Pack - https://software.intel.com/en-us/articles/intel-inde-media-pack-for-android-tutorials

    It has transcoding\remuxing functionality as MediaComposer class and several sample effects like JpegSubstituteEffect - it shows how substitute video frame by a picture from jpg file and TextOverlayEffect to overlay text on video frame etc. It could be easily enhanced to watermark effect

    enter image description here

    0 讨论(0)
提交回复
热议问题