I have an ffmpeg script to do my screencasts. I have Debian 9 at the office and Xubuntu 18.04 at home. On those two operating systems, the following works to record system audio and from my microphone.
pacmd set-default-source alsa_output.pci-0000_00_14.2.analog-stereo.monitor
ffmpeg \
-thread_queue_size 4096 -f alsa -ac 1 -ar 48000 -i default \
-thread_queue_size 4096 -f alsa -ac 1 -ar 48000 -i plughw:CARD=Device,DEV=0 \
-filter_complex amix=inputs=2 \
-thread_queue_size 4096 -f x11grab -r 30 -s 1920x1080 -i $DISPLAY+1920,0 \
-c:v libx264 -crf 20 -preset veryfast \
-c:a aac -ac 2 -b:a 192k \
-pix_fmt yuv420p -movflags faststart \
~/Desktop/out.mp4
This uses the pulse 'Monitor of Built-in Audio' to capture desktop audio. Unfortunately, on Debian 10, Xubuntu 19.04 & 19.10, and on Fedora 30, when I want to end my screen recording and press q
it does not stop properly. It hangs. Then I have to use ctrl+c multiple times to get back to the prompt. It kills my script and does not run the needed following commands. I will report this bug as soon as I get a chance. I am not sure if it is an ALSA or Pulse bug. I do not think it is an ffmpeg bug because I had the same ffmpeg version on both Debian 9 and Debian 10, and it only occured on Debian 10 and not Debian 9.
I have a Lenovo ThinkCentre. There is a front and back audio out and microphone 3.5mm jack. I used a 3.5mm cable to route audio out back in to the microphone jack. It worked, but the audio was poor quality. To do this I used -f alsa -i plughw:CARD=Generic,DEV=0
in my ffmpeg command. By using the ALSA device name, it did not hang on Xubuntu 19.10, etc.
I have therefore been trying to get the ALSA Loopback device to work to record the system audio. I have not been able to get it to record at all. I am loading the snd-aloop
kernel module at boot. I have tried various configuration options in my ~/.asoundrc
including at the bottom of the page here and also here. Here is the output of arecord -L
on my system.
default
Playback/recording through the PulseAudio sound server
null
Discard all samples (playback) or generate zero samples (capture)
pulse
PulseAudio Sound Server
sysdefault:CARD=Loopback
Loopback, Loopback PCM
Default Audio Device
front:CARD=Loopback,DEV=0
Loopback, Loopback PCM
Front speakers
surround21:CARD=Loopback,DEV=0
Loopback, Loopback PCM
2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=Loopback,DEV=0
Loopback, Loopback PCM
4.0 Surround output to Front and Rear speakers
surround41:CARD=Loopback,DEV=0
Loopback, Loopback PCM
4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=Loopback,DEV=0
Loopback, Loopback PCM
5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=Loopback,DEV=0
Loopback, Loopback PCM
5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=Loopback,DEV=0
Loopback, Loopback PCM
7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
dmix:CARD=Loopback,DEV=0
Loopback, Loopback PCM
Direct sample mixing device
dmix:CARD=Loopback,DEV=1
Loopback, Loopback PCM
Direct sample mixing device
dsnoop:CARD=Loopback,DEV=0
Loopback, Loopback PCM
Direct sample snooping device
dsnoop:CARD=Loopback,DEV=1
Loopback, Loopback PCM
Direct sample snooping device
hw:CARD=Loopback,DEV=0
Loopback, Loopback PCM
Direct hardware device without any conversions
hw:CARD=Loopback,DEV=1
Loopback, Loopback PCM
Direct hardware device without any conversions
plughw:CARD=Loopback,DEV=0
Loopback, Loopback PCM
Hardware device with all software conversions
plughw:CARD=Loopback,DEV=1
Loopback, Loopback PCM
Hardware device with all software conversions
sysdefault:CARD=Generic
HD-Audio Generic, ALC662 rev3 Analog
Default Audio Device
front:CARD=Generic,DEV=0
HD-Audio Generic, ALC662 rev3 Analog
Front speakers
dmix:CARD=Generic,DEV=0
HD-Audio Generic, ALC662 rev3 Analog
Direct sample mixing device
dmix:CARD=Generic,DEV=2
HD-Audio Generic, ALC662 rev3 Alt Analog
Direct sample mixing device
dsnoop:CARD=Generic,DEV=0
HD-Audio Generic, ALC662 rev3 Analog
Direct sample snooping device
dsnoop:CARD=Generic,DEV=2
HD-Audio Generic, ALC662 rev3 Alt Analog
Direct sample snooping device
hw:CARD=Generic,DEV=0
HD-Audio Generic, ALC662 rev3 Analog
Direct hardware device without any conversions
hw:CARD=Generic,DEV=2
HD-Audio Generic, ALC662 rev3 Alt Analog
Direct hardware device without any conversions
plughw:CARD=Generic,DEV=0
HD-Audio Generic, ALC662 rev3 Analog
Hardware device with all software conversions
plughw:CARD=Generic,DEV=2
HD-Audio Generic, ALC662 rev3 Alt Analog
Hardware device with all software conversions
sysdefault:CARD=Device
USB PnP Audio Device, USB Audio
Default Audio Device
front:CARD=Device,DEV=0
USB PnP Audio Device, USB Audio
Front speakers
surround21:CARD=Device,DEV=0
USB PnP Audio Device, USB Audio
2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=Device,DEV=0
USB PnP Audio Device, USB Audio
4.0 Surround output to Front and Rear speakers
surround41:CARD=Device,DEV=0
USB PnP Audio Device, USB Audio
4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=Device,DEV=0
USB PnP Audio Device, USB Audio
5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=Device,DEV=0
USB PnP Audio Device, USB Audio
5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=Device,DEV=0
USB PnP Audio Device, USB Audio
7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
iec958:CARD=Device,DEV=0
USB PnP Audio Device, USB Audio
IEC958 (S/PDIF) Digital Audio Output
dmix:CARD=Device,DEV=0
USB PnP Audio Device, USB Audio
Direct sample mixing device
dsnoop:CARD=Device,DEV=0
USB PnP Audio Device, USB Audio
Direct sample snooping device
hw:CARD=Device,DEV=0
USB PnP Audio Device, USB Audio
Direct hardware device without any conversions
plughw:CARD=Device,DEV=0
USB PnP Audio Device, USB Audio
Hardware device with all software conversions
sysdefault:CARD=U0x46d0x825
USB Device 0x46d:0x825, USB Audio
Default Audio Device
front:CARD=U0x46d0x825,DEV=0
USB Device 0x46d:0x825, USB Audio
Front speakers
surround21:CARD=U0x46d0x825,DEV=0
USB Device 0x46d:0x825, USB Audio
2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=U0x46d0x825,DEV=0
USB Device 0x46d:0x825, USB Audio
4.0 Surround output to Front and Rear speakers
surround41:CARD=U0x46d0x825,DEV=0
USB Device 0x46d:0x825, USB Audio
4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=U0x46d0x825,DEV=0
USB Device 0x46d:0x825, USB Audio
5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=U0x46d0x825,DEV=0
USB Device 0x46d:0x825, USB Audio
5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=U0x46d0x825,DEV=0
USB Device 0x46d:0x825, USB Audio
7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
iec958:CARD=U0x46d0x825,DEV=0
USB Device 0x46d:0x825, USB Audio
IEC958 (S/PDIF) Digital Audio Output
dmix:CARD=U0x46d0x825,DEV=0
USB Device 0x46d:0x825, USB Audio
Direct sample mixing device
dsnoop:CARD=U0x46d0x825,DEV=0
USB Device 0x46d:0x825, USB Audio
Direct sample snooping device
hw:CARD=U0x46d0x825,DEV=0
USB Device 0x46d:0x825, USB Audio
Direct hardware device without any conversions
plughw:CARD=U0x46d0x825,DEV=0
USB Device 0x46d:0x825, USB Audio
Hardware device with all software conversions
I did the following test run with the loopback devices listed. None of the following recorded the audio I was playing.
ffmpeg -f alsa -i loopin -t 10 1.wav
ffmpeg -f alsa -i loopout -t 10 2.wav
ffmpeg -f alsa -i sysdefault:CARD=Loopback -t 10 3.wav
ffmpeg -f alsa -i front:CARD=Loopback,DEV=0 -t 10 4.wav
ffmpeg -f alsa -i surround21:CARD=Loopback,DEV=0 -t 10 5.wav
ffmpeg -f alsa -i surround40:CARD=Loopback,DEV=0 -t 10 6.wav
ffmpeg -f alsa -i surround41:CARD=Loopback,DEV=0 -t 10 7.wav
ffmpeg -f alsa -i surround50:CARD=Loopback,DEV=0 -t 10 8.wav
ffmpeg -f alsa -i surround51:CARD=Loopback,DEV=0 -t 10 9.wav
ffmpeg -f alsa -i surround71:CARD=Loopback,DEV=0 -t 10 10.wav
ffmpeg -f alsa -i dmix:CARD=Loopback,DEV=0 -t 10 11.wav
ffmpeg -f alsa -i dmix:CARD=Loopback,DEV=1 -t 10 12.wav
ffmpeg -f alsa -i dsnoop:CARD=Loopback,DEV=0 -t 10 13.wav
ffmpeg -f alsa -i dsnoop:CARD=Loopback,DEV=1 -t 10 14.wav
ffmpeg -f alsa -i hw:CARD=Loopback,DEV=0 -t 10 15.wav
ffmpeg -f alsa -i hw:CARD=Loopback,DEV=1 -t 10 16.wav
ffmpeg -f alsa -i plughw:CARD=Loopback,DEV=0 -t 10 17.wav
ffmpeg -f alsa -i plughw:CARD=Loopback,DEV=1 -t 10 18.wav
I noticed that pavucontrol
did not have any loopback devices listed. So, I ran the following pactl load-module module-loopback
. Now it is only listed under the Playback tab and none of the other ones. I have been testing all of this on Xubuntu 18.04, but I also have a Xubuntu 19.10 install.
In the past I have tried using ffmpeg with the pulse device, i.e. from pacmd list-sources
. This created a 1-2 second delay on the system audio being recorded.