Use MediaCodec and MediaExtractor to decode and code video

后端 未结 2 1037
情歌与酒
情歌与酒 2021-02-06 13:35

I need to decode a video into a sequence of bitmaps, such that I am able to modify them, and then compress them back to a video file in android.

I plan to manage this b

2条回答
  •  渐次进展
    2021-02-06 14:03

    You can find a collection of useful examples on the bigflake site.

    In particular, the ExtractMpegFramesTest demonstrates how to decode a .mp4 file to Bitmap, and the DecodeEditEncodeTest decodes and re-encodes an H.264 stream, modifying the frames with a GLES shader.

    Many of the examples use features introduced in API 18, such as Surface input to MediaCodec (which avoids a number of color-format issues), and MediaMuxer (which allows you to convert the raw H.264 elementary stream coming out of MediaCodec into a .mp4 file). Some devices will allow you to extract video to YUV data in ByteBuffer, modify it, and re-encode it, but other devices extract to proprietary YUV color formats that may be rejected by the API 16 version of MediaCodec.

    I'd recommend coding for API 18 (Android 4.3 "Jellybean" MR2) or later.

提交回复
热议问题