问题描述
这是问题所在:用ffmpeg
解码H264流时,我可以获得SPS和PPS的原始数据,但是我不知道如何将它们填充到AVCodecContext
的extradata
字段中.没有extradata
,我将无法正确解码帧.每次调用avcodec_decodec_video2
时,返回值为正,但got_picture
标志始终为zero
.
Here is the problem: When decoding H264 stream with ffmpeg
, I can obtain raw data of SPS and PPS but I have no idea how to fill them into the extradata
field of AVCodecContext
. Without extradata
, I can't decode frames properly. Every time I call avcodec_decodec_video2
, the return value is positive but the got_picture
flag is always zero
.
我正在处理的流看起来像这样:
The stream I am dealing with looks like this:
[0x67]...[0x68]...[0x61]...[0x61]... ....... [0x61]...[0x67]...[0x68]... ......
推荐答案
您提到的数据是一个字节流,其中包含用于SPS和PPS的NAL单元. extradata
反过来需要一个指向AVC解码器配置记录的指针,这是您具有额外格式的数据.
The data you mentioned is a byte stream holding NAL units for SPS and PPS. extradata
in turn expects a pointer to AVC decoder configuration record, which is the data you have with extra formatting.
有关详细信息,请参见MPEG-4第15部分高级视频编码(AVC)文件格式"部分.
See MPEG-4 Part 15 "Advanced Video Coding (AVC) file format" section 5.2.4.1 for details.
5.2.4.1.1 Syntax
aligned(8) class AVCDecoderConfigurationRecord {
unsigned int(8) configurationVersion = 1;
unsigned int(8) AVCProfileIndication;
unsigned int(8) profile_compatibility;
unsigned int(8) AVCLevelIndication;
bit(6) reserved = ‘111111’b;
unsigned int(2) lengthSizeMinusOne;
bit(3) reserved = ‘111’b;
unsigned int(5) numOfSequenceParameterSets;
for (i=0; i< numOfSequenceParameterSets; i++) {
unsigned int(16) sequenceParameterSetLength ;
bit(8*sequenceParameterSetLength) sequenceParameterSetNALUnit;
}
unsigned int(8) numOfPictureParameterSets;
for (i=0; i< numOfPictureParameterSets; i++) {
unsigned int(16) pictureParameterSetLength;
bit(8*pictureParameterSetLength) pictureParameterSetNALUnit;
}
}
这篇关于如何用SPS和PPS数据填充AVCodecContext的“额外数据"字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!