Create a screencast with ffmpeg: how to keep video+audio in sync? The 2019 Stack Overflow...

If a Druid sees an animal’s corpse, can they wild shape into that animal?

A poker game description that does not feel gimmicky

How technical should a Scrum Master be to effectively remove impediments?

Why was M87 targetted for the Event Horizon Telescope instead of Sagittarius A*?

For what reasons would an animal species NOT cross a *horizontal* land bridge?

What is the accessibility of a package's `Private` context variables?

Aging parents with no investments

Lightning Grid - Columns and Rows?

Why is the Constellation's nose gear so long?

Why do we hear so much about the Trump administration deciding to impose and then remove tariffs?

Can someone be penalized for an "unlawful" act if no penalty is specified?

How come people say “Would of”?

Did Scotland spend $250,000 for the slogan "Welcome to Scotland"?

Which Sci-Fi work first showed weapon of galactic-scale mass destruction?

"as much details as you can remember"

What is the motivation for a law requiring 2 parties to consent for recording a conversation

Is an up-to-date browser secure on an out-of-date OS?

Is three citations per paragraph excessive for undergraduate research paper?

Origin of "cooter" meaning "vagina"

How are circuits which use complex ICs normally simulated?

What is the most effective way of iterating a std::vector and why?

Am I thawing this London Broil safely?

How can I autofill dates in Excel excluding Sunday?

What tool would a Roman-age civilization have for the breaking of silver and other metals into dust?



Create a screencast with ffmpeg: how to keep video+audio in sync?



The 2019 Stack Overflow Developer Survey Results Are InNew FFMPEG; “[swscaler @ 0xa314080] Warning: data is not aligned! This can lead to a speedloss”ffmpeg conversion problemHow can I use ffmpeg to accurately export images from a video file?What does the video output stream details from ffmpeg mean?FFmpeg split video doesn't start at 0 secondsProblems with frame rate on video conversion using ffmpeg with libx264How does ffmpeg determine individual stream bitrates?Using ffmpeg to split mkv but get a few seconds video lost (cutting between keyframes without re-encoding?)How to use ffmpeg frei0r filter with mixer2 pluginsFFMPEG extract audio from video with an annoying sound at the endHow to convert (broken) MPEG1 video to format that can be viewed by most people





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I created some screencasts with ffmpeg. The PC I use has capable hardware (Intel Core i7-4930K Six Core 3.40GHz 12MB Cache, 32 GB RAM), but unfortunately it runs Windows 7. Because I want to do my screencast on Linux I installed Kubuntu in VMware. I assigned 4 CPU cores and 4 GB RAM to the VM.



I record my screencast with the following command:



ffmpeg -f alsa -ac 1 -i pulse -f x11grab -r 30 -s 1920x1080 -i :0.0 -acodec mp3 -vcodec libx264 -preset ultrafast -crf 0 -threads 0 output.mp4


However the video runs way faster than the audio. After a couple of minutes the audio (recorded by microphone) lags several seconds behind the video.
I tried to record the audio on the Windows Host with audacity in parallel and the audio from audacity and the audio captured by ffmpeg in the VM seem to be in sync. Just the video runs to fast.



What is the reason for this? Could it have to do VMware? Are there any settings that I can tweak? Are there ffmpeg options I could use for syncing? E.g. if I could force ffmpeg to drop or duplicate frames if audio/video is not in sync that would be totally OK for me, but as far as I understand the manual for ffmpeg's -vsync option, this is already the default.



I compiled ffmpeg myself following the Ubuntu Compilation Guide and I got the idea to use ffmpeg from here.



EDIT: ffmpeg output as requested:



