How to encode Bitmaps into a video using MediaCodec?

后端 未结 4 1978
情话喂你
情话喂你 2020-12-02 06:49

I would like to encode a set of Bitmaps that I have into an h264. Is this possible via MediaEncoder? I have written some code in order to do it, but the output cannot be pla

4条回答
  •  抹茶落季
    2020-12-02 07:14

    The output of MediaCodec is a raw H.264 elementary stream. I've found that the Totem media player for Linux is able to play them.

    What you really want to do is convert the output to a .mp4 file. (Update:) Android 4.3 (API 18) introduced the MediaMuxer class, which provides a way to convert the raw data (plus an optional audio stream) to a .mp4 file.

    The layout of data in the ByteBuffer is, as of Android 4.3, device-dependent. (In fact, not all devices support COLOR_FormatYUV420Planar -- some prefer a semi-planar variant.) I can't tell you the exact layout without knowing your device, but I can tell you that it wants uncompressed data, so passing in compressed PNG data is not going to work.

    (Update:) Android 4.3 also allows Surface input to MediaCodec encoders, so anything you can render with OpenGL ES can be recorded. For an example, see the EncodeAndMuxTest sample here.

提交回复
热议问题