[FFmpeg-devel] Request for comment: Tutorial

Scott Harper orcein
Fri May 25 04:55:46 CEST 2007

On 2007/05/24, at 20:31, Stephen Dranger wrote:

> On 5/25/07, Scott Harper <orcein at gmail.com> wrote:
>> On 2007/05/21, at 22:47, Stephen Dranger wrote:
>>> I have written a rather lengthy ffmpeg tutorial that starts by going
>>> over Martin Bohme's old tutorial, then proceeding to recreate
>>> ffplay.c, teaching about how ffmpeg, SDL, and video in general  
>>> works.
>>> Here's the link:
>>> http://dranger.com/ffmpeg/ffmpeg.html
>> Excellent tutorial!  That will be very helpful, especially the part
>> where you explain the syncing elements.
>> ...
>> Sorry for the long post, hope it was clear enough and on-topic enough
>> to not get flames too badly. ^_^
>> -- Scott
> Well as far as seeking is concerned, you're usually going to want to
> just seek like in the tutorial. av_seek_frame is going to seek to the
> next key frame unless you set AVSEEK_FLAG_ANY. I do believe that
> av_seek_frame is going to seek to the next key frame even if you
> specify the audio stream in the call. Make sure you are clearing
> avcodec's buffer and any internal buffers you might have when you
> seek, too.
> Your idea of taking the fractional value of "duration" is correct, I
> think, but remember that that value is in AV_TIME_BASE units, and if
> you pass av_seek_frame an audio or video stream, you need to rescale
> that value first to be in that stream's units. I don't know that you
> need to "seek frames up to the video frame", either. av_seek_frame
> will take you to the location that you want right away. I'm not really
> sure what's wrong with your player though; it could be a lot of
> things.

Thanks, I think that AV_TIME_BASE is something I neglected to look  
at, and that explains why my audio was off.

Seeking on the video track does return key frames only, which in most  
cases for me are not the EXACT frame I was searching for.  In  
professional video players when you click a specific location on the  
progress bar they jump to the specific frame, and that's what I mean  
by building up the frames.  That is, you go to the most recent i- 
frame and have to progress through all of the b- and p- frames (and  
any others) to get the correct picture on the frame you're seeking  
to, or rather the one you actually WANT, not the nearest keyframe  
according to the seek forward/backward request.  That's all. (I hope  
that wasn't confusing.)  And when I did that, it seemed like my audio  
ratio and video ratio were different by a notable amount, but I guess  
I'll just have to play with it more.  Thanks for the suggestion! ^_^

> As far as seeking by bytes goes, check out ffplay.c. Basically, it
> works like this: you get the actual current offset of the file, then
> use the bit rate from AVFormatContext to figure out how many bytes you
> want to skip ahead/behind. Then ffmpeg will go back that many bytes.
> I'm not certain if seeking by bytes guarantees you will seek to a key
> frame or not (from peeking at the source, it seems like you aren't
> guaranteed that; I'm really not sure).
> I don't think seeking by bytes is any better, and looking at the
> mailing list, it looks like it is just preferable when using files
> where the timestamps are discontinuous (like VOB). Here's the mailing
> list discussion about why the feature was added to ffplay.c:
> http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/2006-November/ 
> 018400.html

Thanks for the link and the help!   ...and the great tutorial!

-- Scott

More information about the ffmpeg-devel mailing list