如何判断当前AVPacket是否为关键帧呢?
答案是: 通过AVPacket中的flags来判断。
typedef struct AVPacket {
...
/**
* A combination of AV_PKT_FLAG values
*/
int flags;
...
}
AV_PKT_FLAG values定义如下:
#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
其中AV_PKT_FLAG_KEY用来表示是否为关键帧。
- 赋值
AVPacket *pkt;
...
pkt.flags |= AV_PKT_FLAG_KEY;
- 判断是否为关键帧
AVPacket *pkt;
...
if (pkt->flags & AV_PKT_FLAG_KEY) // is keyframe
{
...
}
...
另一个例子:
AVPacket pkt;
...
for (;;) {
int read_status;
do {
read_status = av_read_frame(s, &pkt);
} while (read_status == AVERROR(EAGAIN));
if (read_status < 0)
break;
if (stream_index == pkt.stream_index && pkt.dts > timestamp) {
if (pkt.flags & AV_PKT_FLAG_KEY) {
av_packet_unref(&pkt);
break;
}
...
}
av_packet_unref(&pkt);
}
网友评论