Skip to content
Advertisement

Out of order BufferInfo.presentationTimeUs timestamps in mediacodec decoder

I am getting irregular newBufferInfo.presentationTimeUs because of which if I put Thread.sleep to slow down the playback, a lot of frames are dropped.

Actually, with Surface the frames timestamps are synchronized automatically with system timestamp without sleep, however it does not work with giving output to OpenGLES. https://developer.android.com/reference/android/media/MediaCodec#releaseOutputBuffer(int,%20long)

I thought mExtractor.getSampleTime() is the problem but even after removing it, the problem is still there.

JavaScript

This class takes the mp4 video clipPath, and has start and stop functions which start and stop decoding the mp4 video to the passed surface.

Here are the logs

JavaScript

Here are the logs with

JavaScript
JavaScript

Here are the logs with

JavaScript
JavaScript

By default int outIndex = mVideoDecoder.dequeueOutputBuffer(newBufferInfo, 1000); should output frames in display order (which is the timestamp order) as I have checked in the documentation but the timestamps are out of order.

For some reason, the video playback seems smooth even with out of order timestamps and I am utterly confused.

Advertisement

Answer

I figured out the issue. It was in dequeueInputBuffer part. I was doing mExtractor.advance() beforehand in if statement.

The correct implementation is as follows

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement