[FFmpeg-devel] [PATCH+RFC] AVFrame for audio

Justin Ruggles justin.ruggles
Fri Sep 3 01:11:37 CEST 2010


Hi,

Peter Ross wrote:

> To prototype use of audio in AVFrame, I have modified the PCM encoder/decoder
> and addded new public lavc functions.
> 
> Existing SAMPLE_FMTs are mapping onto (AVFrame*)->data[0]. The obvious
> next step is to support planar audio, and splitting FF_COMMON_FRAME into
> common, audio- and video-specific parts.
> 
> avctx->reget_audio_buffer() is implemened using a simple realloc. It
> probably makes sense to reuse the video InternalBuffer stuff, but i'm not
> sure.

Any progress on this?  I really like the idea.

> +#if LIBAVCODEC_VERSION_MAJOR < 53
>  int attribute_align_arg avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size,
>                           const short *samples)
>  {
> +    AVFrame frame;
> +    avcodec_get_frame_defaults(&frame);
> +    frame.data[0]    = (uint8_t*)samples;
> +    frame.nb_samples = buf_size / ( av_get_bits_per_sample(avctx->codec->id)/8 * avctx->channels);
> +    return avcodec_encode_audio2(avctx, buf, buf_size, &frame);
> +}
> +#endif

Shouldn't the nb_samples calculation use av_get_bits_per_sample_format()
instead?  av_get_bits_per_sample() only works for pcm and adpcm codecs.
 Also, it should check for divide by zero.

Cheers,
Justin




More information about the ffmpeg-devel mailing list