[FFmpeg-devel] support for audio with sample resolution better than 16bit

Michael Niedermayer michaelni
Sun Apr 20 14:17:52 CEST 2008

On Sun, Apr 20, 2008 at 10:44:16AM +0200, Lars T?uber wrote:
> Hallo!
> Recently I added a wish (#425) to the ffmpeg roundup system.
> I'd like ffmpeg to be capable to transcode 24bit pcm into 24bit flac.
> Therefore the audio handling has to be enhanced. Now I want to make some suggestions how I think this could be done.
> At first the decoding needs to be able to handle other resolutions than 16bit.
> I'd suggest to add the following function:
> int attribute_align_arg avcodec_decode_audio3(AVCodecContext *avctx,
>                                               int16_t *samples,
>                                               int *frame_size_ptr,
>                                               void *low_samples,
>                                               int *low_frame_size_ptr,
>                                               uint8_t *sample_res,
>                                               const uint8_t *buf, int buf_size)
> When there is audio decoded in 24 bit depth the caller can tell that he only wants to receive 16bit depth with setting *sample_res=16.
> Then low_frame_size_ptr and low_samples can be uninitialized.
> when 16 < *sample_res <=24  low_samples is of type (unint8_t *) and the memory has to be allocated
> when 24 < *sample_res <=32  low_samples is of type (uint16_t *) and the memory has to be allocated
> when 32 < *sample_res  return error
> audio samples are always put into the high bits:
> 26 bit sample:
> int32_t real_sample[0] = samples[0]<<16 | ((uint16_t *) low_samples[0] & 0xfffc)
> after decoding *sample_res is set to the actual sample resolution
> e.g. the caller tells he wants 24bit maximum but the stream only had 20bit resolution then *sample_res is set to 20
> When the caller sets *sample_res == 0 he accepts all depth up to 32bit.
> Optionaly the samples pointer could also be of type (void *) and then *samples_res could distinguish 16bit samples from 8bit samples.
> What do you think?

That you are insane :)

If <=16 bits are stored the decoder should output 16bits
If  >16 <32 bits are stored the decoder should output 32bits
If >32bits are stored the decoder should output float

The decoder sets AVCodecContext.sample_fmt to the format it outputs

On the encoder side the users sets AVCodecContext.sample_fmt to what he will
provide as input to the encoder (the encoder would fail if it doesnt support
that) the encoder can also list its supported sample formats in AVCodec
similar to how pix_fmts are listed there.

Convertion between sample formats is never done in a codec.


The only thing that needs to be changed is ffmpeg and ffplay, so they
can handle 32bit int.

Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Concerning the gods, I have no means of knowing whether they exist or not
or of what sort they may be, because of the obscurity of the subject, and
the brevity of human life -- Protagoras
-------------- 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/20080420/eb0f696d/attachment.pgp>

More information about the ffmpeg-devel mailing list