我使用 MediaCodec 播放 avc 视频文件。现在我正在尝试从流中播放视频,我找不到任何关于使用 MediaCodec 进行自适应流的示例或好的文档。我想知道是否有人可以引导我举一个很好的例子,或者只是发布我需要做的事情?
一些代码:
...
codec = MediaCodec.createDecoderByType(type);
format = new MediaFormat();
format.setString(MediaFormat.KEY_MIME, type);
format.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, track.getInt("maxsize"));
format.setInteger(MediaFormat.KEY_WIDTH, videoWidth);
format.setInteger(MediaFormat.KEY_HEIGHT, videoHeight);
format.setInteger(MediaFormat.KEY_MAX_WIDTH, videoWidth);
format.setInteger(MediaFormat.KEY_MAX_HEIGHT, videoHeight);
...
mSurface = new Surface(mSurfaceTexture);
codec.configure(format, mSurface, null, 0);
codec.start();
...
请注意,我在初始化时没有 csd-0 和 csd1,我想在编解码器启动后提交它们。我怎样才能做到这一点?
现在当我打电话
int index = codec.dequeueInputBuffer(timeout * 1000);
索引始终为 -1。
任何帮助,将不胜感激。