0

I am trying to record my screen and the audio from my speakers using ffmpeg. This works fine on my tower PC with Ubuntu 18.04, but does not work using my 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.

Is there a workaround for this, or is there another way to record my screen and the audio?

0

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.

0

A very useful answer can be found here: https://unix.stackexchange.com/a/489522

Translated to your case, it might read as follows:

A="$(pacmd list-sources | grep -PB 1 "analog.*monitor>" | head -n 1 | perl -pe 's/.* //g')"
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 "$A"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.