[Libav-user] How to control av_write_frame() to get a correct frame sequence.

Li Zhang lizhang at utelisys.com
Mon Jun 18 11:30:00 CEST 2012



Hi everyone,

I have a problem when I used av_write_frame() or av_interleaved_write_frame() for TS muxer.  The sequence of video and audio is not what I wanted to have.

I was trying to output a video frame, and then an audio frame which has similar dts or pts with that video frame. Loop this process, if their dts are different too much, then output a video or audio frame which is slower than the other. However, I can not control the output frame sequence when I used the av_write_frame() or av_interleaved_write_frame().

For example, for my situation, video rate:128kbps, audio:32kbps, then the final output frame sequence I got was: 10-12 video frames and then 10 audio frames(16 188-ts-packets). Then, when I use VLC to play this stream, it always said that like "buffer too early (-40364), down-sampling". After 10 hours, the audio and video is in-synchronized, and audio is about 5 seconds earlier than video.

I have tried let VLC to transcode the same stream and output stream with the same parameters. I check VLC'S output stream sequence: video frame-> audio frame->video frame->audio->frame->video frame-> audio frame->video frame->video frame... ....

So I am wondering how to control the muxer in ffmpeg to get an output stream with the correct sequence which I want to have.

Thanks in advance.


Best regards,

Li


More information about the Libav-user mailing list