我有一些通过 USB 连接的网络摄像头设备,我想使用arecord
.设备列表如下(卡 1 至 4):
t:~$ arecord --list-devices
**** List of CAPTURE Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: ALC Analog [ALC Analog]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: TT [CA TT], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 2: TT_1 [CA TT], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 3: TT_2 [CA TT], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 4: TT_3 [CA TT], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0
当我列出 PulseAudio 看到的设备时,我有以下内容(部分列表仅显示网络摄像头):
t:~$pactl list
Module #0
Name: module-device-restore
....
Card #11
Name: alsa_card.usb-VS_Inc_CA_TT-02
Driver: module-alsa-card.c
Owner Module: 38
Properties:
alsa.card = "1"
alsa.card_name = "CA TT"
alsa.long_card_name = "VS Inc CA TT at usb-0000:00:14.0-3"
alsa.driver_name = "snd_usb_audio"
device.bus_path = "pci-0000:00:14.0-usb-0:3:1.2"
sysfs.path = "/devices/pci0000:00/0000:00:14.0/usb2/2-3/2-3:1.2/sound/card1"
udev.id = "usb-VS_Inc_CA_TT-02"
device.bus = "usb"
device.vendor.id = "1a1a"
device.vendor.name = "Technology Inc."
device.product.id = "2a2a"
device.product.name = "CA TT"
device.serial = "VS_Inc_CA_TT"
device.form_factor = "webcam"
device.string = "1"
device.description = "CA TT"
module-udev-detect.discovered = "1"
device.icon_name = "camera-web-usb"
Profiles:
input:analog-stereo: Analog Stereo Input (sinks: 0, sources: 1, priority: 60, available: yes)
input:iec958-stereo: Digital Stereo (IEC958) Input (sinks: 0, sources: 1, priority: 55, available: yes)
off: Off (sinks: 0, sources: 0, priority: 0, available: yes)
Active Profile: input:analog-stereo
Ports:
analog-input: Analog Input (priority: 10000, latency offset: 0 usec)
Part of profile(s): input:analog-stereo
iec958-stereo-input: Digital Input (S/PDIF) (priority: 0, latency offset: 0 usec)
Part of profile(s): input:iec958-stereo
Card #12
Name: alsa_card.usb-VS_Inc_CA_TT-02.2
Driver: module-alsa-card.c
Owner Module: 39
Properties:
alsa.card = "2"
alsa.card_name = "CA TT"
alsa.long_card_name = "VS Inc CA TT at usb-0000:00:14.0-4"
alsa.driver_name = "snd_usb_audio"
device.bus_path = "pci-0000:00:14.0-usb-0:4:1.2"
sysfs.path = "/devices/pci0000:00/0000:00:14.0/usb2/2-4/2-4:1.2/sound/card2"
udev.id = "usb-VS_Inc_CA_TT-02"
device.bus = "usb"
device.vendor.id = "1a1a"
device.vendor.name = "Technology Inc."
device.product.id = "2a2a"
device.product.name = "CA TT"
device.serial = "VS_Inc_CA_TT"
device.form_factor = "webcam"
device.string = "2"
device.description = "CA TT"
module-udev-detect.discovered = "1"
device.icon_name = "camera-web-usb"
Profiles:
input:analog-stereo: Analog Stereo Input (sinks: 0, sources: 1, priority: 60, available: yes)
input:iec958-stereo: Digital Stereo (IEC958) Input (sinks: 0, sources: 1, priority: 55, available: yes)
off: Off (sinks: 0, sources: 0, priority: 0, available: yes)
Active Profile: input:analog-stereo
Ports:
analog-input: Analog Input (priority: 10000, latency offset: 0 usec)
Part of profile(s): input:analog-stereo
iec958-stereo-input: Digital Input (S/PDIF) (priority: 0, latency offset: 0 usec)
Part of profile(s): input:iec958-stereo
Card #13
Name: alsa_card.usb-VS_Inc_CA_TT-02.3
Driver: module-alsa-card.c
Owner Module: 40
Properties:
alsa.card = "3"
alsa.card_name = "CA TT"
alsa.long_card_name = "VS Inc CA TT at usb-0000:00:14.0-1"
alsa.driver_name = "snd_usb_audio"
device.bus_path = "pci-0000:00:14.0-usb-0:1:1.2"
sysfs.path = "/devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.2/sound/card3"
udev.id = "usb-VS_Inc_CA_TT-02"
device.bus = "usb"
device.vendor.id = "1a1a"
device.vendor.name = "Technology Inc."
device.product.id = "2a2a"
device.product.name = "CA TT"
device.serial = "VS_Inc_CA_TT"
device.form_factor = "webcam"
device.string = "3"
device.description = "CA TT"
module-udev-detect.discovered = "1"
device.icon_name = "camera-web-usb"
Profiles:
input:analog-stereo: Analog Stereo Input (sinks: 0, sources: 1, priority: 60, available: yes)
input:iec958-stereo: Digital Stereo (IEC958) Input (sinks: 0, sources: 1, priority: 55, available: yes)
off: Off (sinks: 0, sources: 0, priority: 0, available: yes)
Active Profile: input:analog-stereo
Ports:
analog-input: Analog Input (priority: 10000, latency offset: 0 usec)
Part of profile(s): input:analog-stereo
iec958-stereo-input: Digital Input (S/PDIF) (priority: 0, latency offset: 0 usec)
Part of profile(s): input:iec958-stereo
Card #14
Name: alsa_card.usb-VS_Inc_CA_TT-02.4
Driver: module-alsa-card.c
Owner Module: 41
Properties:
alsa.card = "4"
alsa.card_name = "CA TT"
alsa.long_card_name = "VS Inc CA TT at usb-0000:00:14.0-2"
alsa.driver_name = "snd_usb_audio"
device.bus_path = "pci-0000:00:14.0-usb-0:2:1.2"
sysfs.path = "/devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.2/sound/card4"
udev.id = "usb-VS_Inc_CA_TT-02"
device.bus = "usb"
device.vendor.id = "1a1a"
device.vendor.name = "Technology Inc."
device.product.id = "2a2a"
device.product.name = "CA TT"
device.serial = "VS_Inc_CA_TT"
device.form_factor = "webcam"
device.string = "4"
device.description = "CA TT"
module-udev-detect.discovered = "1"
device.icon_name = "camera-web-usb"
Profiles:
input:analog-stereo: Analog Stereo Input (sinks: 0, sources: 1, priority: 60, available: yes)
input:iec958-stereo: Digital Stereo (IEC958) Input (sinks: 0, sources: 1, priority: 55, available: yes)
off: Off (sinks: 0, sources: 0, priority: 0, available: yes)
Active Profile: input:analog-stereo
Ports:
analog-input: Analog Input (priority: 10000, latency offset: 0 usec)
Part of profile(s): input:analog-stereo
iec958-stereo-input: Digital Input (S/PDIF) (priority: 0, latency offset: 0 usec)
Part of profile(s): input:iec958-stereo
arecord --list-devices
现在,我正在编写一个 shell 脚本,该脚本从固定配置文件中读取卡号,并且我不希望在拔掉其中一个网络摄像头时更改其中的卡号。我想确保网络摄像头已连接到第一个 USB 端口(/devices/pci0000:00/0000:00:14.0/usb2/2-3/2-3:1.2
) 的网络摄像头是总是映射到卡 1,第二张映射到卡 2,依此类推。换句话说,我希望网络摄像头/USB 端口与卡号之间的映射是固定的。
这可能吗?
答案1
换卡数字对于具有相同 USB ID 的设备是不可能的。
但是可以使用udev规则来改变卡ID(TT_2
上面等),也可以与arecord
。请参阅“识别两个相同的音频设备”https://alsa.opensrc.org/Udev:
SUBSYSTEM!="sound", GOTO="my_usb_audio_end" ACTION!="add", GOTO="my_usb_audio_end" DEVPATH=="/devices/pci0000:00/0000:00:13.2/usb2/2-6/2-6.2/2-6.2:1.0/sound/card?", ATTR{id}="UA1A_A" DEVPATH=="/devices/pci0000:00/0000:00:13.2/usb2/2-6/2-6.3/2-6.3:1.0/sound/card?", ATTR{id}="UA1A_B" LABEL="my_usb_audio_end"
$ arecord -D default:UA1A_A something.wav