[FFmpeg-devel] [PATCH] extract bit rate calculation into separate function

Michael Niedermayer michaelni
Tue Nov 10 19:51:28 CET 2009


On Tue, Nov 10, 2009 at 03:14:02PM +0100, Robert Kr?ger wrote:
>
> Hi,
>
> this patch extracts the bit rate calculation into a new function so 
> applications using libav like ffprobe do not have to duplicate this.
>
> Regression tests passed. At least I think they did because they completed 
> without a final error message.
>
> I hope this meets your requirements. If not, please let me know what I 
> should change.
>
> Thanks and regards,
>
> Robert
>
>
> Index: libavcodec/utils.c
> ===================================================================
> --- libavcodec/utils.c	(revision 20498)
> +++ libavcodec/utils.c	(working copy)
> @@ -741,6 +741,74 @@
>      return NULL;
>  }
>

> +/**
> + * Calculates the bit rate of a stream
> + *
> + * @ctx AVCodecContext of the stream
> + * @return bit rate in bits per second
> + */

this belongs in a header


> +int avcodec_get_bitrate(AVCodecContext *ctx)
> +{
> +    int bitrate;
> +
> +    switch(ctx->codec_type) {
> +    case CODEC_TYPE_VIDEO:
> +  	    bitrate = ctx->bit_rate;
> +    	break;

tabs


> +    case CODEC_TYPE_AUDIO:
> +        /* for PCM codecs, compute bitrate directly */
> +        switch(ctx->codec_id) {
> +        case CODEC_ID_PCM_F64BE:
> +        case CODEC_ID_PCM_F64LE:
> +            bitrate = ctx->sample_rate * ctx->channels * 64;
> +            break;
> +        case CODEC_ID_PCM_S32LE:
> +        case CODEC_ID_PCM_S32BE:
> +        case CODEC_ID_PCM_U32LE:
> +        case CODEC_ID_PCM_U32BE:
> +        case CODEC_ID_PCM_F32BE:
> +        case CODEC_ID_PCM_F32LE:
> +            bitrate = ctx->sample_rate * ctx->channels * 32;
> +            break;
> +        case CODEC_ID_PCM_S24LE:
> +        case CODEC_ID_PCM_S24BE:
> +        case CODEC_ID_PCM_U24LE:
> +        case CODEC_ID_PCM_U24BE:
> +        case CODEC_ID_PCM_S24DAUD:
> +            bitrate = ctx->sample_rate * ctx->channels * 24;
> +            break;
> +        case CODEC_ID_PCM_S16LE:
> +        case CODEC_ID_PCM_S16BE:
> +        case CODEC_ID_PCM_S16LE_PLANAR:
> +        case CODEC_ID_PCM_U16LE:
> +        case CODEC_ID_PCM_U16BE:
> +            bitrate = ctx->sample_rate * ctx->channels * 16;
> +            break;
> +        case CODEC_ID_PCM_S8:
> +        case CODEC_ID_PCM_U8:
> +        case CODEC_ID_PCM_ALAW:
> +        case CODEC_ID_PCM_MULAW:
> +        case CODEC_ID_PCM_ZORK:
> +            bitrate = ctx->sample_rate * ctx->channels * 8;
> +            break;

duplicate of av_get_bits_per_sample()


> +        default:
> +            bitrate = ctx->bit_rate;
> +            break;
> +        }
> +        break;
> +        case CODEC_TYPE_DATA:
> +            bitrate = ctx->bit_rate;
> +            break;
> +        case CODEC_TYPE_SUBTITLE:
> +            bitrate = ctx->bit_rate;
> +            break;
> +        case CODEC_TYPE_ATTACHMENT:
> +            bitrate = ctx->bit_rate;
> +            break;

default:


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I wish the Xiph folks would stop pretending they've got something they
do not.  Somehow I fear this will remain a wish. -- M?ns Rullg?rd
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20091110/abc92fa2/attachment.pgp>



More information about the ffmpeg-devel mailing list