[FFmpeg-devel] avcodec_encode_audio() and libavcodec/pcm.c

Stefano Sabatini stefano.sabatini-lala
Sun May 25 20:36:25 CEST 2008


Hi all,

maybe this belongs to libav-user, anyway...

According to documentation for avcodec_encode_audio():

 * @param[in] samples the input buffer containing the samples
 * The number of samples read from this buffer is frame_size*channels,
 * both of which are defined in \p avctx.

This isn't true for PCM audio, for example with PCM 16 the function
reads exactly a number of bytes which is buf_size/sample_size, and
this causes also the strange switch in ffmpeg.c:

        /* output a pcm frame */
        /* XXX: change encoding codec API to avoid this ? */
        switch(enc->codec->id) {
        case CODEC_ID_PCM_S32LE:
        case CODEC_ID_PCM_S32BE:
        case CODEC_ID_PCM_U32LE:
        case CODEC_ID_PCM_U32BE:
            size_out = size_out << 1;
            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:
            size_out = size_out / 2 * 3;
            break;
        case CODEC_ID_PCM_S16LE:
        case CODEC_ID_PCM_S16BE:
        case CODEC_ID_PCM_U16LE:
        case CODEC_ID_PCM_U16BE:
            break;
        default:
            size_out = size_out >> 1;
            break;
        }

Can someone comment on this (pretty weird) behaviour, there is some
hope to change it to make it match the documentation for
avcodec_encode_audio() or application writers have to hardcode the
above logic into every application which deals with PCM audio?

Thanks in advance for any clarification/suggestion.

Regards.
-- 
FFmpeg = Funny and Frenzy MultiPurpose EntanGlement




More information about the ffmpeg-devel mailing list