[Ffmpeg-devel] How to retrieve audio or video stream at same timestamp using av_read_frame

Michel Bardiaux mbardiaux
Mon May 23 12:38:00 CEST 2005


Martin Boehme wrote:
> Michel Bardiaux wrote:
> 
>> Martin Boehme wrote:
>>
>>> Keith Mok wrote:
>>>
>>>> If buffer excess data, will require a lot of memory specially if you 
>>>> need to buffer several seconds of the video data in a frame rate of 
>>>> 30 fps.
>>>> Any comment?
>>>
>>>
>>> Yes, it's going to require some memory... but what else could you do?
>>
>>
>> av_seek_frame and av_read_frame should work independently on each stream.
> 
> 
> Really? av_seek_frame() does have a "stream" parameter, but AFAICT that 
> just specifies the stream you want to use as an timebase. 

Sorry, bad wording on my part. *should* in the sense that 'this is what 
I would like', not 'would work if used correctly'.

> The end of 
> av_seek_frame_generic() (for example) goes like this:
> 
>     url_fseek(&s->pb, ie->pos, SEEK_SET);
> 
>     av_update_cur_dts(s, st, ie->timestamp);
> 
> And av_update_cur_dts() then does this:
> 
>     for(i = 0; i < s->nb_streams; i++) {
>         AVStream *st = s->streams[i];
> 
>         st->cur_dts = av_rescale(timestamp,
>             st->time_base.den *
>                 (int64_t)ref_st->time_base.num,
>             st->time_base.num *
>                 (int64_t)ref_st->time_base.den);
>     }
> 
> (Reformatted for 72 characters.)
> 
> And even if av_seek_frame() did seek streams independently, that would 
> just shift the burden of buffering frames to the disk cache or (worse) 
> cause the disk to thrash... Keith seems to be doing the equivalent of 
> seeking frames independently by using two different AVFormatContexts on 
> the same file, which (for the above reason) is not a good idea IMO.

There are not that many alternatives. Either you buffer yourself and 
thrash userspace memory, or you let some lowery level do it and you 
thrash the buffer cache. To me the simplest API is the best, and things 
are certainly simpler if you dont have to take side effects of one 
stream on the other into account.

Besides, I dont feel having 2 AVFormatContext (only way now to have 
independently seekable streams) is going the thrash memory anyway 
(strictly SOTP of course).

> 
> Martin
> 


-- 
Michel Bardiaux
Peaktime Belgium S.A.  Bd. du Souverain, 191  B-1160 Bruxelles
Tel : +32 2 790.29.41





More information about the ffmpeg-devel mailing list