noxz-sites

A collection of a builder and various scripts creating the noxz.tech sites
git clone https://noxz.tech/git/noxz-sites.git
Log | Files | README | LICENSE

noxz.tech/articles/record_screen_and_audio_using_ffmpeg/index.www
1Recording your screen with audio, including loopback audio, can be a valuable
2skill for creating tutorials, capturing gameplay, or archiving video
3conferences. This guide will show you how to use FFmpeg to record your screen
4along with loopback audio with ALSA as backend.
5
6.HnS 1
7Steps
8.HnE
9
10.DLS
11.LI "Load `snd-aloop` Module:"
12To enable loopback audio recording, you need to load the
13.ICD snd-aloop
14module with a single PCM substream. Use the following command (use
15.ICD sudo
16if you don't have
17.ICD doas
18installed):
19
20.CDS
21.COS
22doas modprobe snd-aloop pcm_substreams=1
23.COE
24.CDE
25
26.LI "Edit the ALSA Configuration File:"
27To direct audio output to the loopback device and record it, edit your ALSA
28configuration file. This step involves creating or appending to
29.ICD /etc/asound.conf .
30This will temporarily disable audio output. Execute the following command:
31
32.CDS
33.COS
34echo 'pcm.!default { type plug slave.pcm "hw:Loopback,0,0" }' >> /etc/asound.conf
35.COE
36.CDE
37
38If you wish to record audio from an application while also routing the audio to
39an output device, you can find alternative configurations on the
40.URL "https://trac.ffmpeg.org/wiki/Capture/ALSA" "FFmpeg Wiki" .
41
42.LI "Start Recordning:"
43Now, you can start the actual screen recording. In this example, we'll record a
441280x1080 portion of the screen starting from coordinates 0,0 using the ALSA
45audio hardware 'Loopback,1,0'. You can adjust the resolution and other
46parameters as needed.
47
48.CDS
49.COS
50ffmpeg -video_size 1280x1080 -framerate 25 -f x11grab -i :0.0+0,0 -f alsa -ac 2 -ar 44100 -i hw:Loopback,1,0 output.mkv
51.COE
52.CDE
53
54.ULE
55.LI
56.ICD "-video_size" :
57Sets the video size to 1280x1080 pixels.
58
59.LI
60.ICD "-framerate" :
61Specifies the frame rate (25 frames per second in this example).
62
63.LI
64.ICD "-f x11grab" :
65Uses the x11grab input format for screen capture.
66
67.LI
68.ICD "-i :0.0+0,0" :
69Specifies the screen area to capture (0,0 starting from the top-left corner).
70
71.LI
72.ICD "-f alsa" :
73Sets the audio input format to ALSA.
74
75.LI
76.ICD "-ac 2" :
77Configures 2 audio channels.
78
79.LI
80.ICD "-ar 44100" :
81Sets the audio sample rate to 44.1 kHz.
82
83.LI
84.ICD "-i hw:Loopback,1,0" :
85Specifies the loopback audio input.
86
87.LI
88.ICD "output.mkv" :
89Defines the output file name (you can use any desired format).
90.ULS
91
92.LI "Stop Recording:"
93To stop the recording, simply press
94.ICD Ctrl+C
95in the terminal where you started FFmpeg.
96
97.LI "Re-enable Audio Output:"
98Once you've finished your recording, remove or comment out the line added to
99.ICD "/etc/asound.conf"
100in step 2. This will re-enable audio output on your system.
101.DLE
102
103Now you can record your screen with loopback audio using FFmpeg. This can be
104especially useful for various content creation and screen capture needs.