$ /home/yankee/bin/ffmpeg -f alsa -ac 1 -i pulse -f x11grab -r 30 -s 1920x1080 -i :0.0 -acodec mp3 -vcodec libx264 -preset ultrafast -crf 0 -threads 0 05-visitor.mp4
ffmpeg version 2.1.git Copyright (c) 2000-2014 the FFmpeg developers
built on Feb 24 2014 08:38:08 with gcc 4.8 (Ubuntu/Linaro 4.8.1-10ubuntu9)
configuration: --prefix=/home/yankee/ffmpeg_build --extra-cflags=-I/home/yankee/ffmpeg_build/include --extra-ldflags=-L/home/yankee/ffmpeg_build/lib --bindir=/home/yankee/bin --extra-libs=-ldl --enable-gpl --enable-libass --enable-libfdk-aac --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-nonfree --enable-x11grab
libavutil 52. 65.100 / 52. 65.100
libavcodec 55. 52.102 / 55. 52.102
libavformat 55. 33.100 / 55. 33.100
libavdevice 55. 10.100 / 55. 10.100
libavfilter 4. 1.103 / 4. 1.103
libswscale 2. 5.101 / 2. 5.101
libswresample 0. 17.104 / 0. 17.104
libpostproc 52. 3.100 / 52. 3.100
Guessed Channel Layout for Input Stream #0.0 : mono
Input #0, alsa, from 'pulse':
Duration: N/A, start: 1394106509.365291, bitrate: 768 kb/s
Stream #0:0: Audio: pcm_s16le, 48000 Hz, mono, s16, 768 kb/s
[x11grab @ 0x2551e40] device: :0.0 -> display: :0.0 x: 0 y: 0 width: 1920 height: 1080
[x11grab @ 0x2551e40] shared memory extension found
Input #1, x11grab, from ':0.0':
Duration: N/A, start: 1394106509.415547, bitrate: 1990656 kb/s
Stream #1:0: Video: rawvideo (BGR[0] / 0x524742), bgr0, 1920x1080, 1990656 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 @ 0x256db60] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x256db60] profile High 4:4:4 Predictive, level 4.0, 4:4:4 8-bit
[libx264 @ 0x256db60] 64 - core 142 - H.264/MPEG-4 AVC codec - Copyleft 2003-2014 - 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, mp4, to '05-visitor.mp4':
Metadata:
encoder : Lavf55.33.100
Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv444p, 1920x1080, q=-1--1, 15360 tbn, 30 tbc
Stream #0:1: Audio: mp3 (libmp3lame) (i[0][0][0] / 0x0069), 48000 Hz, mono, s16p
Stream mapping:
Stream #1:0 -> #0:0 (rawvideo -> libx264)
Stream #0:0 -> #0:1 (pcm_s16le -> libmp3lame)
Press [q] to stop, [?] for help
frame=19011 fps= 30 q=-1.0 Lsize= 186418kB time=00:10:34.84 bitrate=2405.5kbits/s
video:180861kB audio:4960kB subtitle:0 data:0 global headers:0kB muxing overhead 0.321432%
[libx264 @ 0x256db60] frame I:77 Avg QP: 0.00 size:451985
[libx264 @ 0x256db60] frame P:18934 Avg QP: 0.00 size: 7943
[libx264 @ 0x256db60] mb I I16..4: 100.0% 0.0% 0.0%
[libx264 @ 0x256db60] mb P I16..4: 59.7% 0.0% 0.0% P16..4: 0.0% 0.0% 0.0% 0.0% 0.0% skip:40.3%
[libx264 @ 0x256db60] coded y,u,v intra: 0.2% 0.2% 0.2% inter: 0.0% 0.0% 0.0%
[libx264 @ 0x256db60] i16 v,h,dc,p: 100% 0% 0% 0%
[libx264 @ 0x256db60] kb/s:2338.03


I played around a little more and I noticed that if the output file already exists ffmpeg asks me if I would like to override the file. In this case the audio stream already contains things I said while the overwrite file question exists. The video however does not start before I confirmed file overwrite and thus the audio naturally lags behind the video quite a lot. But that is easy to deal with. Just don't overwrite existing files.



I don't really care about the format I end up with as long as the video has some lossless format and I can edit it with Adobe Premiere (it does not support mkv).



EDIT2: I got a little closer to the problem. When looking very closely at the resulting video stream, it is sometimes noticeable that a couple of frames are missing. May because I opened a window in just this moment which causes video compression to consume more CPU (because many pixels changed) or the like. Maybe there are some buffers I can assign to ffmpeg to speed up processing in such moments? After all my machine has 32GB RAM, it should be good for something... Or are there any other lossless codecs I could use or...? Next time i'll also try ro set a higher CPU priority for ffmpeg.










share|improve this question

























  • Please include the complete ffmpeg console output.

    – llogan
    Mar 6 '14 at 18:41











  • @LordNeckbeard: done

    – yankee
    Mar 7 '14 at 7:20











  • This question looks to be a similar issue and might be of interest: superuser.com/questions/728795/…. The answer there pointed to a size rounding problem.

    – neontapir
    May 25 '16 at 18:11


















0















I created some screencasts with ffmpeg. The PC I use has capable hardware (Intel Core i7-4930K Six Core 3.40GHz 12MB Cache, 32 GB RAM), but unfortunately it runs Windows 7. Because I want to do my screencast on Linux I installed Kubuntu in VMware. I assigned 4 CPU cores and 4 GB RAM to the VM.



I record my screencast with the following command:



ffmpeg -f alsa -ac 1 -i pulse -f x11grab -r 30 -s 1920x1080 -i :0.0 -acodec mp3 -vcodec libx264 -preset ultrafast -crf 0 -threads 0 output.mp4


However the video runs way faster than the audio. After a couple of minutes the audio (recorded by microphone) lags several seconds behind the video.
I tried to record the audio on the Windows Host with audacity in parallel and the audio from audacity and the audio captured by ffmpeg in the VM seem to be in sync. Just the video runs to fast.



What is the reason for this? Could it have to do VMware? Are there any settings that I can tweak? Are there ffmpeg options I could use for syncing? E.g. if I could force ffmpeg to drop or duplicate frames if audio/video is not in sync that would be totally OK for me, but as far as I understand the manual for ffmpeg's -vsync option, this is already the default.



