[FFmpeg-devel] [PATCH] replace av_get_bits_per_sample() with avcodec_get_bits_per_coded_sample()

Stefano Sabatini stefano.sabatini-lala at poste.it
Wed Jul 6 12:53:35 CEST 2011

On date Sunday 2011-06-05 19:37:36 -0400, Justin Ruggles encoded:
> On 06/05/2011 07:27 PM, Justin Ruggles wrote:
> > On 06/05/2011 06:31 PM, Stefano Sabatini wrote:
> > 
> >>     /**
> >>      * Bits per sample/pixel of internal libavcodec pixel/sample format.
> >>      * This field is applicable only when sample_fmt is AV_SAMPLE_FMT_S32.
> >>      * - encoding: set by user.
> >>      * - decoding: set by libavcodec.
> >>      */
> >>     int bits_per_raw_sample;
> > 
> > 
> > This just describes the accuracy of the data inside the internal
> > libavcodec sample *after decoding* or *before encoding*.  For example,
> > 24-bit audio data in AV_SAMPLE_FMT_S32 is still scaled to 32 bit range
> > as required by the sample format, but this field is set to 24 to
> > indicate that there is only 24 bits of information.  So say you want to
> > convert 24-bit audio from 1 lossless codec to another lossless codec,
> > the encoder will know that it can discard the low 8 bits and encode in
> > 24-bit mode if it has one because bits_per_raw_sample is 24.
> > 
> > bits_per_coded_sample refers to the size of the samples *before
> > decoding* or *after encoding*.
> > 
> > The 2 values may be the same, and probably are in most cases, but
> > they're used for different purposes.  bits_per_raw_sample depends on the
> > decoder implementation and sample format, where-as bits_per_coded_sample
> > depends only on the CODEC_ID and thus is the one used by libavformat.
> sorry... i just realized that last sentence isn't 100% true.
> bits_per_coded_sample does depend on the CODEC_ID, but sometimes it can
> be different for the same CODEC_ID and can be signaled as such by the
> demuxer (e.g. wavpack). theoretically the demuxer might not even know
> and might rely on the decoder init. but still bits_per_raw_sample and
> bits_per_coded_sample have different meanings.

Check patch.

The only drawback of the patch seems that the new
avcodec_get_bits_per_coded_sample() is only able to get the value for
*registered codecs* (which is not necessarily a problem), and requires
to iterate through the list of registered codec for getting the
information (this may be fixed by introducing an efficient search data
structure), but insofar should not have efficiency penalties since I'm
calling that function only during the init stage.

Possibly we may move the code which sets the
avctx->bits_per_coded_sample in the libavcodec/utils.c.

Comments are welcome.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-lavc-deprecate-av_get_bits_per_sample-in-favor-of-av.patch
Type: text/x-diff
Size: 32178 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20110706/867552c2/attachment.bin>

More information about the ffmpeg-devel mailing list