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

后端 未结 4 1672
伪装坚强ぢ
伪装坚强ぢ 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

    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.

提交回复
热议问题