I compiled ffmpeg myself following the Ubuntu Compilation Guide and I got the idea to use ffmpeg from here.



EDIT: ffmpeg output as requested:



$ /home/yankee/bin/ffmpeg -f alsa -ac 1 -i pulse -f x11grab -r 30 -s 1920x1080 -i :0.0 -acodec mp3 -vcodec libx264 -preset ultrafast -crf 0 -threads 0 05-visitor.mp4
ffmpeg version 2.1.git Copyright (c) 2000-2014 the FFmpeg developers
built on Feb 24 2014 08:38:08 with gcc 4.8 (Ubuntu/Linaro 4.8.1-10ubuntu9)
configuration: --prefix=/home/yankee/ffmpeg_build --extra-cflags=-I/home/yankee/ffmpeg_build/include --extra-ldflags=-L/home/yankee/ffmpeg_build/lib --bindir=/home/yankee/bin --extra-libs=-ldl --enable-gpl --enable-libass --enable-libfdk-aac --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-nonfree --enable-x11grab
libavutil 52. 65.100 / 52. 65.100
libavcodec 55. 52.102 / 55. 52.102
libavformat 55. 33.100 / 55. 33.100
libavdevice 55. 10.100 / 55. 10.100
libavfilter 4. 1.103 / 4. 1.103
libswscale 2. 5.101 / 2. 5.101
libswresample 0. 17.104 / 0. 17.104
libpostproc 52. 3.100 / 52. 3.100
Guessed Channel Layout for Input Stream #0.0 : mono
Input #0, alsa, from 'pulse':
Duration: N/A, start: 1394106509.365291, bitrate: 768 kb/s
Stream #0:0: Audio: pcm_s16le, 48000 Hz, mono, s16, 768 kb/s
[x11grab @ 0x2551e40] device: :0.0 -> display: :0.0 x: 0 y: 0 width: 1920 height: 1080
[x11grab @ 0x2551e40] shared memory extension found
Input #1, x11grab, from ':0.0':
Duration: N/A, start: 1394106509.415547, bitrate: 1990656 kb/s
Stream #1:0: Video: rawvideo (BGR[0] / 0x524742), bgr0, 1920x1080, 1990656 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 @ 0x256db60] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x256db60] profile High 4:4:4 Predictive, level 4.0, 4:4:4 8-bit
[libx264 @ 0x256db60] 64 - core 142 - H.264/MPEG-4 AVC codec - Copyleft 2003-2014 - 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, mp4, to '05-visitor.mp4':
Metadata:
encoder : Lavf55.33.100
Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv444p, 1920x1080, q=-1--1, 15360 tbn, 30 tbc
Stream #0:1: Audio: mp3 (libmp3lame) (i[0][0][0] / 0x0069), 48000 Hz, mono, s16p
Stream mapping:
Stream #1:0 -> #0:0 (rawvideo -> libx264)
Stream #0:0 -> #0:1 (pcm_s16le -> libmp3lame)
Press [q] to stop, [?] for help
frame=19011 fps= 30 q=-1.0 Lsize= 186418kB time=00:10:34.84 bitrate=2405.5kbits/s
video:180861kB audio:4960kB subtitle:0 data:0 global headers:0kB muxing overhead 0.321432%
[libx264 @ 0x256db60] frame I:77 Avg QP: 0.00 size:451985
[libx264 @ 0x256db60] frame P:18934 Avg QP: 0.00 size: 7943
[libx264 @ 0x256db60] mb I I16..4: 100.0% 0.0% 0.0%
[libx264 @ 0x256db60] mb P I16..4: 59.7% 0.0% 0.0% P16..4: 0.0% 0.0% 0.0% 0.0% 0.0% skip:40.3%
[libx264 @ 0x256db60] coded y,u,v intra: 0.2% 0.2% 0.2% inter: 0.0% 0.0% 0.0%
[libx264 @ 0x256db60] i16 v,h,dc,p: 100% 0% 0% 0%
[libx264 @ 0x256db60] kb/s:2338.03


I played around a little more and I noticed that if the output file already exists ffmpeg asks me if I would like to override the file. In this case the audio stream already contains things I said while the overwrite file question exists. The video however does not start before I confirmed file overwrite and thus the audio naturally lags behind the video quite a lot. But that is easy to deal with. Just don't overwrite existing files.



I don't really care about the format I end up with as long as the video has some lossless format and I can edit it with Adobe Premiere (it does not support mkv).



EDIT2: I got a little closer to the problem. When looking very closely at the resulting video stream, it is sometimes noticeable that a couple of frames are missing. May because I opened a window in just this moment which causes video compression to consume more CPU (because many pixels changed) or the like. Maybe there are some buffers I can assign to ffmpeg to speed up processing in such moments? After all my machine has 32GB RAM, it should be good for something... Or are there any other lossless codecs I could use or...? Next time i'll also try ro set a higher CPU priority for ffmpeg.










