FFmpeg extracting current frame time stamp

2019-08-13 23:25发布

I need to extract frames in certain interval of the video, (eg from 40 sec to 50 sec). Working in c++. First I am getting position where I need to start reading

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 );

Then I using av_read_frame to get all sequential frames. The problem that I have is that I dont know when to stop. How can I check that I reached my end interval (eg 50 sec) ?

Thanks.

2条回答
Juvenile、少年°
2楼-- · 2019-08-13 23:46

av_read_frame() will give you a PTS (Presentation Time Stamp). It is AVPacket's member pts. Perhaps that value can help you decide when to stop reading.

查看更多
Bombasti
3楼-- · 2019-08-13 23:51

Try to find frames per second and then use that number to calculate exact time of each frame as

frame_absolute_time = frame_number / FPS
查看更多
登录 后发表回答