[FFmpeg-user] Video and audio desync when recording screen

Leonardo Soares Müller leozinho29_eu at hotmail.com
Thu May 11 02:05:52 EEST 2017


Hello

I am trying to record my screen on Xubuntu 16.04.2. While I can record 
both video and audio, on some software the video and audio are out of 
sync. When watching the video in VLC, the audio and the video are in 
sync, but when editing with Kdenlive or uploading directly the video to 
YouTube, audio and video get out of sync.

I am using a script to do this recording. The command line, considering 
its options, would be:

env PULSE_LATENCY_MSEC=25 ffmpeg \
-vaapi_device /dev/dri/renderD128 -hwaccel vaapi -hwaccel_output_format 
yuv420p  \
-thread_queue_size 4096 -f pulse -sample_rate 44100 -channels 2 -i 
alsa_output.pci-0000_00_1f.3.analog-stereo.monitor \
-thread_queue_size 1024 -f x11grab -s 1366x768 -r "30" -i :0.0 \
-acodec libfdk_aac -b:a 160k \
-vf 'format=nv12,hwupload,scale_vaapi=w=1280:h=720' -vcodec h264_vaapi 
-qp 24 \
-f flv -strict experimental TEST4.flv

The output on terminal is:

ffmpeg version N-85539-g5caaa3a Copyright (c) 2000-2017 the FFmpeg 
developers
   built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 20160609
   configuration: --enable-shared --disable-stripping 
--disable-decoder=libopenjpeg --disable-decoder=libschroedinger 
--enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa 
--enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca 
--enable-libcdio --enable-libflite --enable-libfontconfig 
--enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm 
--enable-libmodplug --enable-libmp3lame --enable-libopenjpeg 
--enable-libopus --enable-libpulse --enable-librtmp 
--enable-libschroedinger --enable-libshine --enable-libsnappy 
--enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora 
--enable-libtwolame --enable-libvorbis --enable-libvpx 
--enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid 
--enable-libzvbi --enable-openal --enable-opengl --enable-libdc1394 
--enable-libiec61883 --enable-libzmq --enable-frei0r --enable-libx264 
--enable-libopencv --enable-libfdk-aac --enable-libmfx --enable-vaapi 
--enable-nonfree --enable-gpl --enable-libxcb --enable-libxcb-shm 
--enable-libxcb-xfixes --enable-libxcb-shape
   libavutil      55. 61.100 / 55. 61.100
   libavcodec     57. 92.100 / 57. 92.100
   libavformat    57. 72.101 / 57. 72.101
   libavdevice    57.  7.100 / 57.  7.100
   libavfilter     6. 84.101 /  6. 84.101
   libavresample   3.  6.  0 /  3.  6.  0
   libswscale      4.  7.101 /  4.  7.101
   libswresample   2.  8.100 /  2.  8.100
   libpostproc    54.  6.100 / 54.  6.100
libva info: VA-API version 0.39.0
libva info: va_getDriverName() returns 0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so
libva info: Found init function __vaDriverInit_0_39
libva info: va_openDriver() returns 0
Guessed Channel Layout for Input Stream #0.0 : stereo
Input #0, pulse, from 'alsa_output.pci-0000_00_1f.3.analog-stereo.monitor':
   Duration: N/A, start: 1494455796.589364, bitrate: 1411 kb/s
     Stream #0:0: Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s
[x11grab @ 0x16073a0] Stream #0: not enough frames to estimate rate; 
consider increasing probesize
Input #1, x11grab, from ':0.0':
   Duration: N/A, start: 1494455796.988299, bitrate: N/A
     Stream #1:0: Video: rawvideo (BGR[0] / 0x524742), bgr0, 1366x768, 
30 fps, 1000k tbr, 1000k tbn, 1000k tbc
Stream mapping:
   Stream #1:0 -> #0:0 (rawvideo (native) -> h264 (h264_vaapi))
   Stream #0:0 -> #0:1 (pcm_s16le (native) -> aac (libfdk_aac))
Press [q] to stop, [?] for help
[swscaler @ 0x1636ba0] Warning: data is not aligned! This can lead to a 
speedloss
Output #0, flv, to 'TEST4.flv':
   Metadata:
     encoder         : Lavf57.72.101
     Stream #0:0: Video: h264 (h264_vaapi) (High) ([7][0][0][0] / 
0x0007), vaapi_vld(progressive), 1280x720, q=0-31, 30 fps, 1k tbn, 30 tbc
     Metadata:
       encoder         : Lavc57.92.100 h264_vaapi
     Stream #0:1: Audio: aac (libfdk_aac) ([10][0][0][0] / 0x000A), 
44100 Hz, stereo, s16, 160 kb/s
     Metadata:
       encoder         : Lavc57.92.100 libfdk_aac
frame=  897 fps= 30 q=-0.0 Lsize=    3430kB time=00:00:29.83 bitrate= 
941.9kbits/s speed=0.999x
video:2808kB audio:583kB subtitle:0kB other streams:0kB global 
headers:0kB muxing overhead: 1.157823%

While I am using VAAPI, the fact audio and video get out of sync on some 
software happens too when using software encoding (plus 65% of CPU usage).

On the output of the terminal, it can be seen that the start of pulse 
stream is 1494455796.589364, while the x11grab stream starts at 
1494455796.988299. Can this be why video and audio are out of sync on 
Kdenlive and YouTube?

If yes, is there a way to make the streams start at the same time?

Thank you.


More information about the ffmpeg-user mailing list