FFmpeg提取当前帧时间戳

kir*_*rbo 1 c++ timestamp ffmpeg

我需要在视频的特定间隔内提取帧(例如,从40秒到50秒).使用c ++.首先,我得到了我需要开始阅读的位置

static double t = 10 ;//time in seconds
int64_t timestamp = t * AV_TIME_BASE; //destination time
av_seek_frame( pFormatContext , -1 ,  timestamp + pFormatContext->start_time ,AVSEEK_FLAG_BACKWARD );
Run Code Online (Sandbox Code Playgroud)

然后我使用av_read_frame获取所有连续帧.我遇到的问题是我不知道什么时候停下来.如何检查我的结束间隔(例如50秒)?

谢谢.

小智 7

av_read_frame()会给你一个PTS(演示时间戳).它是AVPacket的成员pts.也许这个值可以帮助您决定何时停止阅读.