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

Clément Bœsch ubitux at gmail.com
Mon Feb 6 19:32:51 CET 2012


On Mon, Feb 06, 2012 at 06:53:31PM +0100, Matthieu Bouron wrote:
> 2012/2/6 Stefano Sabatini <stefasab at gmail.com>:
> > On date Monday 2012-02-06 12:13:02 +0100, Matthieu Bouron encoded:
> >> 2012/2/6 Stefano Sabatini <stefasab at gmail.com>:
> >> > 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(-)
> > [...]
> >> Patch updated.
> >> >
> >> > 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.
> >> This code has the same behaviour as ffmpeg (libavcodec/util.c). If
> >> bits_per_sample is set, the bit_rate is computed but if not
> >> AVCodecContext.bit_rate is used.
> >
> > Yes, I wonder if it would make sense to export the get_bit_rate()
> > function, or even better to set the value right into the codec
> > context which should be even more robust.
> 
> New patches attached, bit rate entry is now reported for all kind of
> streams and use avcodec_get_bit_rate.
> 
> >
> >> Maybe this entry should be called avg_bit_rate ?
> > --
> > FFmpeg = Foolish & Forgiving Magic Practical Epic Ghost
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel at ffmpeg.org
> > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

> From 58120e1560826786b653b05083e5f06b43da910f Mon Sep 17 00:00:00 2001
> From: Matthieu Bouron <matthieu.bouron at smartjog.com>
> Date: Mon, 6 Feb 2012 17:07:18 +0100
> Subject: [PATCH 1/2] libavcodec: add avcodec_get_bit_rate function
> 
> ---
>  libavcodec/avcodec.h |    8 ++++++++
>  libavcodec/utils.c   |    4 ++--
>  libavcodec/version.h |    2 +-
>  3 files changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> index 43c2128..b2b1999 100644
> --- a/libavcodec/avcodec.h
> +++ b/libavcodec/avcodec.h
> @@ -3512,6 +3512,14 @@ AVCodec *avcodec_find_decoder_by_name(const char *name);
>  void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);
>  
>  /**
> + * Return the codec average bit rate
> + *
> + * @param the codec context

missing "codec": @param codec the codec context

> + * @return The codec average bit rate

nit: s/The/the/

> + */
> +int avcodec_get_bit_rate(AVCodecContext *codec);
> +
> +/**
>   * Return a name for the specified profile, if available.
>   *
>   * @param codec the codec that is searched for the given profile
> diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> index 0df3d7f..6914511 100644
> --- a/libavcodec/utils.c
> +++ b/libavcodec/utils.c
> @@ -1517,7 +1517,7 @@ AVCodec *avcodec_find_decoder_by_name(const char *name)
>      return NULL;
>  }
>  
> -static int get_bit_rate(AVCodecContext *ctx)
> +int avcodec_get_bit_rate(AVCodecContext *ctx)
>  {
>      int bit_rate;
>      int bits_per_sample;
> @@ -1661,7 +1661,7 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
>              snprintf(buf + strlen(buf), buf_size - strlen(buf),
>                       ", pass 2");
>      }
> -    bitrate = get_bit_rate(enc);
> +    bitrate = avcodec_get_bit_rate(enc);
>      if (bitrate != 0) {
>          snprintf(buf + strlen(buf), buf_size - strlen(buf),
>                   ", %d kb/s", bitrate / 1000);
> diff --git a/libavcodec/version.h b/libavcodec/version.h
> index ac28707..9a11b6f 100644
> --- a/libavcodec/version.h
> +++ b/libavcodec/version.h
> @@ -22,7 +22,7 @@
>  
>  #define LIBAVCODEC_VERSION_MAJOR 54
>  #define LIBAVCODEC_VERSION_MINOR  0
> -#define LIBAVCODEC_VERSION_MICRO 102
> +#define LIBAVCODEC_VERSION_MICRO 103
>  

minor increment (and micro reset, to 100).

>  #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
>                                                 LIBAVCODEC_VERSION_MINOR, \
> -- 
> 1.7.8.3
> 

> From 334b61c3d3bacc6278e02be43fac0a95e57b1825 Mon Sep 17 00:00:00 2001
> From: Matthieu Bouron <matthieu.bouron at smartjog.com>
> Date: Mon, 6 Feb 2012 11:58:14 +0100
> Subject: [PATCH 2/2] ffprobe: report bit rate in stream description
> 
> ---
>  doc/ffprobe.xsd |    1 +
>  ffprobe.c       |    5 +++++
>  2 files changed, 6 insertions(+), 0 deletions(-)
> 
> diff --git a/doc/ffprobe.xsd b/doc/ffprobe.xsd
> index e7104ef..ad8b3e3 100644
> --- a/doc/ffprobe.xsd
> +++ b/doc/ffprobe.xsd
> @@ -113,6 +113,7 @@
>        <xsd:attribute name="nb_frames"        type="xsd:int"/>
>        <xsd:attribute name="nb_read_frames"   type="xsd:int"/>
>        <xsd:attribute name="nb_read_packets"  type="xsd:int"/>
> +      <xsd:attribute name="bit_rate"         type="xsd:int"/>
>      </xsd:complexType>
>  
>      <xsd:complexType name="formatType">
> diff --git a/ffprobe.c b/ffprobe.c
> index 8ef9180..1a4554e 100644
> --- a/ffprobe.c
> +++ b/ffprobe.c
> @@ -1414,6 +1414,7 @@ static void show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_i
>      AVCodec *dec;
>      char val_str[128];
>      const char *s;
> +    int bit_rate;
>      AVRational display_aspect_ratio;
>      struct print_buf pbuf = {.s = NULL};
>  
> @@ -1501,6 +1502,10 @@ static void show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_i
>          }
>      }
>  
> +    bit_rate = avcodec_get_bit_rate(dec_ctx);
> +    if (bit_rate > 0) print_int    ("bit_rate", bit_rate);
> +    else              print_str_opt("bit_rate", "N/A");
> +

nit: could be inlined.

[...]

-- 
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120206/d38726c7/attachment.asc>


More information about the ffmpeg-devel mailing list