[FFmpeg-devel] [PATCH] ffprobe: add -framecount option.

Stefano Sabatini stefasab at gmail.com
Sun Oct 9 14:43:43 CEST 2011


On date Monday 2011-10-03 18:01:04 +0200, Clément Bœsch encoded:
> Hi,
> 
> Some information might not be available until we loop over all the
> packets, and the number of frames is among them. This patch add the
> possibility to run a slow analysis in order to get that value.
> 
> This really is a "violent" method, slow, and not really sexy (I don't like
> the seek I have to do for instance), but it might be useful for various
> reasons.
> 
> Any better idea is welcome,

In SF/ffprobe this is achieved with a read_frames flag, which forces
to read all the frames, and updates the count (even if frames are not
shown). In particolar this would avoid the seek and to iterate the
count for each stream.

> Regards,
> 
> -- 
> Clément B.

> From 8cd400bd3d56139fc78b2ebd1e6b0d98a3952858 Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= <clement.boesch at smartjog.com>
> Date: Mon, 3 Oct 2011 17:54:40 +0200
> Subject: [PATCH] ffprobe: add -framecount option.
> 
> ---
>  doc/ffprobe.texi |   17 +++++++++++++++++
>  ffprobe.c        |   25 +++++++++++++++++++++++++
>  2 files changed, 42 insertions(+), 0 deletions(-)
> 
> diff --git a/doc/ffprobe.texi b/doc/ffprobe.texi
> index a5d5df8..1504652 100644
> --- a/doc/ffprobe.texi
> +++ b/doc/ffprobe.texi
> @@ -112,6 +112,23 @@ multimedia stream.
>  Each media stream information is printed within a dedicated section
>  with name "STREAM".
>  
> + at item -framecount @var{mode}
> +Advanced frame count.
> +Available modes are:
> +
> + at table @option
> + at item default
> +Only print nb_frames if available.
> +
> + at item soft
> +Count each video frame if nb_frames is not available, and print them under the
> +key exact_nb_frames. Also print exact_nb_key_frames. This operation is slow.
> +
> + at item hard
> +Whatever the value of nb_frames, exact_nb_frames and exact_nb_key_frames will
> +be computed and printed. Just like soft, this operation is slow.
> + at end table
> +
>  @item -i @var{input_file}
>  Read @var{input_file}.
>  
> diff --git a/ffprobe.c b/ffprobe.c
> index 2c354ad..135e204 100644
> --- a/ffprobe.c
> +++ b/ffprobe.c
> @@ -41,6 +41,7 @@ static int use_value_prefix             = 0;
>  static int use_byte_value_binary_prefix = 0;
>  static int use_value_sexagesimal_format = 0;
>  
> +static char *framecount;
>  static char *print_format;
>  
>  static const OptionDef options[];
> @@ -439,6 +440,29 @@ static void show_stream(struct writer *w, AVFormatContext *fmt_ctx, int stream_i
>      if (stream->nb_frames)
>          print_fmt("nb_frames", "%"PRId64, stream->nb_frames);
>  
> +    if (fmt_ctx->pb->seekable &&
> +         stream->codec && stream->codec->codec_type == AVMEDIA_TYPE_VIDEO &&
> +        (strcmp(framecount, "hard") == 0 ||
> +        (strcmp(framecount, "soft") == 0 && stream->nb_frames == 0))) {

You may warn here that the format is not seekable, and avoid random
headaches to people.


More information about the ffmpeg-devel mailing list