[FFmpeg-devel] [PATCH] Set AVStream duration in several demuxers
Wed Jan 20 18:02:48 CET 2010
On Mon, Jan 18, 2010 at 10:43:06PM -0500, David Conrad wrote:
> 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;
> - 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.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 393 bytes
Desc: not available
More information about the ffmpeg-devel