In a video previewer that I am writing, I am trying to synchronize the audio to 
the video as in ffplay.c with av_sync_type = AV_SYNC_VIDEO_MASTER.   The 
resulting audio seems to be in sync with the video; however, it is warbly, like 
it's playing through water or something.  Obviously, I am missing something in 
mimicking the technique from ffplay.c

In synchronize_audio() of ffplay.c, there is this line:
diff = get_audio_clock(is) - get_master_clock(is);
I am using the get_audio_clock() as in ffplay, but for the get_master_clock(), 
I am using a custom get_video_clock() directly, as I will always be syncing to 
the video.  However, I am not using the same function as in ffplay.c, because I 
am not handling the video stream through a PacketQueue.

My app performs video analysis on the video frames as they are decoded and then 
passes them to a Windows C# UI for display and optional saving to disk.   The 
throughput of the video analysis drives the video playback.  That is, when it 
is done processing a frame, then it requests the next one.   If the processing 
takes less time than a frame interval, then I insert a delay to ensure that the 
playback is close to real time for the user.  (Maybe this is not the best 
design?)

Therefore, I would like the audio to follow the video. The problem seems to be 
in getting the proper value for the video "clock".  To this end, I have been 
using a function as in Dranger's tutorial06.c:
double get_video_clock(VideoState *is) {
                double delta;
                delta = (av_gettime() - video_current_pts_time) / 1000000.0;
                return video_current_pts + delta;
}
where delta is amount of time since the video_current_pts was obtained.  Seems 
to me that this should work in my context, yet the result is not yet 
acceptable.  If I change the function to simply
return video_current_pts;
Then the warble is more pronounced.

How do I get the audio to properly synchronize with the video?
_______________________________________________
Libav-user mailing list
[email protected]
http://ffmpeg.org/mailman/listinfo/libav-user

Reply via email to