share|improve this question

























  • Please include the complete ffmpeg console output.

    – llogan
    Mar 6 '14 at 18:41











  • @LordNeckbeard: done

    – yankee
    Mar 7 '14 at 7:20











  • This question looks to be a similar issue and might be of interest: superuser.com/questions/728795/…. The answer there pointed to a size rounding problem.

    – neontapir
    May 25 '16 at 18:11














0












0








0








I created some screencasts with ffmpeg. The PC I use has capable hardware (Intel Core i7-4930K Six Core 3.40GHz 12MB Cache, 32 GB RAM), but unfortunately it runs Windows 7. Because I want to do my screencast on Linux I installed Kubuntu in VMware. I assigned 4 CPU cores and 4 GB RAM to the VM.



I record my screencast with the following command:



ffmpeg -f alsa -ac 1 -i pulse -f x11grab -r 30 -s 1920x1080 -i :0.0 -acodec mp3 -vcodec libx264 -preset ultrafast -crf 0 -threads 0 output.mp4


However the video runs way faster than the audio. After a couple of minutes the audio (recorded by microphone) lags several seconds behind the video.
I tried to record the audio on the Windows Host with audacity in parallel and the audio from audacity and the audio captured by ffmpeg in the VM seem to be in sync. Just the video runs to fast.



What is the reason for this? Could it have to do VMware? Are there any settings that I can tweak? Are there ffmpeg options I could use for syncing? E.g. if I could force ffmpeg to drop or duplicate frames if audio/video is not in sync that would be totally OK for me, but as far as I understand the manual for ffmpeg's -vsync option, this is already the default.



I compiled ffmpeg myself following the Ubuntu Compilation Guide and I got the idea to use ffmpeg from here.



EDIT: ffmpeg output as requested:



$ /home/yankee/bin/ffmpeg -f alsa -ac 1 -i pulse -f x11grab -r 30 -s 1920x1080 -i :0.0 -acodec mp3 -vcodec libx264 -preset ultrafast -crf 0 -threads 0 05-visitor.mp4
ffmpeg version 2.1.git Copyright (c) 2000-2014 the FFmpeg developers
built on Feb 24 2014 08:38:08 with gcc 4.8 (Ubuntu/Linaro 4.8.1-10ubuntu9)
configuration: --prefix=/home/yankee/ffmpeg_build --extra-cflags=-I/home/yankee/ffmpeg_build/include --extra-ldflags=-L/home/yankee/ffmpeg_build/lib --bindir=/home/yankee/bin --extra-libs=-ldl --enable-gpl --enable-libass --enable-libfdk-aac --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-nonfree --enable-x11grab
libavutil 52. 65.100 / 52. 65.100
libavcodec 55. 52.102 / 55. 52.102
libavformat 55. 33.100 / 55. 33.100
libavdevice 55. 10.100 / 55. 10.100
libavfilter 4. 1.103 / 4. 1.103
libswscale 2. 5.101 / 2. 5.101
libswresample 0. 17.104 / 0. 17.104
libpostproc 52. 3.100 / 52. 3.100
Guessed Channel Layout for Input Stream #0.0 : mono
Input #0, alsa, from 'pulse':
Duration: N/A, start: 1394106509.365291, bitrate: 768 kb/s
Stream #0:0: Audio: pcm_s16le, 48000 Hz, mono, s16, 768 kb/s
[x11grab @ 0x2551e40] device: :0.0 -> display: :0.0 x: 0 y: 0 width: 1920 height: 1080
[x11grab @ 0x2551e40] shared memory extension found
Input #1, x11grab, from ':0.0':
Duration: N/A, start: 1394106509.415547, bitrate: 1990656 kb/s
Stream #1:0: Video: rawvideo (BGR[0] / 0x524742), bgr0, 1920x1080, 1990656 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 @ 0x256db60] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x256db60] profile High 4:4:4 Predictive, level 4.0, 4:4:4 8-bit
[libx264 @ 0x256db60] 64 - core 142 - H.264/MPEG-4 AVC codec - Copyleft 2003-2014 - 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, mp4, to '05-visitor.mp4':
Metadata:
encoder : Lavf55.33.100
Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv444p, 1920x1080, q=-1--1, 15360 tbn, 30 tbc
Stream #0:1: Audio: mp3 (libmp3lame) (i[0][0][0] / 0x0069), 48000 Hz, mono, s16p
Stream mapping:
Stream #1:0 -> #0:0 (rawvideo -> libx264)
Stream #0:0 -> #0:1 (pcm_s16le -> libmp3lame)
Press [q] to stop, [?] for help
frame=19011 fps= 30 q=-1.0 Lsize= 186418kB time=00:10:34.84 bitrate=2405.5kbits/s
video:180861kB audio:4960kB subtitle:0 data:0 global headers:0kB muxing overhead 0.321432%
[libx264 @ 0x256db60] frame I:77 Avg QP: 0.00 size:451985
[libx264 @ 0x256db60] frame P:18934 Avg QP: 0.00 size: 7943
[libx264 @ 0x256db60] mb I I16..4: 100.0% 0.0% 0.0%
[libx264 @ 0x256db60] mb P I16..4: 59.7% 0.0% 0.0% P16..4: 0.0% 0.0% 0.0% 0.0% 0.0% skip:40.3%
[libx264 @ 0x256db60] coded y,u,v intra: 0.2% 0.2% 0.2% inter: 0.0% 0.0% 0.0%
[libx264 @ 0x256db60] i16 v,h,dc,p: 100% 0% 0% 0%
[libx264 @ 0x256db60] kb/s:2338.03


