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.
av_read_frame()
will give you a PTS (Presentation Time Stamp). It is AVPacket's memberpts
. Perhaps that value can help you decide when to stop reading.Try to find frames per second and then use that number to calculate exact time of each frame as