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

Michael Niedermayer michaelni at gmx.at
Wed Feb 15 05:05:50 CET 2012


On Thu, Feb 09, 2012 at 07:06:42PM +0100, Stefano Sabatini wrote:
> On date Thursday 2012-02-09 00:38:03 +0100, Stefano Sabatini encoded:
> > On date Tuesday 2012-02-07 21:55:03 +0100, Michael Niedermayer encoded:
> > > On Tue, Feb 07, 2012 at 05:52:24PM +0100, Stefano Sabatini wrote:
> > > > On date Tuesday 2012-02-07 10:44:22 +0100, Matthieu Bouron encoded:
> > > > > 2012/2/6 Clément Bœsch <ubitux at gmail.com>:
> > > > [...]
> > > > > From ab616ceea409f623b3d0c16bef714bba8036b96c 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 |    4 ++--
> > > > >  3 files changed, 12 insertions(+), 4 deletions(-)
> > > > > 
> > > > > diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> > > > > index 43c2128..bdd36b2 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
> > > > 
> > > > nit: missing dot
> > > > 
> > > > > + *
> > > > > + * @param codec the codec context
> > > > 
> > > > > + * @return the codec average bit rate
> > > > 
> > > > What happens if the information is not available in the codec? (I
> > > > suppose it will return 0 in this case, so you may need to extend the
> > > > docs for that or the user will get surprised).
> > > > 
> > > > Looks fine otherwise, but I'd like to hear the opinion from Michael
> > > > about this new interface.
> > > 
> > > iam fine with teh interface, though i think the bit_rate field itself
> > > should be set correctly when its not currently
> > 
> > It may be set in avcodec_open() after init is called on the codec, in
> > case it was not already set, this should avoid this interface, I'll
> > try to have a look at it soon if nobody beats me at it, in the
> > meanwhile please suspend this patch.
> 
> Check patches in attachment.
> -- 
> FFmpeg = Funny & Faithful Marvellous Puritan Embarassing God

>  utils.c |   48 +++++++++++++++++++++++++-----------------------
>  1 file changed, 25 insertions(+), 23 deletions(-)
> 040a6b1de1dd169c3e8525c737554f13e603ed45  0001-lavc-set-bit_rate-in-the-codec-context-just-after-th.patch
> From 909333d0d2ab8ba490044787e21353733913fb04 Mon Sep 17 00:00:00 2001
> From: Stefano Sabatini <stefasab at gmail.com>
> Date: Thu, 9 Feb 2012 18:50:32 +0100
> Subject: [PATCH] lavc: set bit_rate in the codec context, just after the init
>  stage
> 
> Also move the get_bit_rate() function, in order to avoid undefined symbol
> reference in avcodec_open2().
> ---
>  libavcodec/utils.c |   48 +++++++++++++++++++++++++-----------------------
>  1 files changed, 25 insertions(+), 23 deletions(-)
> 
> diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> index 9e31d9e..fb83cc9 100644
> --- a/libavcodec/utils.c
> +++ b/libavcodec/utils.c
> @@ -676,6 +676,29 @@ static void avcodec_get_subtitle_defaults(AVSubtitle *sub)
>      sub->pts = AV_NOPTS_VALUE;
>  }
>  
> +static int get_bit_rate(AVCodecContext *ctx)
> +{
> +    int bit_rate;
> +    int bits_per_sample;
> +
> +    switch(ctx->codec_type) {
> +    case AVMEDIA_TYPE_VIDEO:
> +    case AVMEDIA_TYPE_DATA:
> +    case AVMEDIA_TYPE_SUBTITLE:
> +    case AVMEDIA_TYPE_ATTACHMENT:
> +        bit_rate = ctx->bit_rate;
> +        break;
> +    case AVMEDIA_TYPE_AUDIO:
> +        bits_per_sample = av_get_bits_per_sample(ctx->codec_id);
> +        bit_rate = bits_per_sample ? ctx->sample_rate * ctx->channels * bits_per_sample : ctx->bit_rate;
> +        break;
> +    default:
> +        bit_rate = 0;
> +        break;
> +    }
> +    return bit_rate;
> +}
> +
>  #if FF_API_AVCODEC_OPEN
>  int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec)
>  {
> @@ -865,6 +888,8 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVD
>              avctx->channels = av_get_channel_layout_nb_channels(avctx->channel_layout);
>          }
>      }
> +    if (!avctx->bit_rate)
> +        avctx->bit_rate = get_bit_rate(avctx);
>  
>      avctx->pts_correction_num_faulty_pts =
>      avctx->pts_correction_num_faulty_dts = 0;

iam not sure if this is safe or may interfere with an encoder because
i think this is run also for encoders

otherwise i think its ok if it passes fate

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Breaking DRM is a little like attempting to break through a door even
though the window is wide open and the only thing in the house is a bunch
of things you dont want and which you would get tomorrow for free anyway
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120215/99420bbe/attachment.asc>


More information about the ffmpeg-devel mailing list