You are not logged in.
Hi, I've been trying to record system sound through an ALSA loopback to no success. I am trying to use ffmpeg, though I suppose arecorder should work as well.
I followed this guide, which for convenience I will reproduce below: https://trac.ffmpeg.org/wiki/Capture/ALSA
First add the aloop module
sudo modprobe snd-aloop pcm_substreams=1
This should create a loopback device. Here's the output of aplay -l:
card 0: PCH [HDA Intel PCH], device 0: CX20590 Analog [CX20590 Analog]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: NVidia [HDA NVidia], device 3: HDMI 0 [HDMI 0]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: NVidia [HDA NVidia], device 7: HDMI 1 [HDMI 1]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: NVidia [HDA NVidia], device 8: HDMI 2 [HDMI 2]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 2: Loopback [Loopback], device 0: Loopback PCM [Loopback PCM]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 2: Loopback [Loopback], device 1: Loopback PCM [Loopback PCM]
Subdevices: 1/1
Subdevice #0: subdevice #0
then set ~/.asoundrc to the following:
# .asoundrc
pcm.multi {
type route;
slave.pcm {
type multi;
slaves.a.pcm "output";
slaves.b.pcm "loopin";
slaves.a.channels 2;
slaves.b.channels 2;
bindings.0.slave a;
bindings.0.channel 0;
bindings.1.slave a;
bindings.1.channel 1;
bindings.2.slave b;
bindings.2.channel 0;
bindings.3.slave b;
bindings.3.channel 1;
}
ttable.0.0 1;
ttable.1.1 1;
ttable.0.2 1;
ttable.1.3 1;
}
pcm.!default {
type plug
slave.pcm "multi"
}
pcm.output {
type hw
card 0 # replace with your output card, if needed
}
pcm.loopin {
type plug
slave.pcm "hw:Loopback,0,0"
}
pcm.loopout {
type plug
slave.pcm "hw:Loopback,1,0"
}
Finally, record with
ffmpeg -f alsa -ac 2 -ar 44100 -i loopout out.wav
However, my out.wav file gets created, but just remains an empty file, even though ffmpeg appears to successfully record. I'm not sure what the problem is.
I've also tried this guide from stackexchange, no success:
https://unix.stackexchange.com/question … undrc-file
I've also tried the solution from this old thread
https://bbs.archlinux.org/viewtopic.php?id=147852
Does anyone know what's going wrong here?
Last edited by accy (2019-12-23 04:40:59)
Offline
Haven't done that in a while. I have a script that does this. If this does you any good.
mv ~/.loop_asoundrc ~/.asoundrc
modprobe snd-aloop
cat ~/.asoundrc
pcm.!default {
type asym
playback.pcm "LoopAndReal"
#capture.pcm "looprec"
capture.pcm "hw:0,0"
}
pcm.looprec {
type hw
card "Loopback"
device 1
subdevice 0
}
pcm.LoopAndReal {
type plug
slave.pcm mdev
route_policy "duplicate"
}
pcm.mdev {
type multi
slaves.a.pcm pcm.MixReale
slaves.a.channels 2
slaves.b.pcm pcm.MixLoopback
slaves.b.channels 2
bindings.0.slave a
bindings.0.channel 0
bindings.1.slave a
bindings.1.channel 1
bindings.2.slave b
bindings.2.channel 0
bindings.3.slave b
bindings.3.channel 1
}
pcm.MixReale {
type dmix
ipc_key 1024
slave {
pcm "hw:0,0"
rate 48000
#rate 44100
periods 128
period_time 0
period_size 1024 # must be power of 2
buffer_size 8192
}
}
pcm.MixLoopback {
type dmix
ipc_key 1025
slave {
pcm "hw:Loopback,0,0"
rate 48000
#rate 44100
periods 128
period_time 0
period_size 1024 # must be power of 2
buffer_size 8192
}
}
ffmpeg -f alsa -i hw:1,1 -c:a libmp3lame -b:a 32k -vn capture.mp3
ffprobe ~/capture.mp3
...
Input #0, mp3, from '~/capture.mp3':
Metadata:
encoder : Lavf58.29.100
Duration: 00:00:15.07, start: 0.023021, bitrate: 32 kb/s
Stream #0:0: Audio: mp3, 48000 Hz, stereo, fltp, 32 kb/s
And capture.mp3 plays ok.
Offline