[FFmpeg-devel] [PATCH] Set AVStream duration in several demuxers
Michael Niedermayer
michaelni
Tue Jan 19 16:39:45 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/flvdec.c b/libavformat/flvdec.c
> index 9c43149..0382a7b 100644
> --- a/libavformat/flvdec.c
> +++ b/libavformat/flvdec.c
> @@ -124,6 +124,7 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream, AVStream *vst
> AMFDataType amf_type;
> char str_val[256];
> double num_val;
> + int i;
>
> num_val = 0;
> ioc = s->pb;
> @@ -192,7 +193,9 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream, AVStream *vst
> } else if(amf_type == AMF_DATA_TYPE_NUMBER) {
> snprintf(str_val, sizeof(str_val), "%.f", num_val);
> av_metadata_set(&s->metadata, key, str_val);
> - if(!strcmp(key, "duration")) s->duration = num_val * AV_TIME_BASE;
> + if(!strcmp(key, "duration"))
> + for (i = 0; i < s->nb_streams; i++)
> + s->streams[i]->duration = num_val * 1000;
> else if(!strcmp(key, "videodatarate") && vcodec && 0 <= (int)(num_val * 1024.0))
> vcodec->bit_rate = num_val * 1024.0;
> } else if (amf_type == AMF_DATA_TYPE_STRING)
if duration is defined in the spec as the duration of all streams (compared
to the duration of the longest stream) then ok
[...]
> @@ -362,7 +364,7 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
> }
>
> // if not streamed and no duration from metadata then seek to end to find the duration from the timestamps
> - if(!url_is_streamed(s->pb) && s->duration==AV_NOPTS_VALUE){
> + if(!url_is_streamed(s->pb) && s->streams[0]->duration==AV_NOPTS_VALUE){
> int size;
> const int64_t pos= url_ftell(s->pb);
> const int64_t fsize= url_fsize(s->pb);
> @@ -372,7 +374,8 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
> if(size == get_be24(s->pb) + 11){
> uint32_t ts = get_be24(s->pb);
> ts |= get_byte(s->pb) << 24;
> - s->duration = ts * (int64_t)AV_TIME_BASE / 1000;
> + for (i = 0; i < s->nb_streams; i++)
> + s->streams[i]->duration = ts;
> }
> url_fseek(s->pb, pos, SEEK_SET);
> }
finding one timestemp from one stream is only good for one duration
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Rewriting code that is poorly written but fully understood is good.
Rewriting code that one doesnt understand is a sign that one is less smart
then the original author, trying to rewrite it will not make it better.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100119/99f17573/attachment.pgp>
More information about the ffmpeg-devel
mailing list