You are not logged in.

#1 2013-01-31 04:14:25

OniLink
Member
Registered: 2012-09-08
Posts: 5

FFMPEG desktop capture slowly desyncs audio

I'm trying to record footage from a video game using ffmpeg, but I'm running into an annoying issue with audio desync. The video starts out with video and audio synced perfectly, but as the recording goes on, the audio slowly drifts out of sync. By four minutes into a recording, the audio is playing one or two seconds later than it should. By five minutes, the audio is four or five seconds late. I don't have any issues with dropped frames or lag (or at least, ffmpeg reports everything as fine on that end, and I notice no lag when playing, and that only dropped frames I see, which are minor, occur after the desync is already pretty bad).

I have a test recording that shows this problem here.

The command I use to capture is

ffmpeg -f alsa -ac 2 -i pulse -async 1 -f x11grab -r 30 -s 640x480 -i :0.0+256,256 -acodec pcm_s16le -vcodec libx264 -crf 0 -preset ultrafast -threads 0 -y Capture.mkv

Thanks in advance.

Offline

#2 2013-01-31 21:00:39

DrZaius
Member
Registered: 2008-01-02
Posts: 166

Re: FFMPEG desktop capture slowly desyncs audio

The complete ffmpeg console output is always useful when you're asking for help with ffmpeg. Have you tried it without "-async 1"? What if you change "-acodec pcm_s16le" to "-acodec copy"?


Damned dirty ape.

Offline

#3 2013-02-01 00:35:06

OniLink
Member
Registered: 2012-09-08
Posts: 5

Re: FFMPEG desktop capture slowly desyncs audio

Without -async 1 does not help. That's actually what I started with. I thought I heard a slight improvement with it, but that could have been a trick of the mind.

Changing the audio codec to copy seemed to help, but not much.

FFMPEG's beginning of recording output looked like this for testing with -acodec copy:

ffmpeg version 1.0.1 Copyright (c) 2000-2012 the FFmpeg developers
  built on Dec  7 2012 18:16:36 with gcc 4.7.2 (GCC)
  configuration: --prefix=/usr --enable-libmp3lame --enable-libvorbis --enable-libxvid --enable-libx264 --enable-libvpx --enable-libtheora --enable-libgsm --enable-libspeex --enable-postproc --enable-shared --enable-x11grab --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libschroedinger --enable-libopenjpeg --enable-librtmp --enable-libpulse --enable-libv4l2 --enable-gpl --enable-version3 --enable-runtime-cpudetect --disable-debug --disable-static
  libavutil      51. 73.101 / 51. 73.101
  libavcodec     54. 59.100 / 54. 59.100
  libavformat    54. 29.104 / 54. 29.104
  libavdevice    54.  2.101 / 54.  2.101
  libavfilter     3. 17.100 /  3. 17.100
  libswscale      2.  1.101 /  2.  1.101
  libswresample   0. 15.100 /  0. 15.100
  libpostproc    52.  0.100 / 52.  0.100
[alsa @ 0x1d88320] Estimating duration from bitrate, this may be inaccurate
Guessed Channel Layout for  Input Stream #0.0 : stereo
Input #0, alsa, from 'pulse':
  Duration: N/A, start: 1359674047.157797, bitrate: 1536 kb/s
    Stream #0:0: Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s
[x11grab @ 0x1d89120] device: :0.0+256,256 -> display: :0.0 x: 256 y: 256 width: 640 height: 480
[x11grab @ 0x1d89120] shared memory extension found
[x11grab @ 0x1d89120] Estimating duration from bitrate, this may be inaccurate
Input #1, x11grab, from ':0.0+256,256':
  Duration: N/A, start: 1359674047.274138, bitrate: 294912 kb/s
    Stream #1:0: Video: rawvideo (BGR[0] / 0x524742), bgr0, 640x480, 294912 kb/s, 30 tbr, 1000k tbn, 30 tbc
