我一直在尝试创建一个虚拟设备来使用纯 ALSA 录制声卡的内部音频。经过大量谷歌搜索后,我找到了一个.asoundrc
非常接近我正在寻找的文件的文件:
pcm.mycard {
type hw
card 0
}
ctl.mycard {
type hw
card 0
}
pcm.myconvert {
type plug
slave {
pcm "myrecord"
format S16_LE
}
}
pcm.myrecord {
type file
format "raw"
slave.pcm "mycard"
file "| oggenc -Q -q6 -r -B %b -C %c -R %r -o /tmp/record-$(date +%%Y-%%m-%%d_%%H%%M%%S).ogg -"
}
pcm.!default{
type asym
playback.pcm "myconvert"
capture.pcm "mycard"
}
此配置可以录制ogg
包含我计算机中播放的所有音频的文件。我现在想做的是修改部分pcm.myrecord
配置,以便音频在虚拟卡中“流式传输”,稍后我可以使用arecord
.如果有人能帮助我解决这个问题,我会很高兴。
我试过这个:如何创建虚拟 ALSA 设备以记录播放的所有内容?但这对我来说不起作用。以下是输出arecord -L
:
muammar@zarathustra /tmp
% arecord -L !10015
null
Discard all samples (playback) or generate zero samples (capture)
default:CARD=PCH
HDA Intel PCH, CS4208 Analog
Default Audio Device
sysdefault:CARD=PCH
HDA Intel PCH, CS4208 Analog
Default Audio Device
front:CARD=PCH,DEV=0
HDA Intel PCH, CS4208 Analog
Front speakers
dmix:CARD=PCH,DEV=0
HDA Intel PCH, CS4208 Analog
Direct sample mixing device
dsnoop:CARD=PCH,DEV=0
HDA Intel PCH, CS4208 Analog
Direct sample snooping device
hw:CARD=PCH,DEV=0
HDA Intel PCH, CS4208 Analog
Direct hardware device without any conversions
plughw:CARD=PCH,DEV=0
HDA Intel PCH, CS4208 Analog
Hardware device with all software conversions
default:CARD=Loopback
Loopback, Loopback PCM
Default Audio Device
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
谢谢。
答案1
我按如下方式解决了这个问题:
首先,加载snd-aloop
模块:
sudo modprobe snd-aloop
这将创建一个名为的新设备Loopback
:
± % cat /proc/asound/cards !10017
0 [PCH ]: HDA-Intel - HDA Intel PCH
HDA Intel PCH at 0xc1814000 irq 60
1 [HDMI ]: HDA-Intel - HDA Intel HDMI
HDA Intel HDMI at 0xc1810000 irq 61
2 [Loopback ]: Loopback - Loopback
Loopback 1
根据上面显示的信息,我们必须创建两个hw
设备:
hw:0,0
(PCH是我的主声卡)。hw:2,1
(Loopback
虚拟设备)。
通常,hw
设备的形式为:hw:X,Y
。就我们的目的而言,Y
对于主卡来说,似乎总是0
,而对于我们来说,Loopback
我们有Y
equals 1
。
现在,为了完成所有这些工作,我们需要一个~/.asoundrc
包含以下内容的文件:
pcm.!default {
type asym
playback.pcm "LoopAndReal"
#capture.pcm "looprec"
capture.pcm "hw:X1,Y1"
}
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:X1,Y1"
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
}
}
hw:X1,Y1
使用主卡的值进行修改(在我的例子中hw:0,0
)。
您可以通过在计算机中播放某些内容来测试此配置是否有效。如果你听到了,那就好了。现在让我们在计算机中播放一些内容,并使用以下命令从该虚拟设备录制它ffmpeg
:
ffmpeg -f alsa -i hw:X2,Y2 -c:a libmp3lame -b:a 256k -vn capture.mp3
在这种情况下,
hw:X2,Y2
必须更换设备的位置。Loopback
hw:2,1
我认为使用arecord
也应该有效。