tags:

views:

1272

answers:

2

I am attempting to seek in a movie using ffmpeg's av_seek_frame method however I'm having the most trouble determining how to generate a time-stamp to seek to. Assuming I want to seek x amount of frames either forward or backward and I know what frame the movie is currently on, how would I go about doing this?

+1  A: 

I haven't actually ffmpeg but this tutorial seems to address your question:

Tutorial 07: Seeking

diciu
This tutorial seeks based on seconds, not frames. It does help some. FFMPEG does not seek correctly for all containers and codecs. The timestamp used in FFMPEG is in microseconds (1,000,000 mus = 1 second).
Brian
A: 

Simple answer: You should have an AVFormatContext object lying around. Its duration property tells you how long your file is in terms of the time-stamp multiplied by 1000 that can be used in av_seek_frame, so treat it as 100%. Then you can calculate how far into the video you want to seek to.

if you want to go forward one frame, simply call av_read_frame and avcodec_decode_video until it fills the got_picture_ptr with a non-zero value. Before calling avcodec_decode_video make sure the packet from av_read_frame is from the video stream. avcodec_decode_video will then fill in the AVFrame structure which you can use to do anything with.