[FFmpeg-devel] Reducing time spent in av_find_stream_info()

Michael Niedermayer michaelni
Tue Nov 13 13:31:56 CET 2007


Hi

On Tue, Nov 13, 2007 at 12:11:56PM +0100, Diego Santa Cruz wrote:
> Hi there,
> 
> I am using ffmpeg on an embedded platform with a slow cpu (ARMv5 300 MHz, no FPU) and av_find_stream_info() is taking a long time on the audio streams (> 800 ms). Looking around I found that close to 99% of this time is spent updating duration_error for the audio stream. However, duration_error is only used for the video streams. I added an if test to avoid calculating duration_error for audio streams (see patch below). As far as I could test this reduced the time spent in av_find_stream_info() greatly.
> 
> For video streams there is still a good deal of time spent updating duration_error, due to the lack of FPU and the large amount of standard timebases tested when updating duration_error. Is it really necessary to have all those standard time bases? There are currently 725. As far as I understand all frame rates between 1/1001 and 60/1001, in steps of 1/12, are included. Can this be reduced to a (much) more reduced set so that it does not take that much time to compute duration_error? As this code affects all file formats and broken files I do not know all the implications by far...

its surely possible to remove some of frame rates, but the code must be clean
if its more complex than currently then it likely will be rejected
also the floats could be chnaged to integers
and there are likely many optimizations possible, ive not expected this code
to matter speedwise at all


> 
> --- libavformat/utils.c (revision 11006)
> +++ libavformat/utils.c (working copy)
> @@ -1852,7 +1852,9 @@
>          if (pkt->duration != 0)
>              codec_info_nb_frames[st->index]++;
> 
> -        {
> +       /* NOTE: the duration_error calculated here is only required
> +        * for video streams, avoid doing it for non-video streams */
> +        if (ic->streams[pkt->stream_index]->codec->codec_type == CODEC_TYPE_VIDEO) {
>              int index= pkt->stream_index;
>              int64_t last= last_dts[index];
>              int64_t duration= pkt->dts - last;
> @@ -1874,15 +1876,15 @@
>              }
>              if(last == AV_NOPTS_VALUE || duration_count[index]<=1)
>                  last_dts[pkt->stream_index]= pkt->dts;
> +       }
> +       if (st->codec->codec_id == CODEC_ID_NONE) {
> +           AVProbeData *pd = &(probe_data[st->index]);
> +           pd->buf = av_realloc(pd->buf, pd->buf_size+pkt->size+AVPROBE_PADDING_SIZE);
> +           memcpy(pd->buf+pd->buf_size, pkt->data, pkt->size);
> +           pd->buf_size += pkt->size;
> +           memset(pd->buf+pd->buf_size, 0, AVPROBE_PADDING_SIZE);
> +       }
> 
> -            if (st->codec->codec_id == CODEC_ID_NONE) {
> -                AVProbeData *pd = &(probe_data[st->index]);
> -                pd->buf = av_realloc(pd->buf, pd->buf_size+pkt->size+AVPROBE_PADDING_SIZE);
> -                memcpy(pd->buf+pd->buf_size, pkt->data, pkt->size);
> -                pd->buf_size += pkt->size;
> -                memset(pd->buf+pd->buf_size, 0, AVPROBE_PADDING_SIZE);
> -            }
> -        }

reindentions must be in seperate patches from functional changes (see the
docs on ffmpeg.org)

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

No great genius has ever existed without some touch of madness. -- Aristotle
-------------- 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/20071113/ef2d9d12/attachment.pgp>



More information about the ffmpeg-devel mailing list