EasySR screen recorder audio cutoff fixed
I posted about EasySR recently, and have been using it to create the YouTube videos, as EasyCast is unsatisfactory. I created EasySR about a week ago, a GUI frontend for the 'ffmpeg' commandline utility, and have been gradually improving it.
One problem is that audio cuts out before the video stops recording. I hunted online for solutions, none of them perfect, but did find a recommendation that reduces the audio cutoff to 800ms before the video stops. Still not good enough.
Just now did another search, framing the question to Google AI a bit differently; this time got an answer that fixes the problem:
Audio truncation when recording desktop using x11grab and pulse happens because the audio stream finishes exactly at the time it took for the video encoder (e.g., libx264) to initialize. Add the -apad audio filter to your output command to indefinitely pad the audio stream so it matches the video length.
A proper command structure using the pad filter looks like this:
ffmpeg -video_size 1920x1080 -framerate 30 -f x11grab -i :0.0 -f pulse -i default -af apad -c:v libx264 -preset ultrafast -c:a aac output.mp4
Key Flags to Prevent Cutoffs and Sync Issues:
-af apad: This FFmpeg filter prevents audio from falling
short of the video stream by continually padding the audio with
silence until the video stream ends.
-preset ultrafast: Lowers CPU usage during recording. Using
high-load encoders without this flag is often the root cause of
initialization delays that truncate the audio.
-async 1: If your audio and video slowly drift out of sync
over a long recording, adding this legacy flag can help force
them together (though it is largely deprecated, it is still used
by many for desktop capture)
This is what I have put into EasySR, script /usr/local/easysr/easysr:
ffmpeg -framerate ${FPS} -f x11grab -i :0.0 -f pulse -i default -af apad -c:v libx264 -preset ultrafast -c:a aac -vf "scale=-2:${HEIGHT}" /files/media/video/EasySR/${FNAME}.mp4
...works great! The ordering of the components on the command
line is tricky, had to get it just right. I haven't put in that
"-async 1"
Tags: easy