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

Matthieu Bouron matthieu.bouron at gmail.com
Mon Feb 6 12:13:02 CET 2012


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(-)
>>
>> 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);
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.
Maybe this entry should be called avg_bit_rate ?
> --
> FFmpeg = Fundamentalist & Frightening Mere Plastic Elected Goblin
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-ffprobe-report-audio-bit-rate-in-stream-description.patch
Type: text/x-diff
Size: 2265 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120206/80db1ebd/attachment.bin>


More information about the ffmpeg-devel mailing list