Record desktop and microphone audio with Avconv

Solution 1:

  • Install Pulse Audio Control

    sudo apt-get install pavucontrol
    
  • Only playback record (no microphone)

    Open it → Input Devices → Show: All input devices → Use Green Button to the right to Select "Monitor: Analog Audio"

    There are different channel names but You can run some player and see which has signal.

    When Gnome Volume Control is opened, It overrides it back to Microphone. I have noticed that in the late releases 13.04, 13.10, 14.04. It cannot be changed back using Gnome Volume Control. (Avoid using it on recording)

Pulse Audio Control : Input Devices

  • Both microphone and playback mixed: pactl CLI could be used. Exmaple:

    1. Check name of sink

      $ pactl list short sinks
      0   alsa_output.pci-0000_01_00.1.hdmi-stereo    module-alsa-card.c  s16le 2ch 44100Hz   SUSPENDED
      1   alsa_output.pci-0000_00_1b.0.analog-stereo  module-alsa-card.c  s16le 2ch 44100Hz   SUSPENDED
      
    2. Loopback microphone source to analog sink

      $ pactl load-module module-loopback latency_msec=1 sink=alsa_output.pci-0000_00_1b.0.analog-stereo
      30
      
    3. Use same step above to select the correct input device.

    To close it:

    $ pactl unload-module 30
    

    or using name:

    $ pactl unload-module module-loopback
    

    To check module id:

    $ pactl list short modules
    
  • In case, Unable to find a Playback Analog Monitor in the Input Devices

    1. Check Configuration tab, it should be Full Duplex (Input/Output)

    2. Otherwise, It is possible to create a virtual output device then loop it back.

      pactl load-module module-null-sink sink_name=Virtual1
      pactl load-module module-loopback latency_msec=1 sink=Virtual1
      
    3. Then use Pulse Audio Control, Same step above to select the correct input device Virtual1.

    4. For output device:

      • Use Output Devices tab if all mixed system output needed.

      • Or use Playback tab if only some application output needed (like: just VLC music play ...). In this case you can record somethings and listen to somethings else.

    As reference see, How can I use PulseAudio virtual audio streams to play music over Skype?

  • if it didn't work (your case as example)

    1. Check exact name of "Analog Stereo Output" sink

      pactl list sinks
      
    2. Loop back microphone to "Analog Stereo Output"

      pactl load-module module-loopback latency_msec=1 sink=alsa_output.usb-C-Media_Electronics_Inc._USB_PnP_Sound_Device-00-Device.ana‌​log-stereo
      
    3. Check exact name of "Analog Stereo Output Monitor" source

      pactl list sources
      
    4. Then Record directly by specifying device name of "Analog Stereo Output Monitor", Example in your case:

      avconv -f pulse -i "alsa_output.usb-C-Media_Electronics_Inc._USB_PnP_Sound_Device-00-Device.analog-‌​stereo.monitor" -b 64k -f x11grab -r 25 -s 1280x800 -i :0.0 -vcodec libx264 -preset ultrafast -threads 4 -y myscreencast2.mp4
      

Solution 2:

-i:0.0 will "steal" the microphone from pulse and you won't be able to use the mirophone while recording (like on a skype conversation).

A looback interface will introduce some delay between the played sound and the recorded.

This worked for me:

ffmpeg -f pulse -i 0 -f pulse -i 1  -filter_complex amerge  out.wav

0 & 1 are pulse audio sources listed with

pactl list sinks