I played around a little more and I noticed that if the output file already exists ffmpeg asks me if I would like to override the file. In this case the audio stream already contains things I said while the overwrite file question exists. The video however does not start before I confirmed file overwrite and thus the audio naturally lags behind the video quite a lot. But that is easy to deal with. Just don't overwrite existing files.



I don't really care about the format I end up with as long as the video has some lossless format and I can edit it with Adobe Premiere (it does not support mkv).



EDIT2: I got a little closer to the problem. When looking very closely at the resulting video stream, it is sometimes noticeable that a couple of frames are missing. May because I opened a window in just this moment which causes video compression to consume more CPU (because many pixels changed) or the like. Maybe there are some buffers I can assign to ffmpeg to speed up processing in such moments? After all my machine has 32GB RAM, it should be good for something... Or are there any other lossless codecs I could use or...? Next time i'll also try ro set a higher CPU priority for ffmpeg.










share|improve this question
















I created some screencasts with ffmpeg. The PC I use has capable hardware (Intel Core i7-4930K Six Core 3.40GHz 12MB Cache, 32 GB RAM), but unfortunately it runs Windows 7. Because I want to do my screencast on Linux I installed Kubuntu in VMware. I assigned 4 CPU cores and 4 GB RAM to the VM.



I record my screencast with the following command:



ffmpeg -f alsa -ac 1 -i pulse -f x11grab -r 30 -s 1920x1080 -i :0.0 -acodec mp3 -vcodec libx264 -preset ultrafast -crf 0 -threads 0 output.mp4


However the video runs way faster than the audio. After a couple of minutes the audio (recorded by microphone) lags several seconds behind the video.
I tried to record the audio on the Windows Host with audacity in parallel and the audio from audacity and the audio captured by ffmpeg in the VM seem to be in sync. Just the video runs to fast.



What is the reason for this? Could it have to do VMware? Are there any settings that I can tweak? Are there ffmpeg options I could use for syncing? E.g. if I could force ffmpeg to drop or duplicate frames if audio/video is not in sync that would be totally OK for me, but as far as I understand the manual for ffmpeg's -vsync option, this is already the default.



I compiled ffmpeg myself following the Ubuntu Compilation Guide and I got the idea to use ffmpeg from here.



EDIT: ffmpeg output as requested:



$ /home/yankee/bin/ffmpeg -f alsa -ac 1 -i pulse -f x11grab -r 30 -s 1920x1080 -i :0.0 -acodec mp3 -vcodec libx264 -preset ultrafast -crf 0 -threads 0 05-visitor.mp4
ffmpeg version 2.1.git Copyright (c) 2000-2014 the FFmpeg developers
built on Feb 24 2014 08:38:08 with gcc 4.8 (Ubuntu/Linaro 4.8.1-10ubuntu9)
configuration: --prefix=/home/yankee/ffmpeg_build --extra-cflags=-I/home/yankee/ffmpeg_build/include --extra-ldflags=-L/home/yankee/ffmpeg_build/lib --bindir=/home/yankee/bin --extra-libs=-ldl --enable-gpl --enable-libass --enable-libfdk-aac --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-nonfree --enable-x11grab
libavutil 52. 65.100 / 52. 65.100
libavcodec 55. 52.102 / 55. 52.102
libavformat 55. 33.100 / 55. 33.100
libavdevice 55. 10.100 / 55. 10.100
libavfilter 4. 1.103 / 4. 1.103
libswscale 2. 5.101 / 2. 5.101
libswresample 0. 17.104 / 0. 17.104
libpostproc 52. 3.100 / 52. 3.100
Guessed Channel Layout for Input Stream #0.0 : mono
Input #0, alsa, from 'pulse':
Duration: N/A, start: 1394106509.365291, bitrate: 768 kb/s
Stream #0:0: Audio: pcm_s16le, 48000 Hz, mono, s16, 768 kb/s
[x11grab @ 0x2551e40] device: :0.0 -> display: :0.0 x: 0 y: 0 width: 1920 height: 1080
[x11grab @ 0x2551e40] shared memory extension found
Input #1, x11grab, from ':0.0':
Duration: N/A, start: 1394106509.415547, bitrate: 1990656 kb/s
Stream #1:0: Video: rawvideo (BGR[0] / 0x524742), bgr0, 1920x1080, 1990656 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 @ 0x256db60] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x256db60] profile High 4:4:4 Predictive, level 4.0, 4:4:4 8-bit
[libx264 @ 0x256db60] 64 - core 142 - H.264/MPEG-4 AVC codec - Copyleft 2003-2014 - 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, mp4, to '05-visitor.mp4':
Metadata:
encoder : Lavf55.33.100
Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv444p, 1920x1080, q=-1--1, 15360 tbn, 30 tbc
Stream #0:1: Audio: mp3 (libmp3lame) (i[0][0][0] / 0x0069), 48000 Hz, mono, s16p
Stream mapping:
Stream #1:0 -> #0:0 (rawvideo -> libx264)
Stream #0:0 -> #0:1 (pcm_s16le -> libmp3lame)
Press [q] to stop, [?] for help
frame=19011 fps= 30 q=-1.0 Lsize= 186418kB time=00:10:34.84 bitrate=2405.5kbits/s
video:180861kB audio:4960kB subtitle:0 data:0 global headers:0kB muxing overhead 0.321432%
[libx264 @ 0x256db60] frame I:77 Avg QP: 0.00 size:451985
[libx264 @ 0x256db60] frame P:18934 Avg QP: 0.00 size: 7943
[libx264 @ 0x256db60] mb I I16..4: 100.0% 0.0% 0.0%
[libx264 @ 0x256db60] mb P I16..4: 59.7% 0.0% 0.0% P16..4: 0.0% 0.0% 0.0% 0.0% 0.0% skip:40.3%
[libx264 @ 0x256db60] coded y,u,v intra: 0.2% 0.2% 0.2% inter: 0.0% 0.0% 0.0%
[libx264 @ 0x256db60] i16 v,h,dc,p: 100% 0% 0% 0%
[libx264 @ 0x256db60] kb/s:2338.03


