[Libav-user] Resampling issue

Andrew Sherepenko andrew.sherepenko at gmail.com
Fri Nov 22 09:52:56 CET 2013

Hello libav users!

I try to remuxing MPEG-TS to MP4 container.

MPEG-TS stores H.264 video and AC3 audio. I copy video context to the 
new container,
but I have to transcode audio to MP3.

What I do:
1. Read packet from input context;
2. Decode packet to the frame;
3. Resample audio (use swr_conwert() API method);
4. Encode frame into packet;
5. Write packet into output context.

AC3 frame stores 1536 samples, and MP3 - only 1152.
In this case we have downsampling. I've found that swr_convert() 
buffered unprocessed samples (1536 - 1152 = 384 samples per frame).
If I don't read buffered samples I don't have an audio in the and of the 
movie. So I try to flush data from the swr buffer and encode it too.
I flush after every third input frame (384 * 3 = 1152 - we have one full 
output extra frame).
In such scenario I have complete audio stream but it has a lot of 
strange artifacts.
I've tried change PTS/DTS, rescale, etc., but it doesn't help (Or i have 
audio that plays faster without artifacts , or normal audio speed with 

Also may be somebody knows can I use av_samples copy() without 
swr_convert() in this case.

I will be glad to any advice.

Thank you.
Andrew Sherepenko

More information about the Libav-user mailing list