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

Nicolas George nicolas.george at normalesup.org
Sat Apr 21 13:15:23 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 probesize, to a value probably big enough
to let lavf probe two frames of each stream.

It is only done if probesize has its default value,
and if the new probe size does not exceeds 8 times
the default value. 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 |   32 ++++++++++++++++++++++++++++++++
 1 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/libavdevice/lavfi.c b/libavdevice/lavfi.c
index 0a6eb91..1e979b4 100644
--- a/libavdevice/lavfi.c
+++ b/libavdevice/lavfi.c
@@ -79,6 +79,37 @@ av_cold static int lavfi_read_close(AVFormatContext *avctx)
     return 0;
 }
 
+static void raise_probesize(AVFormatContext *avctx)
+{
+    unsigned i, default_probesize, probesize = 0, bps;
+    const AVOption *probesize_opt;
+
+    probesize_opt = av_opt_find(avctx, "probesize", NULL, 0, 0);
+    if (!probesize_opt)
+        return;
+    default_probesize = probesize_opt->default_val.dbl;
+    if (avctx->probesize != default_probesize) /* 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]);
+            probesize += (codec->width * codec->height * bps + 7) / 8;
+            break;
+        case AVMEDIA_TYPE_AUDIO:
+            probesize += AVCODEC_MAX_AUDIO_FRAME_SIZE;
+            break;
+        }
+        if (probesize >= 4 * default_probesize) /* too much */
+            return;
+    }
+    if (probesize < default_probesize)
+        return;
+    avctx->probesize = 2 * probesize + 1; /* two frames of each stream */
+    av_log(avctx, AV_LOG_INFO, "Raised probesize to %d\n", avctx->probesize);
+}
+
 av_cold static int lavfi_read_header(AVFormatContext *avctx)
 {
     LavfiContext *lavfi = avctx->priv_data;
@@ -269,6 +300,7 @@ av_cold static int lavfi_read_header(AVFormatContext *avctx)
                        av_get_sample_fmt_name(link->format));
         }
     }
+    raise_probesize(avctx);
 
 end:
     av_free(pix_fmts);
-- 
1.7.2.5



More information about the ffmpeg-devel mailing list