我有一个 ffmpeg 脚本来进行截屏视频。我办公室有 Debian 9,家里有 Xubuntu 18.04。在这两个操作系统上,以下内容可以从我的麦克风录制系统音频。
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
这使用脉冲“内置音频监视器”来捕获桌面音频。不幸的是,在 Debian 10、Xubuntu 19.04 和 19.10 以及 Fedora 30 上,当我想结束屏幕录制并按下q
它时,它无法正常停止。它挂了。然后我必须多次使用 ctrl+c 才能回到提示符。它会终止我的脚本并且不运行所需的以下命令。我一有机会就会报告这个错误。我不确定这是 ALSA 还是 Pulse 错误。我不认为这是一个 ffmpeg bug,因为我在 Debian 9 和 Debian 10 上都有相同的 ffmpeg 版本,而且它只发生在 Debian 10 上,而不是 Debian 9 上。
我有一台联想 ThinkCentre。有前后音频输出和麦克风 3.5 毫米插孔。我使用 3.5 毫米电缆将音频传回到麦克风插孔。它有效,但音频质量很差。为此,我-f alsa -i plughw:CARD=Generic,DEV=0
在 ffmpeg 命令中使用了它。通过使用 ALSA 设备名称,它不会挂在 Xubuntu 19.10 等上。
因此,我一直在尝试让 ALSA Loopback 设备来录制系统音频。我根本没能把它记录下来。我在启动时加载snd-aloop
内核模块。我在~/.asoundrc
页面底部尝试了各种配置选项这里并且这里。这是arecord -L
我的系统上的输出。
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
我使用列出的环回设备进行了以下测试运行。以下没有记录我正在播放的音频。
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
我注意到pavucontrol
没有列出任何环回设备。所以,我运行了以下命令pactl load-module module-loopback
。现在它仅列在“播放”选项卡下,而没有其他选项卡。我一直在 Xubuntu 18.04 上测试所有这些,但我也安装了 Xubuntu 19.10。
过去我尝试过将 ffmpeg 与脉冲设备一起使用,即来自pacmd list-sources
.这会导致录制的系统音频出现 1-2 秒的延迟。
答案1
这对我有用:
ffmpeg -f alsa -ac 1 -i dsnoop:CARD=USB,DEV=0 -acodec mp3 -y ~/recording/$(date +"%Y-%m-%d_%H:%M").mp3
我认为关键可能是使用指向物理设备的 dsnoop 条目之一,而不是环回,但我不确定。