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

Stefano Sabatini stefasab at gmail.com
Wed Feb 15 00:12:41 CET 2012


On date Thursday 2012-02-09 19:06:42 +0100, Stefano Sabatini encoded:
> 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:
[...]
> > > 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

> 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;
> @@ -1587,29 +1612,6 @@ AVCodec *avcodec_find_decoder_by_name(const char *name)
>      return NULL;
>  }
>  
> -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;
> -}
> -
>  const char *avcodec_get_name(enum CodecID id)
>  {
>      AVCodec *codec;
> -- 
> 1.7.5.4

Ping.
-- 
FFmpeg = Fundamentalist Faithless Magnificient Puritan Eccentric Glue


More information about the ffmpeg-devel mailing list