通常,我在解码视频时使用以下代码来获取当前帧编号。
while(av_read_frame(pFormatCtx, &packet)>=0) {
if(packet.stream_index==videoStream) {
// Decode video frame
avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet);
// Did we get a video frame?
if(frameFinished) {
int currentFrameNumber = pFrame->coded_picture_number;
}
/* Free the packet that was allocated by av_read_frame*/
av_free_packet(&packet);
}
然后,当我实现搜索功能时,我添加av_seek_frame以寻找所需的位置,如下所示:
if(av_seek_frame(pFormatCtx, -1, seekTarget, 0 )<0){
LOG("log","error when seeking");
}
while(av_read_frame(pFormatCtx, &packet)>=0) {
if(packet.stream_index==videoStream) {
// Decode video frame
avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet);
// Did we get a video frame?
if(frameFinished) {
int currentFrameNumber = pFrame->coded_picture_number;
}
/* Free the packet that was allocated by av_read_frame*/
av_free_packet(&packet);
}
这是问题出现的时候。 pFrame-&gt; coded_picture_number返回不正确的值。 我的问题是,如果我有一个解码的帧pFrame,我如何获取当前帧?