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

Stefano Sabatini stefasab at gmail.com
Sat Apr 21 17:59:44 CEST 2012


On date Saturday 2012-04-21 13:15:23 +0200, Nicolas George encoded:
> 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;

This is semantically problematic. Suppose the user sets the default
value explicitely and by chance it is the same as the default value,
then she may *want* to keep that value.

> +    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;

What could go wrong with a too big value?

> +    }
> +    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);

I suggest to add an option - you may call it -auto_probesize or
whatever you want to call it - so that it is still possible to set the
probesize value explicitely, when the option is on the heuristic
presented in this patch is applied (you can set it by default if you
think it would be useful to prevent the issue).

BTW why is lavfi special in this regard? Why the issue is not required
e.g. with the video4linux device?
-- 
FFmpeg = Fantastic & Fundamentalist Mind-dumbing Ponderous Exxagerate Guide


More information about the ffmpeg-devel mailing list