[Libav-user] How to correctly split AVFrame with audio samples on encoding

Nicolas George nicolas.george at normalesup.org
Thu Nov 15 13:18:17 CET 2012

Le quintidi 25 brumaire, an CCXXI, hatred a écrit :
> It provides AVFrame's with nb_samples = 1152, but when I open output codec
> it have frame_size = 576 and when I encode audio frame I take error message:
>     more samples than frame size (avcodec_encode_audio2)
> I think that I must split one AVFrame into two or more and encode this
> resulting frames. Is it valid way? Do I must do it manualy with
> av_samples_copy?

Yes. This is clumsy but currently unavoidable. A simpler API was suggested
at some point, but no one did anything for it.

You could use a filter to do the work, but it would probably be overkill.

>		   How I can recalculate PTS for resulting frames?

A simple extrapolation based on the sample rate versus time base, using
av_rescale_q. If the time base is the same as the sample rate, it is even


  Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20121115/2c933eb4/attachment.asc>

More information about the Libav-user mailing list