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
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.