[FFmpeg-devel] [PATCH] Set AVStream duration in several demuxers

Aurelien Jacobs aurel
Wed Jan 20 18:02:48 CET 2010


On Mon, Jan 18, 2010 at 10:43:06PM -0500, David Conrad wrote:
> Hi,
> 
> Several demuxers set duration and start_time in AVFormatContext, despite the comment to never set them directly. This sets them in AVStream instead, fixing "Estimating duration from bitrate, this may be inaccurate" messages.
> 
> iavs/ivas AVIs still set AVFormatContext duration, I didn't find a sample to test.
> 

> commit d1ec4470be04fba3ff10fbecd455a14ab322d14e
> Author: David Conrad <lessen42 at gmail.com>
> Date:   Mon Jan 18 22:33:25 2010 -0500
> 
>     Set start_time and duration in AVStream not AVFormatContext.
>     The latter is deduced from the former.
> 
> diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
> index 59dc166..7fcef04 100644
> --- a/libavformat/matroskadec.c
> +++ b/libavformat/matroskadec.c
> @@ -1151,9 +1151,6 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap)
>          return -1;
>      matroska_execute_seekhead(matroska);
>  
> -    if (matroska->duration)
> -        matroska->ctx->duration = matroska->duration * matroska->time_scale
> -                                  * 1000 / AV_TIME_BASE;
>      av_metadata_set(&s->metadata, "title", matroska->title);
>  
>      tracks = matroska->tracks.elem;
> @@ -1338,6 +1335,9 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap)
>              track->time_scale = 1.0;
>          av_set_pts_info(st, 64, matroska->time_scale*track->time_scale, 1000*1000*1000); /* 64 bit pts in ns */
>  
> +        if (matroska->duration)
> +            st->duration = matroska->duration;
> +
>          st->codec->codec_id = codec_id;
>          st->start_time = 0;
>          if (strcmp(track->language, "und"))

Strictly speeking this don't really seem correct. The segment duration
stored in matroska file is (IIUC) the total duration of the segment.
IOW it is the duration of the longest track. So using this same duration
for every streams is not excatly correct. But provided the current avformat
API, it seems to be the best we can do :-(

Maybe it would be better to improve the avformat API instead, to allow
demuxers to write directly AVFormatContext.duration when they only know
the total duration and not individual streams duration.
I guess this (untested) patch would fix your original issue. It would
also require an update of AVFormatContext.duration documentation.

Aurel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: has_duration.diff
Type: text/x-diff
Size: 393 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100120/5d50c89d/attachment.diff>



More information about the ffmpeg-devel mailing list