Capturing ONLY desktop audio with ffmpeg

32,095

Solution 1

pavucontrol

enter image description here

  1. Install pavucontrol.
  2. Start recording with ffmpeg (see example commands below).
  3. Start pavucontrol.
  4. Go to the Recording tab and you'll find ffmpeg or Lavf56.15.102 (or similar) listed there.
  5. Change audio capture from Internal Audio Analog Stereo to Monitor of Internal Audio Analog Stereo.

Now it should record system and application audio instead of the microphone.

This setting will be remembered. The next time you want to capture with ffmpeg, it will automatically start recording system audio. If you want to revert this, use pavucontrol again to change back to microphone input.

The text above was adapted from HOWTO: Screencasting on Linux.

example ffmpeg commands

audio only

ffmpeg -f pulse -i default output.wav

with screen capture

ffmpeg -f x11grab -video_size 1360x768 -framerate 30 -i :0.0 -f pulse -i default -preset ultrafast -crf 18 -pix_fmt yuv420p out.mkv

Solution 2

You can also record to compressed MP3 (with a bit rate of your choice) such as:

ffmpeg -f alsa -ac 2 -i default -acodec libmp3lame -ab 320k ouput.mp3
Share:
32,095

Related videos on Youtube

Elderzz
Author by

Elderzz

Updated on September 18, 2022

Comments

  • Elderzz
    Elderzz almost 2 years

    I want to know how can I only capture desktop audio (means no mic!).

    I am using this command:

    $ ffmpeg -f x11grab -s 1360x768 -r 30 -i :0.0 -preset ultrafast ~/Videos/out.mp4
    ffmpeg version 2.4.3-1ubuntu1~trusty6 Copyright (c) 2000-2014 the FFmpeg developers
      built on Nov 22 2014 17:07:19 with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
      configuration: --prefix=/usr --extra-version='1ubuntu1~trusty6' --build-suffix=-ffmpeg --toolchain=hardened --extra-cflags= --extra-cxxflags= --libdir=/usr/lib/x86_64-linux-gnu --shlibdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --enable-shared --disable-stripping --enable-avresample --enable-avisynth --enable-fontconfig --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger --enable-libshine --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-opengl --enable-x11grab --enable-libxvid --enable-libx265 --enable-libdc1394 --enable-libiec61883 --enable-libzvbi --enable-libzmq --enable-frei0r --enable-libx264 --enable-libsoxr --enable-openal --enable-libopencv
      libavutil      54.  7.100 / 54.  7.100
      libavcodec     56.  1.100 / 56.  1.100
      libavformat    56.  4.101 / 56.  4.101
      libavdevice    56.  0.100 / 56.  0.100
      libavfilter     5.  1.100 /  5.  1.100
      libavresample   2.  1.  0 /  2.  1.  0
      libswscale      3.  0.100 /  3.  0.100
      libswresample   1.  1.100 /  1.  1.100
      libpostproc    53.  0.100 / 53.  0.100
    [x11grab @ 0x16051e0] device: :0.0 -> display: :0.0 x: 0 y: 0 width: 1360 height: 768
    [x11grab @ 0x16051e0] shared memory extension found
    Input #0, x11grab, from ':0.0':
      Duration: N/A, start: 1444234613.435347, bitrate: 1002700 kb/s
        Stream #0:0: Video: rawvideo (BGR[0] / 0x524742), bgr0, 1360x768, 1002700 kb/s, 30 tbr, 1000k tbn, 30 tbc
    File '/home/elderzz/Videos/out.mp4' already exists. Overwrite ? [y/N] ^A
    

    I can capture mic with another app, but I need the mic audio to be in a different file. I only want to capture desktop audio!

  • Anmol Singh Jaggi
    Anmol Singh Jaggi about 8 years
    Will this recording be lossless?
  • llogan
    llogan about 8 years
    @AnmolSinghJaggi No. -crf 18 is lossy, and there is also loss due to RGB to YUV 4:2:0 colorspace conversion.
  • Anmol Singh Jaggi
    Anmol Singh Jaggi about 8 years
    No I was talking about the audio only part.
  • llogan
    llogan about 8 years
    @AnmolSinghJaggi Yes, the audio should be lossless.
  • Anmol Singh Jaggi
    Anmol Singh Jaggi over 6 years
    How to stop the recording? q or Ctrl-C is not working.
  • llogan
    llogan over 6 years
    @AnmolSinghJaggi It should be working. Try kill -s SIGINT $(pgrep ffmpeg).
  • regnarg
    regnarg over 4 years
    If you do not want to switch the source manually, you can use the command pactl list soruces to figure out the internal name of the monitor source and then use -f pulse -i NAME instead of default, e.g. -f pulse -i alsa_output.pci-0000_00_1f.3.analog-stereo.monitor The exact name will differ from system to system.
  • Phani Rithvij
    Phani Rithvij about 4 years
    @regnarg After I record using -i alsa_output.pci-0000_00_1f.3.analog-stereo.monitor (it is same for my system) when I play the output using mpv I get Audio device underrun detected. And there's no audio output (Played a song in the background)