Re-encoding h.264 content with a different bit rate using Android MediaCodec

橙三吉。 提交于 2019-11-30 10:11:35

In your program, there is a design issue. In the loop while (!sawOutputEOS) { where you are trying to re-encode,

int inputBufIndex = encoder.dequeueInputBuffer(kTimeOutUs);

Dequeues one buffer from the input / input port of the encoder

 ByteBuffer dstBuf = encoderInputBuffers[inputBufIndex];

Buffer pointer to the dequeued buffer

int sampleSize = extractor.readSampleData(dstBuf, 0 /* offset */);

The dequeued buffer is filled with the data from extractor. The output of an extractor is a compressed bitstream. This is not a YUV uncompressed frame.

encoder.queueInputBuffer(inputBufIndex,....)

Here, the compressed bitstream is encoded. Since this is not a YUV frame, the encoder will try to perform a compression to the best of it's ability and hence, you observe a green illegible frame at the output of the encoder. I presume you are observing this on the screen due to the following portion of code where you decode the same content. This would have been observed even if the encoder's output was written into a file and played through a different player or on PC.

From the program, I presume your intended design is Decode ==> Encode ==> Live Decode for which your graph should be

MediaExtractor ==> MediaCodec (Decoder) ==> MediaCodec (Encoder) ==> MediaCodec (Decoder) ==> Display

P.S: Did you observe any memory violations when you run this program?

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!