I usually use the code below to get the current frame number when decoding a video.
while(av_read_frame(pFormatCtx, &packet)>=0) {
if(packet.stream_index==videoStream) {
avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet);
if(frameFinished) {
int currentFrameNumber = pFrame->coded_picture_number;
}
av_free_packet(&packet);
}
Then, when I implemented the search function, I add av_seek_frame to search for the desired position as follows:
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) {
avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet);
if(frameFinished) {
int currentFrameNumber = pFrame->coded_picture_number;
}
av_free_packet(&packet);
}
This is when a problem arises. pFrame-> coded_picture_number returns an invalid value. My question is, how do I get the current frame if I have a decoded pFrame?
source
share