[FFmpeg-user] Audio synchronisation issues

Dainius (GreatEmerald) pastas4 at gmail.com
Fri May 4 15:56:58 CEST 2012


I am trying to record the screen, system sounds and microphone at the
same time, yet keep everything in sync. However, for some reason, it
doesn't work as it should, in that the length of the recorded streams
is the same, yet the audio and video are still out of sync (the desync
amount seems to change, but in an odd way, it starts desynced already
and gets either better or worse over time). This is what I use to
record my videos, without any special syncing:

/usr/bin/ffmpeg -xerror \
 -f x11grab -r 30 -s 800x600 -i :0.0+2,23 \
 -f pulse -i alsa_output.pci-0000_03_07.0.analog-stereo.monitor \
 -f pulse -i alsa_input.pci-0000_00_14.2.analog-stereo \
 -map 0 -vcodec mpeg4 -q:v 3 -qcomp 0.8 -threads 0 -an -timestamp now
-y Video.mp4 \
 -map 1 -threads 0 -vn -y AudioA.wav \
 -map 2 -threads 0 -vn -y AudioB.wav

Now I did try to fiddle around with -vsync and -async, but I don't
really understand how they work or when to use them. If I set the maps
to 0 1,0 2,0 and set async for both audio streams to 2, the recording
starts with very low framerates and eventually goes down to 0 FPS. If
I set maps to 0,1 1 2,1 and use vsync on the first stream (with either
of the modes) and async 2 on the last, it gets recorded correctly, but
I don't see any changes at all - the streams are still out of sync.
Interestingly enough, it seems that the audio streams are generally
well synced together, while the video stream seems to be
(inconsistently) in front by a second or so.

I also tried to use async in the processing, and not the recording
phase of production (are timestamps stored permanently in the video
and audio, so that this would be possible to begin with?), like this:

/usr/bin/ffmpeg -xerror  -i Video.mp4 \
 -i AudioA.wav \
 -i AudioB.wav \
 -map 0 -an -y VideoS.mp4 \
 -map 1,0 -async 2 -acodec libvorbis -threads 0 -y AudioAS.ogg \
 -map 2,0 -async 2 -acodec libvorbis -threads 0 -y AudioBS.ogg

...but it somehow produces audio that is unplayable (silent or just
refuses to play). Without the async parameter, everything gets played
fine. Not sure what could be the cause of that, either.

According to the task manager, my CPU is hardly utilised, so it can't
be a performance problem. So I'm not sure what causes the whole desync
in the first place... Any ideas about how to get the streams
synchronised?


More information about the ffmpeg-user mailing list