Ffmpeg makes choppy videos when recording audio
Ffmpeg makes choppy videos when recording audio
Well, my issue is simple to explain, but I tried everything to solve it without success.
I like recording gameplays, just for fun. The game I currently make recordings for is not resource heavy (it's Doom 2 through GZDoom). I'm using Lubuntu 22.04.
So, here is the command I've just used:
ffmpeg -f x11grab -draw_mouse 0 -framerate 30 -probesize 42M -video_size 1920x1080 -i :0 -f pulse -i default -c:v libvpx-vp9 -r 30 -g 90 -quality realtime -frame-parallel 1 -qmin 4 -qmax 48 -b:v 4500k -c:a libvorbis prueba.mkv
The issue is, if I record without including the audio, then the video plays smoothly after being recorded. But if I record including the audio, no matter what parameters, codecs, bitrate or anything I use, then the video is barely watchable, with lots of choppiness, and even with delay between audio and video, apparently.
SimpleScreenRecorder works fine, but sometimes there are few frames dropped and I don't like it much. OBS is very heavy for my hardware (Mac Mini 2016, Intel Core i5 1.4 GHz 4260U, Intel HD Graphics 4000, 4 GB RAM).
I also tried VAAPI, with same results as above.
And the thing is that I remember recording some years ago, with no issues at all.
I don't know what to do. Any tip or solution?
Does top/htop/whatever show a large difference between encoding with and without audio? Do e.g. the pulse processes hog resources for some reason?
Do you get smooth recording if you reduce the screen resolution and do something that uses minimal resources (e.g., play Tetris at 640x480)?
Depending exclusively on the codecs I use, htop shows a CPU usage of 90-100% or 10-20%. So, I use those that don't require a huge CPU usage. Memory and Swap are not affected, as far as I know. But despite those circumstances, the outcome is the same. Recording with no sound = smoothness, 60 fps, recording with sound = choppiness, 10 fp5s.
Something I also noticed is that it also happens before I open Doom 2, so it doesn't matter whether I'm playing or not. Even with just the terminal and the file manager open.
Crazy idea, but what happens if you record audio and video with different ffmpeg processes? Just for debugging this might be useful to try. Perhaps there's something funny about the timestamps you're receiving from Pulse that causes weird behavior (or something along those lines).
Also, you mentioned this works better with other software --- any idea if those settings are drastically different than your ffmpeg settings?
I have no idea what I'm talking about though, just throwing out ideas :)