[FFmpeg-devel] [PATCH 2/2] lavd/lavfi: raise info_probe_size if necessary.

Nicolas George nicolas.george at normalesup.org
Mon Apr 23 14:02:41 CEST 2012


lavfi outputs rawvideo frames, which can be quite large;
and due to time-altering filters, the time_base can not
be used to estimate the frame rate.

lavfi will raise info_probe_size, to a value probably big enough
to let lavf probe two frames of each stream.

It is only done if info_probe_size has its default value,
and if the new info probe size does not exceeds 8 times
probesize. With the current value, it is enough for
three full-HD 24bpp streams.

The user is still allowed to set a larger value if necessary.

Fixes trac ticket #1051.

Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
---
 libavdevice/lavfi.c |   28 ++++++++++++++++++++++++++++
 1 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/libavdevice/lavfi.c b/libavdevice/lavfi.c
index 0a6eb91..438aaeb 100644
--- a/libavdevice/lavfi.c
+++ b/libavdevice/lavfi.c
@@ -79,6 +79,33 @@ av_cold static int lavfi_read_close(AVFormatContext *avctx)
     return 0;
 }
 
+static void raise_info_probe_size(AVFormatContext *avctx)
+{
+    unsigned i, size = 0, bps;
+
+    if (avctx->info_probe_size) /* not the default value */
+        return;
+    for (i = 0; i < avctx->nb_streams; i++) {
+        AVCodecContext *codec = avctx->streams[i]->codec;
+        switch (codec->codec_type) {
+        case AVMEDIA_TYPE_VIDEO:
+            bps = av_get_bits_per_pixel(&av_pix_fmt_descriptors[codec->pix_fmt]);
+            size += (codec->width * codec->height * bps + 7) / 8;
+            break;
+        case AVMEDIA_TYPE_AUDIO:
+            size += AVCODEC_MAX_AUDIO_FRAME_SIZE;
+            break;
+        }
+        if (size >= 4 * avctx->probesize) /* too much */
+            return;
+    }
+    size = 2 * size + 1; /* two frames of each stream */
+    if (size < avctx->probesize)
+        return;
+    avctx->info_probe_size = size;
+    av_log(avctx, AV_LOG_INFO, "Raised info_probe_size to %d\n", size);
+}
+
 av_cold static int lavfi_read_header(AVFormatContext *avctx)
 {
     LavfiContext *lavfi = avctx->priv_data;
@@ -269,6 +296,7 @@ av_cold static int lavfi_read_header(AVFormatContext *avctx)
                        av_get_sample_fmt_name(link->format));
         }
     }
+    raise_info_probe_size(avctx);
 
 end:
     av_free(pix_fmts);
-- 
1.7.2.5



More information about the ffmpeg-devel mailing list