一般來說,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