I played around a little more and I noticed that if the output file already exists ffmpeg asks me if I would like to override the file. In this case the audio stream already contains things I said while the overwrite file question exists. The video however does not start before I confirmed file overwrite and thus the audio naturally lags behind the video quite a lot. But that is easy to deal with. Just don't overwrite existing files.



I don't really care about the format I end up with as long as the video has some lossless format and I can edit it with Adobe Premiere (it does not support mkv).



EDIT2: I got a little closer to the problem. When looking very closely at the resulting video stream, it is sometimes noticeable that a couple of frames are missing. May because I opened a window in just this moment which causes video compression to consume more CPU (because many pixels changed) or the like. Maybe there are some buffers I can assign to ffmpeg to speed up processing in such moments? After all my machine has 32GB RAM, it should be good for something... Or are there any other lossless codecs I could use or...? Next time i'll also try ro set a higher CPU priority for ffmpeg.







ubuntu vmware ffmpeg screen-capture






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 7 '14 at 9:36







yankee

















asked Mar 6 '14 at 16:45









yankeeyankee

500515




500515













  • Please include the complete ffmpeg console output.

    – llogan
    Mar 6 '14 at 18:41











  • @LordNeckbeard: done

    – yankee
    Mar 7 '14 at 7:20











  • This question looks to be a similar issue and might be of interest: superuser.com/questions/728795/…. The answer there pointed to a size rounding problem.

    – neontapir
    May 25 '16 at 18:11



















  • Please include the complete ffmpeg console output.

    – llogan
    Mar 6 '14 at 18:41











  • @LordNeckbeard: done

    – yankee
    Mar 7 '14 at 7:20











  • This question looks to be a similar issue and might be of interest: superuser.com/questions/728795/…. The answer there pointed to a size rounding problem.

    – neontapir
    May 25 '16 at 18:11

















Please include the complete ffmpeg console output.

– llogan
Mar 6 '14 at 18:41





Please include the complete ffmpeg console output.

– llogan
Mar 6 '14 at 18:41













@LordNeckbeard: done

– yankee
Mar 7 '14 at 7:20





@LordNeckbeard: done

– yankee
Mar 7 '14 at 7:20













This question looks to be a similar issue and might be of interest: superuser.com/questions/728795/…. The answer there pointed to a size rounding problem.

– neontapir
May 25 '16 at 18:11





This question looks to be a similar issue and might be of interest: superuser.com/questions/728795/…. The answer there pointed to a size rounding problem.

– neontapir
May 25 '16 at 18:11










2 Answers
2






active

oldest

votes


















0














I get a "[swscaler @ 0xa314080] Warning: data is not aligned! This can lead to a speedloss"
that seems to be the issue. However, I don't have a resolution yet.






share|improve this answer



















  • 1





    Welcome to Superuser! Your "answer" is more of a "me too!" and although it may be helpful, it should be a comment.

    – G Koe
    Mar 13 '14 at 21:25











  • I'm still looking for a resolution, his code did not include the "swscaler" warning. This is not a, "me too" this is trying establish if his issue the same as mine, or is mine something different.

    – Syborgia Alphas
    Mar 13 '14 at 22:43











  • my ffmpeg build; ffmpeg version 2.2.git Copyright (c) 2000-2014 the FFmpeg developers built on Mar 13 2014 16:08:45 with gcc 4.8 (Ubuntu/Linaro 4.8.1-10ubuntu9)

    – Syborgia Alphas
    Mar 13 '14 at 22:45











  • Great, my apologies. Post yours as a new question, and reference this questions!

    – G Koe
    Mar 13 '14 at 22:45






  • 1





    Ensure your desired output resolution is exactly divisible by 16.

    – Cees Timmerman
    Aug 21 '14 at 7:34



