[libx264 @ 0x1d83b80] using cpu capabilities: MMX2 SSE2Fast SSSE3 FastShuffle SSE4.1 Cache64
[libx264 @ 0x1d83b80] profile High 4:4:4 Predictive, level 3.0, 4:4:4 8-bit
[libx264 @ 0x1d83b80] 64 - core 128 - H.264/MPEG-4 AVC codec - Copyleft 2003-2012 - http://www.videolan.org/x264.html - options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=0 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=0 chroma_qp_offset=0 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=250 keyint_min=25 scenecut=0 intra_refresh=0 rc=cqp mbtree=0 qp=0
Output #0, matroska, to 'Capture.mkv':
  Metadata:
    encoder         : Lavf54.29.104
    Stream #0:0: Video: h264, yuv444p, 640x480, q=-1--1, 1k tbn, 30 tbc
    Stream #0:1: Audio: pcm_s16le, 48000 Hz, stereo, 1536 kb/s
Stream mapping:
  Stream #1:0 -> #0:0 (rawvideo -> libx264)
  Stream #0:0 -> #0:1 (copy)

The end of recording looked like this:

video:661645kB audio:72734kB subtitle:0 global headers:0kB muxing overhead 0.289224%
[libx264 @ 0x1d83b80] frame I:47    Avg QP: 0.00  size:117771
[libx264 @ 0x1d83b80] frame P:11554 Avg QP: 0.00  size: 58161
[libx264 @ 0x1d83b80] mb I  I16..4: 100.0%  0.0%  0.0%
[libx264 @ 0x1d83b80] mb P  I16..4: 25.6%  0.0%  0.0%  P16..4: 16.6%  0.0%  0.0%  0.0%  0.0%    skip:57.8%
[libx264 @ 0x1d83b80] coded y,u,v intra: 71.4% 63.7% 60.2% inter: 17.0% 14.7% 14.0%
[libx264 @ 0x1d83b80] i16 v,h,dc,p: 46% 54%  0%  0%
[libx264 @ 0x1d83b80] kb/s:14016.52

Offline

#4 2013-02-02 02:59:32

Chuck Arch Linux
Member
Registered: 2011-06-23
Posts: 60

Re: FFMPEG desktop capture slowly desyncs audio

For me when recording my desktop whit microphone support I've add this:

-framerate 30

before your -r 30 and it gave me perfect synchronisation.
I don't use the async.

Whitout -framerate 30, the video is not sync in audio and playback speed.

Hope it help.

Last edited by Chuck Arch Linux (2013-02-02 03:00:14)

Offline

#5 2013-02-04 07:26:22

OniLink
Member
Registered: 2012-09-08
Posts: 5

Re: FFMPEG desktop capture slowly desyncs audio

Chuck Arch Linux wrote:

For me when recording my desktop whit microphone support I've add this:

-framerate 30

before your -r 30 and it gave me perfect synchronisation.
I don't use the async.

Whitout -framerate 30, the video is not sync in audio and playback speed.

Hope it help.

That didn't help either. At all.

Offline

#6 2013-02-04 19:29:59

DrZaius
Member
Registered: 2008-01-02
Posts: 166

Re: FFMPEG desktop capture slowly desyncs audio

Try the ffmpeg-user mailing list.


Damned dirty ape.

Offline

#7 2013-09-01 20:03:22

donatom
Member
From: West Coast (California)
Registered: 2012-12-23
Posts: 25

Re: FFMPEG desktop capture slowly desyncs audio

Ever since I updated arch linux (mid August, 2013), audio would be out of sync after capturing streamed video from desktop using ffmpeg (from zdf.de, a German language site which allows you to view German language movies). I tried everything (-async 1, -crf 0, -pix_fmt yuv420p, etc), but nothing worked. Today I downgraded ffmpeg 2.0.1-1 to ffmpeg 2.0-2 and video and audio are in sync once again. It is possible that there is a bug in ffmpeg 2.0.1-1, although I saw no mention of this during my many google expeditions.

Here is the command I use (minus any changes that I tried): 

ffmpeg -f alsa -ac 2 -i pulse -f x11grab -r 30 -s 910x490 -i :0.0+0,270 -acodec pcm_s16le -vcodec libx264  -preset ultrafast  -threads 0 Test.mkv

I had the above problem on two different machines (e6300 Intel processor with 2 gigs memory on an Intel motherboard and an i5 Intel processor with 16 gig memory on another Intel motherboard).

For those having problems with syncing, you might want to try to downgrade. Refer to: https://wiki.archlinux.org/index.php/Do … g_Packages. If you haven't recently updated arch, then it is an extremely easy process.

Offline

#8 2013-09-02 18:18:28

