我正在使用 Debian 9 及其版本的 ffmpeg。这是ffmpeg
我用来屏幕录制的命令:
ffmpeg -thread_queue_size 4096 -f alsa -i plughw:CARD=Device,DEV=0 -thread_queue_size 4096 \
-f alsa -i default -filter_complex amix=inputs=2:duration=first -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 96k -pix_fmt yuv420p -movflags faststart output.mp4
我能够同时成功录制系统声音和麦克风。但是,我首先需要打开pavucontrol
并确保系统音频在“输入设备”选项卡上设置为默认值。我希望能够使用系统声音的特定设备名称,就像我使用plughw:CARD=Device,DEV=0
.但是,我不确定应该使用什么。对于系统声音,使用-f pulse -i alsa_output.pci-0000_00_14.2.analog-stereo.monitor
有效,但录制的视频文件有大约15秒的延迟。所以,我需要使用-f alsa -i $device_name
.
这是输出pacmd list-sources
:
2 source(s) available.
index: 0
name: <alsa_input.usb-0c76_USB_PnP_Audio_Device-00.analog-mono>
driver: <module-alsa-card.c>
flags: HARDWARE HW_MUTE_CTRL HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY DYNAMIC_LATENCY
state: RUNNING
suspend cause:
priority: 9049
volume: mono: 63923 / 98% / -0.65 dB
balance 0.00
base volume: 19944 / 30% / -31.00 dB
volume steps: 65537
muted: no
current latency: 1.85 ms
max rewind: 0 KiB
sample spec: s16le 1ch 48000Hz
channel map: mono
Mono
used by: 1
linked by: 1
configured latency: 40.00 ms; range is 0.50 .. 2000.00 ms
card: 2 <alsa_card.usb-0c76_USB_PnP_Audio_Device-00>
module: 8
properties:
alsa.resolution_bits = "16"
device.api = "alsa"
device.class = "sound"
alsa.class = "generic"
alsa.subclass = "generic-mix"
alsa.name = "USB Audio"
alsa.id = "USB Audio"
alsa.subdevice = "0"
alsa.subdevice_name = "subdevice #0"
alsa.device = "0"
alsa.card = "2"
alsa.card_name = "USB PnP Audio Device"
alsa.long_card_name = "USB PnP Audio Device at usb-0000:00:10.1-1, full speed"
alsa.driver_name = "snd_usb_audio"
device.bus_path = "pci-0000:00:10.1-usb-0:1:1.0"
sysfs.path = "/devices/pci0000:00/0000:00:10.1/usb5/5-1/5-1:1.0/sound/card2"
udev.id = "usb-0c76_USB_PnP_Audio_Device-00"
device.bus = "usb"
device.vendor.id = "0c76"
device.vendor.name = "JMTek, LLC."
device.product.id = "161e"
device.product.name = "USB PnP Audio Device"
device.serial = "0c76_USB_PnP_Audio_Device"
device.string = "hw:2"
device.buffering.buffer_size = "192000"
device.buffering.fragment_size = "96000"
device.access_mode = "mmap+timer"
device.profile.name = "analog-mono"
device.profile.description = "Analog Mono"
device.description = "USB PnP Audio Device Analog Mono"
alsa.mixer_name = "USB Mixer"
alsa.components = "USB0c76:161e"
module-udev-detect.discovered = "1"
device.icon_name = "audio-card-usb"
ports:
analog-input-mic: Microphone (priority 8700, latency offset 0 usec, available: unknown)
properties:
device.icon_name = "audio-input-microphone"
active port: <analog-input-mic>
* index: 1
name: <alsa_output.pci-0000_00_14.2.analog-stereo.monitor>
driver: <module-alsa-card.c>
flags: DECIBEL_VOLUME LATENCY DYNAMIC_LATENCY
state: RUNNING
suspend cause:
priority: 1950
volume: front-left: 65536 / 100% / 0.00 dB, front-right: 65536 / 100% / 0.00 dB
balance 0.00
base volume: 65536 / 100% / 0.00 dB
volume steps: 65537
muted: no
current latency: 0.00 ms
max rewind: 344 KiB
sample spec: s16le 2ch 44100Hz
channel map: front-left,front-right
Stereo
used by: 1
linked by: 1
configured latency: 40.00 ms; range is 0.50 .. 1999.82 ms
monitor_of: 0
card: 3 <alsa_card.pci-0000_00_14.2>
module: 9
properties:
device.description = "Monitor of Built-in Audio Analog Stereo"
device.class = "monitor"
alsa.card = "0"
alsa.card_name = "HD-Audio Generic"
alsa.long_card_name = "HD-Audio Generic at 0xfeb00000 irq 16"
alsa.driver_name = "snd_hda_intel"
device.bus_path = "pci-0000:00:14.2"
sysfs.path = "/devices/pci0000:00/0000:00:14.2/sound/card0"
device.bus = "pci"
device.vendor.id = "1022"
device.vendor.name = "Advanced Micro Devices, Inc. [AMD]"
device.product.id = "780d"
device.product.name = "FCH Azalia Controller"
device.form_factor = "internal"
device.string = "0"
module-udev-detect.discovered = "1"
device.icon_name = "audio-card-pci"
这是输出arecord -L
:
default
Playback/recording through the PulseAudio sound server
null
Discard all samples (playback) or generate zero samples (capture)
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
我也尝试过使用-f alsa -i loopout
如上所述这里。我首先使用以下命令启用 ALSAaloop
内核模块:insmod /lib/modules/4.9.0-8-amd64/kernel/sound/drivers/snd-aloop.ko
。它正确加载:
~$ lsmod | grep aloop
snd_aloop 24576 6
snd_pcm 110592 10 snd_hda_intel,snd_hda_codec,snd_usb_audio,snd_hda_core,snd_hda_codec_hdmi,snd_aloop
snd 86016 35 snd_hda_intel,snd_hwdep,snd_hda_codec,snd_usb_audio,snd_timer,snd_rawmidi,snd_hda_codec_hdmi,snd_hda_codec_generic,snd_usbmidi_lib,snd_seq_device,snd_aloop,snd_hda_codec_realtek,snd_pcm
但是,我在尝试使用 ffmpeg 录制时收到错误:
[alsa @ 0x55bd6922ee40] cannot open audio device loopout (No such file or directory) loopout: Input/output error
。
使用环出(或者可能是环回?)可能是最理想的,因为我的理解是,无论硬件设备如何,这都可以捕获任何系统声音。
因此,总而言之,我希望能够使用 ALSA 在屏幕捕获期间捕获任何系统输出声音,无论当时默认的是哪种卡或设备。