0














This works for me in 2019. I tried with different encoders but when using ones that aren't native to ffmpeg, the audio and video get out of sync. Specifically the video lags behind. mpeg4 and aac are native.



ffmpeg -f alsa -ac 1 -i pulse -f x11grab -r 30 -s 1920x1080  -i :0.0 -acodec aac -vcodec mpeg4 -preset medium -qscale:v 5 rec.mkv





share|improve this answer
























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "3"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f725581%2fcreate-a-screencast-with-ffmpeg-how-to-keep-videoaudio-in-sync%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I get a "[swscaler @ 0xa314080] Warning: data is not aligned! This can lead to a speedloss"
    that seems to be the issue. However, I don't have a resolution yet.






    share|improve this answer



















    • 1





      Welcome to Superuser! Your "answer" is more of a "me too!" and although it may be helpful, it should be a comment.

      – G Koe
      Mar 13 '14 at 21:25











    • I'm still looking for a resolution, his code did not include the "swscaler" warning. This is not a, "me too" this is trying establish if his issue the same as mine, or is mine something different.

      – Syborgia Alphas
      Mar 13 '14 at 22:43











    • my ffmpeg build; ffmpeg version 2.2.git Copyright (c) 2000-2014 the FFmpeg developers built on Mar 13 2014 16:08:45 with gcc 4.8 (Ubuntu/Linaro 4.8.1-10ubuntu9)

      – Syborgia Alphas
      Mar 13 '14 at 22:45











    • Great, my apologies. Post yours as a new question, and reference this questions!

      – G Koe
      Mar 13 '14 at 22:45






    • 1





      Ensure your desired output resolution is exactly divisible by 16.

      – Cees Timmerman
      Aug 21 '14 at 7:34
















    0














    I get a "[swscaler @ 0xa314080] Warning: data is not aligned! This can lead to a speedloss"
    that seems to be the issue. However, I don't have a resolution yet.






    share|improve this answer



















    • 1





      Welcome to Superuser! Your "answer" is more of a "me too!" and although it may be helpful, it should be a comment.

      – G Koe
      Mar 13 '14 at 21:25











    • I'm still looking for a resolution, his code did not include the "swscaler" warning. This is not a, "me too" this is trying establish if his issue the same as mine, or is mine something different.

      – Syborgia Alphas
      Mar 13 '14 at 22:43











    • my ffmpeg build; ffmpeg version 2.2.git Copyright (c) 2000-2014 the FFmpeg developers built on Mar 13 2014 16:08:45 with gcc 4.8 (Ubuntu/Linaro 4.8.1-10ubuntu9)

      – Syborgia Alphas
      Mar 13 '14 at 22:45











    • Great, my apologies. Post yours as a new question, and reference this questions!

      – G Koe
      Mar 13 '14 at 22:45






    • 1





      Ensure your desired output resolution is exactly divisible by 16.

      – Cees Timmerman
      Aug 21 '14 at 7:34














    0












    0








    0







    I get a "[swscaler @ 0xa314080] Warning: data is not aligned! This can lead to a speedloss"
    that seems to be the issue. However, I don't have a resolution yet.






    share|improve this answer













    I get a "[swscaler @ 0xa314080] Warning: data is not aligned! This can lead to a speedloss"
    that seems to be the issue. However, I don't have a resolution yet.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Mar 13 '14 at 20:49









    Syborgia AlphasSyborgia Alphas

    36114




    36114








    • 1





      Welcome to Superuser! Your "answer" is more of a "me too!" and although it may be helpful, it should be a comment.

      – G Koe
      Mar 13 '14 at 21:25











    • I'm still looking for a resolution, his code did not include the "swscaler" warning. This is not a, "me too" this is trying establish if his issue the same as mine, or is mine something different.

      – Syborgia Alphas
      Mar 13 '14 at 22:43











    • my ffmpeg build; ffmpeg version 2.2.git Copyright (c) 2000-2014 the FFmpeg developers built on Mar 13 2014 16:08:45 with gcc 4.8 (Ubuntu/Linaro 4.8.1-10ubuntu9)

      – Syborgia Alphas
      Mar 13 '14 at 22:45











    • Great, my apologies. Post yours as a new question, and reference this questions!

      – G Koe
      Mar 13 '14 at 22:45






    • 1





      Ensure your desired output resolution is exactly divisible by 16.

      – Cees Timmerman
      Aug 21 '14 at 7:34














    • 1





      Welcome to Superuser! Your "answer" is more of a "me too!" and although it may be helpful, it should be a comment.

      – G Koe
      Mar 13 '14 at 21:25











    • I'm still looking for a resolution, his code did not include the "swscaler" warning. This is not a, "me too" this is trying establish if his issue the same as mine, or is mine something different.

      – Syborgia Alphas
      Mar 13 '14 at 22:43











    • my ffmpeg build; ffmpeg version 2.2.git Copyright (c) 2000-2014 the FFmpeg developers built on Mar 13 2014 16:08:45 with gcc 4.8 (Ubuntu/Linaro 4.8.1-10ubuntu9)

      – Syborgia Alphas
      Mar 13 '14 at 22:45











    • Great, my apologies. Post yours as a new question, and reference this questions!

      – G Koe
      Mar 13 '14 at 22:45






    • 1





      Ensure your desired output resolution is exactly divisible by 16.

      – Cees Timmerman
      Aug 21 '14 at 7:34








    1




    1





    Welcome to Superuser! Your "answer" is more of a "me too!" and although it may be helpful, it should be a comment.

    – G Koe
    Mar 13 '14 at 21:25





    Welcome to Superuser! Your "answer" is more of a "me too!" and although it may be helpful, it should be a comment.

    – G Koe
    Mar 13 '14 at 21:25













    I'm still looking for a resolution, his code did not include the "swscaler" warning. This is not a, "me too" this is trying establish if his issue the same as mine, or is mine something different.

    – Syborgia Alphas
    Mar 13 '14 at 22:43





    I'm still looking for a resolution, his code did not include the "swscaler" warning. This is not a, "me too" this is trying establish if his issue the same as mine, or is mine something different.

    – Syborgia Alphas
    Mar 13 '14 at 22:43













    my ffmpeg build; ffmpeg version 2.2.git Copyright (c) 2000-2014 the FFmpeg developers built on Mar 13 2014 16:08:45 with gcc 4.8 (Ubuntu/Linaro 4.8.1-10ubuntu9)

    – Syborgia Alphas
    Mar 13 '14 at 22:45





    my ffmpeg build; ffmpeg version 2.2.git Copyright (c) 2000-2014 the FFmpeg developers built on Mar 13 2014 16:08:45 with gcc 4.8 (Ubuntu/Linaro 4.8.1-10ubuntu9)

    – Syborgia Alphas
    Mar 13 '14 at 22:45













    Great, my apologies. Post yours as a new question, and reference this questions!

    – G Koe
    Mar 13 '14 at 22:45





    Great, my apologies. Post yours as a new question, and reference this questions!

    – G Koe
    Mar 13 '14 at 22:45




    1




    1





    Ensure your desired output resolution is exactly divisible by 16.

    – Cees Timmerman
    Aug 21 '14 at 7:34





    Ensure your desired output resolution is exactly divisible by 16.

    – Cees Timmerman
    Aug 21 '14 at 7:34













    0














    This works for me in 2019. I tried with different encoders but when using ones that aren't native to ffmpeg, the audio and video get out of sync. Specifically the video lags behind. mpeg4 and aac are native.



    ffmpeg -f alsa -ac 1 -i pulse -f x11grab -r 30 -s 1920x1080  -i :0.0 -acodec aac -vcodec mpeg4 -preset medium -qscale:v 5 rec.mkv





    share|improve this answer




























      0














      This works for me in 2019. I tried with different encoders but when using ones that aren't native to ffmpeg, the audio and video get out of sync. Specifically the video lags behind. mpeg4 and aac are native.



      ffmpeg -f alsa -ac 1 -i pulse -f x11grab -r 30 -s 1920x1080  -i :0.0 -acodec aac -vcodec mpeg4 -preset medium -qscale:v 5 rec.mkv





      share|improve this answer


























        0












        0








        0







        This works for me in 2019. I tried with different encoders but when using ones that aren't native to ffmpeg, the audio and video get out of sync. Specifically the video lags behind. mpeg4 and aac are native.



        ffmpeg -f alsa -ac 1 -i pulse -f x11grab -r 30 -s 1920x1080  -i :0.0 -acodec aac -vcodec mpeg4 -preset medium -qscale:v 5 rec.mkv





        share|improve this answer













        This works for me in 2019. I tried with different encoders but when using ones that aren't native to ffmpeg, the audio and video get out of sync. Specifically the video lags behind. mpeg4 and aac are native.



        ffmpeg -f alsa -ac 1 -i pulse -f x11grab -r 30 -s 1920x1080  -i :0.0 -acodec aac -vcodec mpeg4 -preset medium -qscale:v 5 rec.mkv






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered yesterday









        miyalysmiyalys

        1,60011524




        1,60011524






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Super User!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f725581%2fcreate-a-screencast-with-ffmpeg-how-to-keep-videoaudio-in-sync%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Why not use the yoke to control yaw, as well as pitch and roll? Announcing the arrival of...

            Couldn't open a raw socket. Error: Permission denied (13) (nmap)Is it possible to run networking commands...

            VNC viewer RFB protocol error: bad desktop size 0x0I Cannot Type the Key 'd' (lowercase) in VNC Viewer...