我正在尝试使用ffmpeg录制屏幕和扬声器中的音频。在装有Ubuntu 18.04的塔式PC上,这可以正常工作,但不能在我的ThinkPad上工作。
On the tower PC, this works fine using https://trac.ffmpeg.org/wiki/Capture/Desktop
(from https://trac.ffmpeg.org/wiki/Capture/Desktop ). But if I use the laptop, the same command records the sound from my microphone, which leads to heavily decreased sound quality.
arecord -l
returns
arecord -l
**** Liste der Hardware-Geräte (CAPTURE) ****
Karte 3: PCH [HDA Intel PCH], Gerät 0: ALC3232 Analog [ALC3232 Analog]
Sub-Geräte: 1/1
Sub-Gerät #0: subdevice #0
and aplay -l
returns:
aplay -l
**** Liste der Hardware-Geräte (PLAYBACK) ****
Karte 2: HDMI [HDA Intel HDMI], Gerät 3: HDMI 0 [HDMI 0]
Sub-Geräte: 1/1
Sub-Gerät #0: subdevice #0
Karte 2: HDMI [HDA Intel HDMI], Gerät 7: HDMI 1 [HDMI 1]
Sub-Geräte: 1/1
Sub-Gerät #0: subdevice #0
Karte 2: HDMI [HDA Intel HDMI], Gerät 8: HDMI 2 [HDMI 2]
Sub-Geräte: 1/1
Sub-Gerät #0: subdevice #0
Karte 2: HDMI [HDA Intel HDMI], Gerät 9: HDMI 3 [HDMI 3]
Sub-Geräte: 1/1
Sub-Gerät #0: subdevice #0
Karte 2: HDMI [HDA Intel HDMI], Gerät 10: HDMI 4 [HDMI 4]
Sub-Geräte: 1/1
Sub-Gerät #0: subdevice #0
Karte 3: PCH [HDA Intel PCH], Gerät 0: ALC3232 Analog [ALC3232 Analog]
Sub-Geräte: 1/1
Sub-Gerät #0: subdevice #0
Trying to set input like with ffmpeg -video_size 1368x768 -framerate 25 -f x11grab -i :0.0+0,0 -f alsa -i hw:0,0 -ac 2 output.mkv
(so hw:0,0
which should in my opinition be the default device) results in an error:
ALSA lib pcm_hw.c:1713:(_snd_pcm_hw_open) Invalid value for card
[alsa @ 0x55931414d3e0] cannot open audio device hw:0,0 (No such file or directory)
If I use https://trac.ffmpeg.org/wiki/Capture/ALSA#Recordaudiofromanapplication, so call sudo modprobe snd-aloop pcm_substreams=1
, add
# .asoundrc
pcm.!default { type plug slave.pcm "hw:Loopback,0,0" }
to /etc/asound.conf
, change my output device to so loopback via the settings GUI and run ffmpeg -f alsa -ac 2 -ar 44100 -i hw:Loopback,1,0 out.wav
it records the audio perfectly correct. But if I run ffmpeg -video_size 1368x768 -framerate 25 -f x11grab -i :0.0+0,0 -f alsa -ac 2 -ar 44100 -i hw:Loopback,1,0 output.mkv
, it just records the screen and some very rare small noises.
是否有解决方法,或者还有另一种方式来记录我的屏幕和音频?
最佳答案
One solution I found is the accepted answer from Capturing ONLY desktop audio with ffmpeg : Install pavucontrol
, start recording with ffmpeg -video_size 1280x1024 -framerate 25 -f x11grab -i :0.0 -f pulse -vcodec mpeg2video -thread_queue_size 512 -ac 2 -t 02:00:00 -i default
(or whatever), go to pavucontrol
, choose Recorings and change Lavf56.15.102
(or whatever) to Monitor of Internal Audio Analog Stereo
. Worked for me.
I'll accept an answer which is able to do this without using pavucontrol
for change of recording every restart.