DrZaius
Member
Registered: 2008-01-02
Posts: 166

Re: FFMPEG desktop capture slowly desyncs audio

If you have the time or motivation performing a git-bisect will find the responsible commit(s) involved in a possible regression.


Damned dirty ape.

Offline

#9 2013-09-11 19:13:57

donatom
Member
From: West Coast (California)
Registered: 2012-12-23
Posts: 25

Re: FFMPEG desktop capture slowly desyncs audio

After another round of arch updates, the older version of ffmpeg again results in audio and video that are out of sync, so I am back where I started from.

Oh, well. I guess I have to keep on googling (although ffmpeg on Fedora 17 will capture with audio and video in sync, so until I get this resoved, I will be using Fedora more than I usually do).

Offline

#10 2013-09-12 00:56:42

donatom
Member
From: West Coast (California)
Registered: 2012-12-23
Posts: 25

Re: FFMPEG desktop capture slowly desyncs audio

Out of desperation I added "async 1" (which is deprecated and which I tried several times before -- without any luck) to the ffmpeg command line.  Amazingly everything is now in sync. The following is the exact set of commands I used:

ffmpeg -f alsa -ac 2 -i pulse -async 1 -f x11grab  -r 30 -s 910x490 -i :0.0+0,330 -acodec pcm_s16le -vcodec libx264  -preset ultrafast  -threads 0 DieFremde.mkv

I hope this command continues to work for me and I am very puzzled at the fact that a deprecated command can solve a recent problem with ffmpeg desktop capturing.

Offline

#11 2013-09-12 03:14:56

xpander
Member
Registered: 2013-01-23
Posts: 54

Re: FFMPEG desktop capture slowly desyncs audio

try with my script: https://dl.dropboxusercontent.com/u/28788188/cast.sh

i only have this out of sync problem sometimes with really high demanding games.
but usually its not a problem for me with that script at least.

with Simple Screen Recorder for example i get a lot of it.

Offline

#12 2013-09-12 19:55:22

donatom
Member
From: West Coast (California)
Registered: 2012-12-23
Posts: 25

Re: FFMPEG desktop capture slowly desyncs audio

Thanks xpander. I've looked over the script, and it looks fairly straight-forward. In the near future I will plug in info for my machine and  the streamed video window and see how it goes. Will let you know. I saw your script during my googling, but I wasn't sure why I would need a script to get ffmpeg to properly record streamed video. But if it works, it works. Thanks again.

Offline

#13 2013-09-13 00:40:15

donatom
Member
From: West Coast (California)
Registered: 2012-12-23
Posts: 25

Re: FFMPEG desktop capture slowly desyncs audio

xpander, I tried running the script after plugging in my own info but script did not succeed in capturing desktop. Here is terminal output when I ran the script:

[donatom@arch ~]$ ./Downloads/cast.sh
ffmpeg version 2.0.1 Copyright (c) 2000-2013 the FFmpeg developers
  built on Aug 11 2013 14:52:28 with gcc 4.8.1 (GCC) 20130725 (prerelease)
  configuration: --prefix=/usr --disable-debug --disable-static --enable-avresample --enable-dxva2 --enable-fontconfig --enable-gpl --enable-libass --enable-libbluray --enable-libfreetype --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libv4l2 --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --enable-pic --enable-postproc --enable-runtime-cpudetect --enable-shared --enable-swresample --enable-vdpau --enable-version3 --enable-x11grab
  libavutil      52. 38.100 / 52. 38.100
  libavcodec     55. 18.102 / 55. 18.102
  libavformat    55. 12.100 / 55. 12.100
  libavdevice    55.  3.100 / 55.  3.100
  libavfilter     3. 79.101 /  3. 79.101
  libavresample   1.  1.  0 /  1.  1.  0
  libswscale      2.  3.100 /  2.  3.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  3.100 / 52.  3.100
Guessed Channel Layout for  Input Stream #0.0 : stereo
Input #0, alsa, from 'pulse':
  Duration: N/A, start: 1379032099.511522, bitrate: 1536 kb/s
    Stream #0:0: Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s
