Reputation: 115
I am trying to write a video player using the MediaDecoder class, i came across a problem that its blocking my development,
here is a code snippet
extractor = new MediaExtractor();
extractor.setDataSource(filename);
MediaFormat format = extractor.getTrackFormat(i);
extractor.selectTrack(0);
MediaCodec decoder = MediaCodec.createDecoderByType(mime);
decoder.configure(format, null, null, 0);
decoder.start();
ByteBuffer[] inputBuffers = decoder.getInputBuffers();
ByteBuffer[] outputBuffers = decoder.getOutputBuffers();
Log.d(TAG, " "+decoder.getOutputFormat());
The problem is the output format printed changes with each device making it impossible to print it out to an Open GL texture.
Is there a way to force the decoder to output always the same format? If no, does anyone knows of any libraries available to make the conversion?
Thanks a lot for any insights
Upvotes: 3
Views: 4561
Reputation: 52313
The decoder's output format can't be set. In fact, you probably shouldn't even examine it until you receive an updated MediaFormat
from dequeueOutputBuffer()
-- before the first chunk of data is returned, you'll get a MediaCodec.INFO_OUTPUT_FORMAT_CHANGED
result.
If you want to access the decoded frame from OpenGL ES, you should create a Surface
from a SurfaceTexture
and pass that into the decoder configure()
call. It's more efficient, and doesn't require you to know anything about the data format.
For an example, see the DecodeEditEncodeTest.java CTS test, and note in particular the OutputSurface class and how it's used in checkVideoFile()
.
Upvotes: 6