[Ffmpeg-devel] How to sync audi and video

Paul paul.pham
Thu Jan 25 10:50:45 CET 2007


i have audio frame(s) and video frame in every cycle , then i want to write these to "output_media.mpg" file.

Below are what i will do in a thread :

Thread_Record()
{
    while(still_run)
    {
        //get captured buffer audio, encoding to MPEG 1 audio frame(s)
        //write audio frame(s) to output_media file
        //get captured buffer video, encoding to MPEG video frame
        //write video frame to output_media file
        //call sleep(40); (framerate = 25)
    }

}

if want to stop. still_run is assigned "false" to and then stop the thread.

i wonder using ffmpeg library can do that? Anyone know (sample code) how to do as above?

Before , i write audio frames to "audio_tmp.mp2" and video frames to "video_tmp.mpg" .After finish these file i will use ffmpeg.exe to merge to "output_media.mpg" . But this way can cause video and audio not sync. 

Final, if the thought as above cannot make synch, Can you show me any way to sync audio and video?



More information about the ffmpeg-devel mailing list