[x11grab @ 0x18a4020] device: :0.0+0,310 -> display: :0.0 x: 0 y: 310 width: 910 height: 490
[x11grab @ 0x18a4020] shared memory extension found
Input #1, x11grab, from ':0.0+0,310':
  Duration: N/A, start: 1379032099.563057, bitrate: 428064 kb/s
    Stream #1:0: Video: rawvideo (BGR[0] / 0x524742), bgr0, 910x490, 428064 kb/s, 30 tbr, 1000k tbn, 30 tbc
No pixel format specified, yuv444p for H.264 encoding chosen.
Use -pix_fmt yuv420p for compatibility with outdated media players.
[libx264 @ 0x18bd880] using cpu capabilities: MMX2 SSE2Fast SSSE3 Cache64
[libx264 @ 0x18bd880] profile High 4:4:4 Predictive, level 3.1, 4:4:4 8-bit
[libx264 @ 0x18bd880] 264 - core 133 r2339 585324f - H.264/MPEG-4 AVC codec - Copyleft 2003-2013 - http://www.videolan.org/x264.html - options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=6 threads=3 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=250 keyint_min=25 scenecut=0 intra_refresh=0 rc=crf mbtree=0 crf=20.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=0
[mp4 @ 0x18bde00] track 1: could not find tag, codec not currently supported in container
Output #0, mp4, to '/home/donatom/Desktopvideocast12092013_17.28.19.mp4':
  Metadata:
    encoder         : Lavf55.12.100
    Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv444p, 910x490, q=-1--1, 15360 tbn, 30 tbc
    Stream #0:1: Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s
Stream mapping:
  Stream #1:0 -> #0:0 (rawvideo -> libx264)
  Stream #0:0 -> #0:1 (pcm_s16le -> pcm_s16le)
Could not write header for output file #0 (incorrect codec parameters ?): Operation not permitted

I see the warning "... codec currently not supported in container." Does that refer to the .mp4 output? I tried to plug in mkv instead, but script wouldn't accept that parameter.

Offline

#14 2013-09-13 01:09:13

DrZaius
Member
Registered: 2008-01-02
Posts: 166

Re: FFMPEG desktop capture slowly desyncs audio

donatom wrote:
[mp4 @ 0x18bde00] track 1: could not find tag, codec not currently supported in container

PCM is not supported in MP4 container. Use Matroska instead (.mkv), or use a different audio format.

Use the code tag in your forum posts.


Damned dirty ape.

Offline

#15 2013-09-13 02:44:58

donatom
Member
From: West Coast (California)
Registered: 2012-12-23
Posts: 25

Re: FFMPEG desktop capture slowly desyncs audio

Sorry. As far as mkv, I tried it and the script stated that it wasn't supported. Here is the output in terminal when I ran the xpander's script (hope code tag works)

[donatom@arch ~]$ ./Downloads/cast.sh
ffmpeg version 2.0.1 Copyright (c) 2000-2013 the FFmpeg developers
  built on Aug 11 2013 14:52:28 with gcc 4.8.1 (GCC) 20130725 (prerelease)
  configuration: --prefix=/usr --disable-debug --disable-static --enable-avresample --enable-dxva2 --enable-fontconfig --enable-gpl --enable-libass --enable-libbluray --enable-libfreetype --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libv4l2 --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --enable-pic --enable-postproc --enable-runtime-cpudetect --enable-shared --enable-swresample --enable-vdpau --enable-version3 --enable-x11grab
  libavutil      52. 38.100 / 52. 38.100
  libavcodec     55. 18.102 / 55. 18.102
  libavformat    55. 12.100 / 55. 12.100
  libavdevice    55.  3.100 / 55.  3.100
  libavfilter     3. 79.101 /  3. 79.101
  libavresample   1.  1.  0 /  1.  1.  0
  libswscale      2.  3.100 /  2.  3.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  3.100 / 52.  3.100
Guessed Channel Layout for  Input Stream #0.0 : stereo
Input #0, alsa, from 'pulse':
  Duration: N/A, start: 1379032099.511522, bitrate: 1536 kb/s
    Stream #0:0: Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s
[x11grab @ 0x18a4020] device: :0.0+0,310 -> display: :0.0 x: 0 y: 310 width: 910 height: 490
[x11grab @ 0x18a4020] shared memory extension found
Input #1, x11grab, from ':0.0+0,310':
  Duration: N/A, start: 1379032099.563057, bitrate: 428064 kb/s
    Stream #1:0: Video: rawvideo (BGR[0] / 0x524742), bgr0, 910x490, 428064 kb/s, 30 tbr, 1000k tbn, 30 tbc
