[FFmpeg-devel] Reducing time spent in av_find_stream_info()
Diego Santa Cruz
Diego.SantaCruz
Tue Nov 13 12:11:56 CET 2007
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...
--- 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);
- }
- }
if(st->parser && st->parser->parser->split && !st->codec->extradata){
int i= st->parser->parser->split(st->codec, pkt->data, pkt->size);
if(i){
--
--------------------------------------------------------------------------
Diego Santa Cruz, PhD
Software Architect, SpinetiX S.A.
PSE-C, CH-1015, Lausanne, Switzerland
Tel:??? +41 (0) 21 693 89 81
Mail:?? Diego.SantaCruz at spinetix.com
Get Information : www.spinetix.com
--------------------------------------------------------------------------
More information about the ffmpeg-devel
mailing list