[FFmpeg-devel] [PATCH] ffprobe: report audio bit rate in stream description

Stefano Sabatini stefasab at gmail.com
Mon Feb 6 11:46:19 CET 2012


On date Sunday 2012-02-05 22:26:14 +0100, Matthieu Bouron encoded:
> $title

> From 4bca8fd1dddfcf4851a0ba1cc6bd52d597e9ab8b Mon Sep 17 00:00:00 2001
> From: Matthieu Bouron <matthieu.bouron at gmail.com>
> Date: Sun, 5 Feb 2012 21:59:23 +0100
> Subject: [PATCH] ffprobe: report audio bit rate in stream description
> 
> ---
>  doc/ffprobe.xsd |    1 +
>  ffprobe.c       |    8 +++++++-
>  2 files changed, 8 insertions(+), 1 deletions(-)
> 
> diff --git a/doc/ffprobe.xsd b/doc/ffprobe.xsd
> index 9ac80bb..6ef05aa 100644
> --- a/doc/ffprobe.xsd
> +++ b/doc/ffprobe.xsd
> @@ -103,6 +103,7 @@
>        <xsd:attribute name="sample_rate"      type="xsd:int"/>
>        <xsd:attribute name="channels"         type="xsd:int"/>
>        <xsd:attribute name="bits_per_sample"  type="xsd:int"/>
> +      <xsd:attribute name="bit_rate"         type="xsd:int"/>
>  
>        <xsd:attribute name="id"               type="xsd:string"/>
>        <xsd:attribute name="r_frame_rate"     type="xsd:string" use="required"/>
> diff --git a/ffprobe.c b/ffprobe.c
> index 08ee8fd..5e6e812 100644
> --- a/ffprobe.c
> +++ b/ffprobe.c
> @@ -1403,6 +1403,8 @@ static void show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_i
>      AVCodec *dec;
>      char val_str[128];
>      const char *s;
> +    int bits_per_sample;
> +    int bit_rate;
>      AVRational display_aspect_ratio;
>      struct print_buf pbuf = {.s = NULL};
>  
> @@ -1464,11 +1466,15 @@ static void show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_i
>  
>          case AVMEDIA_TYPE_AUDIO:
>              s = av_get_sample_fmt_name(dec_ctx->sample_fmt);
> +            bits_per_sample = av_get_bits_per_sample(dec_ctx->codec_id);
> +            bit_rate = bits_per_sample ? dec_ctx->sample_rate * dec_ctx->channels * bits_per_sample : dec_ctx->bit_rate;
>              if (s) print_str    ("sample_fmt", s);
>              else   print_str_opt("sample_fmt", "unknown");
>              print_val("sample_rate",     dec_ctx->sample_rate, unit_hertz_str);
>              print_int("channels",        dec_ctx->channels);
> -            print_int("bits_per_sample", av_get_bits_per_sample(dec_ctx->codec_id));
> +            print_int("bits_per_sample", bits_per_sample);

> +            if (bit_rate > 0)
> +                print_int("bit_rate", bit_rate);

Some output formats (compact/csv) demand a fixed number of fields, so
in you need to display a field even in the case the information is not
available. In this case this should work:

              if (bit_rate > 0) print_int    ("bit_rate", bit_rate);
              else              print_str_opt("bit_rate", "N/A");

Also I'm not sure this is a good idea, since this only shows the
*uncompressed data* bitrate, which is in general different from the
effective bitrate.
-- 
FFmpeg = Fundamentalist & Frightening Mere Plastic Elected Goblin


More information about the ffmpeg-devel mailing list