No pixel format specified, yuv444p for H.264 encoding chosen.
Use -pix_fmt yuv420p for compatibility with outdated media players.
[libx264 @ 0x18bd880] using cpu capabilities: MMX2 SSE2Fast SSSE3 Cache64
[libx264 @ 0x18bd880] profile High 4:4:4 Predictive, level 3.1, 4:4:4 8-bit
[libx264 @ 0x18bd880] 264 - core 133 r2339 585324f - H.264/MPEG-4 AVC codec - Copyleft 2003-2013 - http://www.videolan.org/x264.html - options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=6 threads=3 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=250 keyint_min=25 scenecut=0 intra_refresh=0 rc=crf mbtree=0 crf=20.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=0
[mp4 @ 0x18bde00] track 1: could not find tag, codec not currently supported in container
Output #0, mp4, to '/home/donatom/Desktopvideocast12092013_17.28.19.mp4':
  Metadata:
    encoder         : Lavf55.12.100
    Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv444p, 910x490, q=-1--1, 15360 tbn, 30 tbc
    Stream #0:1: Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s
Stream mapping:
  Stream #1:0 -> #0:0 (rawvideo -> libx264)
  Stream #0:0 -> #0:1 (pcm_s16le -> pcm_s16le)
Could not write header for output file #0 (incorrect codec parameters ?): Operation not permitted

I see the warning "... codec currently not supported in container." Does that refer to the .mp4 output? I tried to plug in mkv instead, but script wouldn't accept that parameter.

Offline

#16 2013-09-13 02:53:33

DrZaius
Member
Registered: 2008-01-02
Posts: 166

Re: FFMPEG desktop capture slowly desyncs audio

donatom wrote:
Output #0, mp4, to '/home/donatom/Desktopvideocast12092013_17.28.19.mp4':

It is still outputting to mp4 container.

You need to change:

FILENAME=videocast`$DATE +%d%m%Y_%H.%M.%S`.mp4

to:

FILENAME=videocast`$DATE +%d%m%Y_%H.%M.%S`.mkv

And:

-f mp4

to:

-f matroska

Or don't use this messy script and use ffmpeg directly as shown in HOWTO: Proper Screencasting on Linux.


Damned dirty ape.

Offline

#17 2013-09-13 04:17:27

donatom
Member
From: West Coast (California)
Registered: 2012-12-23
Posts: 25

Re: FFMPEG desktop capture slowly desyncs audio

DrZaius, thanks for the explanation about mkv/matroska (I made these changes, but used -f mkv instead of -f matroska). I agree with you that it is better to use ffmpeg directly. As I said before I finally am able to capture the desktop with audio/video in sync once again. I will check out the website that you suggest to see if I can gain some more insight into the use of ffmpeg (maybe without having to resort to using "-async 1").

Offline

#18 2013-09-16 06:20:38

donatom
Member
From: West Coast (California)
Registered: 2012-12-23
Posts: 25

Re: FFMPEG desktop capture slowly desyncs audio

The command I have recently been using to successfully capture streamed video with ffmpeg does not work on my other machine (-i5 Intel processor, 16 gigs memory, on-board video). I had to add the option "-y" to get it to capture with video and audio in sync. Here is the command that does work on my second machine:

ffmpeg -f alsa -ac 2 -i pulse -async 1 -f x11grab  -r 30 -s 910x490 -i :0.0+0,310 -acodec pcm_s16le -vcodec libx264  -preset ultrafast  -threads 0 -y Lebensbund.mkv

ffmpeg seems to be somewhat tempermental.

Offline

#19 2013-10-15 20:06:59

AleXoundOS
Member
From: Russia
Registered: 2009-07-18
Posts: 31
Website

Re: FFMPEG desktop capture slowly desyncs audio

donatom wrote:

The command I have recently been using to successfully capture streamed video with ffmpeg does not work on my other machine (-i5 Intel processor, 16 gigs memory, on-board video). I had to add the option "-y" to get it to capture with video and audio in sync. Here is the command that does work on my second machine:

ffmpeg -f alsa -ac 2 -i pulse -async 1 -f x11grab  -r 30 -s 910x490 -i :0.0+0,310 -acodec pcm_s16le -vcodec libx264  -preset ultrafast  -threads 0 -y Lebensbund.mkv

