[Libav-user] Muxing audio and video streams with different length

Michael IV explomaster at gmail.com
Mon Mar 19 10:42:52 EET 2018

Hi all. I have a nasty bug. I have written a muxer,which is based on
muxing.c sample.
The only different is that in my case audio stream comes from AAC file.And
if the sound track's
time is longer than video total time,then the overall resulting video time
becomes larger than expected. Here is the whole question I asked on


And I don't understand why the sync based on comparing ts time of audio and
video packets doesn't help here. I had to do something like this for audio

AVRational r = {  60 ,1 };

     auto cmp= av_compare_ts(mAudioOutStream.next_pts,
mAudioOutStream.enc->time_base, 5, r);
     if (cmp>=0)
         mAudioOutStream.next_pts =
         return true; //don't mux audio anymore

where '5' is five seconds total video length. This is the only what looks
like close.But it doesn't work for all audio files.If I use aac mono with
some non standard sample rate,I still get total 6 seconds video size
instead of 5 seconds. Will appreciate any help. Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20180319/cbce683c/attachment.html>

More information about the Libav-user mailing list