一般来说,android会为每个输入指定nal个单位。对于某些设备,我发现在h264的媒体格式上设置csd-0/1的功能不一致。但是,如果您将每个参数集作为输入缓冲区提供,则媒体编解码器会将其作为格式更改进行提取。
int outputBufferIndex = NativeDecoder.DequeueOutputBuffer (info, 1000);
if (outputBufferIndex == (int)MediaCodec.InfoOutputFormatChanged) {
Console.WriteLine ("Format changed: {0}", NativeDecoder.OutputFormat);
} else if (outputBufferIndex >= 0) {
CodecOutputBufferAvailable (NativeDecoder, outputBufferIndex, info);
}
还要注意它是强制性的Nexus和其他一些三星设备的设置:
formatDescription.SetInteger(MediaFormat.KeyWidth, SelectedPalette.Value.Width);
formatDescription.SetInteger(MediaFormat.KeyHeight, SelectedPalette.Value.Height);
formatDescription.SetInteger(MediaFormat.KeyMaxInputSize, SelectedPalette.Value.Width * SelectedPalette.Value.Height);
我很幸运,在我的情况,我可以查询这些决议。但是,您可以从SPS和PPS nal单元手动解析分辨率。
//注意我在这里使用Xamarin。但电话和事情几乎相同。我相当确定在iOS VideoToolbox Xamarin Wrapper中存在错误,所以是的。请记住,如果您曾考虑Xamarin进行视频解码。它适用于任何事物,但稍微更加自定义或低级的事物。
MediaCodec在NAL单元上运行。它需要启动前缀。比照http://stackoverflow.com/questions/1685494/what-does-this-h264-nal-header-mean – fadden