ffmpeg seems to be somewhat tempermental.

"-y" option stands for "Overwrite output files without asking."

Offline

#20 2013-10-16 16:06:44

donatom
Member
From: West Coast (California)
Registered: 2012-12-23
Posts: 25

Re: FFMPEG desktop capture slowly desyncs audio

Recently (after another arch linux update) streamed video captured with ffmpeg was again out of sync -- even on Fedora 18. By leaving out "-async 1" the video (on both Fedora and Arch) was again in sync.

Offline

#21 2013-10-25 01:15:19

jwhendy
Member
Registered: 2010-04-01
Posts: 537

Re: FFMPEG desktop capture slowly desyncs audio

I'm unable to create a video with audio and video in sync, with or without `-async 1` in the command. Is there a definitive resolution on this issue that works with the current Arch version of ffmpeg? Here are the commands I've tried:

$ ffmpeg -f alsa -ac 1 -i hw:2,0 -async 1 -f x11grab -r 30 -s 1600x900 -i :0.0 -b:v 4096 -acodec libmp3lame -vcodec libx264 -preset ultrafast -qp 0 output.mkv
$ ffmpeg -f alsa -ac 1 -i hw:2,0 -f x11grab -r 30 -s 1600x900 -i :0.0 -b:v 4096 -acodec libmp3lame -vcodec libx264 -preset ultrafast -vsync 1 -qp 0 output.mkv
$ ffmpeg -f alsa -ac 1 -i hw:2,0 -f x11grab -r 30 -s 1600x900 -i :0.0 -b:v 4096 -acodec libmp3lame -vcodec libx264 -preset ultrafast -qp 0 -async 1 output.mkv
$ ffmpeg -f alsa -ac 1 -i hw:2,0 -f x11grab -r 30 -s 1600x900 -i :0.0 -b:v 4096 -acodec libmp3lame -async 1 -vcodec libx264 -preset ultrafast -vsync 1 -qp 0 output.mkv

In each, it starts out by appearing exactly correct, but by the end it's a good 2-4 seconds off (~20min total screencast).

Extremely frustrating, and it's very hard to predict. I've made some short ~10sec videos and said something as I did something to check out my command. Some obviously were out of sync from the start, others were not. For the ones that weren't, I gave it a shot with the full screencast run through, only to find that the video was out of sync by the end (video ahead of audio).

Is there a way to troubleshoot/diagnose, or a way to convert from un-synced to properly synced?

Offline

#22 2013-10-25 03:51:41

donatom
Member
From: West Coast (California)
Registered: 2012-12-23
Posts: 25

Re: FFMPEG desktop capture slowly desyncs audio

jwhendy,

I have an up-to-date Arch system and am able to capture live streamed video completely in sync. -async 1 doesn't work (any longer). It seems that you need to include the -y option right before the name of your output video file in order to get audio and video in sync. Lately I have had to resort to a lot of trial and error to get captured video in sync. Here is what works for me (currently):


  ffmpeg -f alsa -ac 2 -i pulse -f x11grab -r 30 -s 910x490 -i :0.0+0,270 -acodec pcm_s16le -vcodec libx264  -preset ultrafast  -threads 0 -y Test.mkv  

I noticed that you are not including "-i pulse". You might want to include it in your ffmpeg command.

Offline

#23 2013-10-25 03:54:25

donatom
Member
From: West Coast (California)
Registered: 2012-12-23
Posts: 25

Re: FFMPEG desktop capture slowly desyncs audio

Seems like this site is cutting off the last part of the command when using code tag. Here is my entire command:

ffmpeg -f alsa -ac 2 -i pulse -f x11grab -r 30 -s 910x490 -i :0.0+0,270 -acodec pcm_s16le -vcodec libx264  -preset ultrafast  -threads 0 -y Test.mkv

Last edited by donatom (2013-10-27 03:51:56)

Offline

#24 2013-10-25 11:22:11

OrdinaryMagician
Member
From: Spain
Registered: 2013-08-21
Posts: 15
Website

Re: FFMPEG desktop capture slowly desyncs audio

Personally I have found that setting the framerate on the output rather than on the input fixes the sync issues.


I'm just an ordinary magician...

Offline

Board footer

Powered by FluxBB