Screen Recording without audio
$ ffmpeg7 -f x11grab -r 30 -s 1920x1080 -i :0.0 -vcodec libx264 -preset ultrafast -threads 0 -y output.mkv
Recording with audio from default audio output while hearing the audio output
To record from default audio output while listening to it requires a bit of preparation and trickery.
First we need to create a named piped, also called a fifo
$ mkfifo dsp
Let's create a wav file with 3 minutes of silence
$ ffmpeg7 -f lavfi -i anullsrc=r=44100:cl=stereo -t 180 silence.wav
Now we need to read from pad0 and pipe it to the fifo and play it back
$ cat /dev/pad0 | tee dsp | audioplay -f -c 2 -s 44100 -e slinear_le -P 16 -
When reading from pad0, pad will create a new audio device. Usually your last audio device + 1.
You can verify this with
$ audiocfg list
In my case it has created /dev/audio2
Now the order is important
On a second terminal, first start the screen recording
$ ffmpeg7 -f s16le -ar 44100 -ac 2 -i dsp -thread_queue_size 128 -f x11grab -r 30 -s 1920x1080 -i :0.0 -vcodec libx264 -preset ultrafast -threads 0 -y output.mkv
ffmpeg will wait for the audio source to come in and will not start immediately recording
On another terminal, now play silence into the new audio2 device used by pad
$ audioplay -d /dev/audio2 silence.wav
The reason we use silence and not music is that the audio will get garbled up in the beginning
Once ffmpeg starts recording we switch the default audio source as root on a new terminal
# audiocfg default 2
This will make all new apps use audio2, while the pipe is still using default audio
You can now do your recording but be aware that audio output will be slightly delayed while all the audio redirecting is happening
When done, stop recording (CTRL-C ffmpeg)
and switch back to your default audio output device
# audiocfg default 1
Post processing
Sync video with audio by removing the delay from the video (in my case .7 seconds)
ffmpeg7 -i output.mkv -itsoffset 0.70 -i output.mkv -c:a copy -c:v copy -map 0:a:0 -map 1:v:0 synced.mkv
Congratulations. Done !