AVFrame结构体中变量解释
AVPacket结构体内几个变量分析:
AVBufferRef *buf;
引用计数时使用,多个packet指向同一块内存,没用到默认是NULL
int stream_index;
当读取到一帧数据后,用以区分是视频帧,音频帧,还是字幕帧。stream_index不同的值代表哪一种帧呢,见后附代码,这个需要从流中获取,stream_index值等于video_index时即为视频帧,stream_index值等于audio_index时即为音频帧。
int flags;
区分是否关键帧,为1时是关键帧,关键帧为AV_PKT_FLAG_KEY(也就是1)
for (int i = 0; i < ic->nb_streams; i++) { if (ic->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) { // ic->streams[i]->codecpar video_index = i; } if (ic->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO) { // ic->streams[i]->codecpar audio_index = i; } }
在源码packet.h中定义如下:
#define AV_PKT_FLAG_KEY 0x0001 ///< The packet contains a keyframe #define AV_PKT_FLAG_CORRUPT 0x0002 ///< The packet content is corrupted /** * Flag is used to discard packets which are required to maintain valid * decoder state but are not required for output and should be dropped * after decoding. **/ #define AV_PKT_FLAG_DISCARD 0x0004 /** * The packet comes from a trusted source. * * Otherwise-unsafe constructs such as arbitrary pointers to data * outside the packet may be followed. */ #define AV_PKT_FLAG_TRUSTED 0x0008 /** * Flag is used to indicate packets that contain frames that can * be discarded by the decoder. I.e. Non-reference frames. */ #define AV_PKT_FLAG_DISPOSABLE 0x0010