[Libav-user] Synchronization of audio and video streams during muxing

Michael IV explomaster at gmail.com
Sat Mar 17 18:34:03 EET 2018

Hi, I am rewriting some messy FFMPEG code I wrote a while ago.
My reference is muxing.c
The difference I have is that my audio stream comes from file (AAC) ,while
video packets
come from generated pixel frame.

I mostly have it working,but my problem is interleaved packets write.If I
do it like the example,that's

int cc = av_compare_ts(mVideoOutStream.next_pts,
mAudioOutStream.next_pts, mAudioOutStream.enc->time_base);

if (mAudioOutStream.st == NULL || cc <= 0)

   //write video
  //write audo.

I am not getting correct results.

The only way it looks fine is if I do it like this:

  //Write video frame first ,always!


if(cc > 0)

   //write audio packets.


I don't understand why it works only in this case. From what I
understood av_interleaved_write_frame() should take care of the correct
interleaving. But I see that I must write video frames always,and audio
packets only when  av_compare_ts is greater than zero.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20180317/a5a31ff0/attachment.html>

More information about the Libav-user mailing list