7

I'm using Avconv on Ubuntu 13.10 with Gnome 3.10 to record Minecraft screencasts. However, I can only get the sound from my microphone and not the laptop speaker. How would I go about recording both laptop and microphone? I'm using a USB headset with a microphone.

Info requested by @Sneetsher:

The actual command:

avconv -f pulse -i default -b 64k -f x11grab -r 25 -s 1280x800 -i :0.0 -vcodec libx264 -preset ultrafast -threads 4 -y myscreencast2.mp4 

PulseAudio info:

$ pactl list short

0   module-device-restore       
1   module-stream-restore       
2   module-card-restore     
3   module-augment-properties       
4   module-switch-on-port-available     
5   module-alsa-card    device_id="0" name="pci-0000_00_1b.0" card_name="alsa_card.pci-0000_00_1b.0" namereg_fail=false tsched=yes fixed_latency_range=no ignore_dB=no deferred_volume=yes use_ucm=yes card_properties="module-udev-detect.discovered=1"    
6   module-alsa-card    device_id="1" name="usb-C-Media_Electronics_Inc._USB_PnP_Sound_Device-00-Device" card_name="alsa_card.usb-C-Media_Electronics_Inc._USB_PnP_Sound_Device-00-Device" namereg_fail=false tsched=yes fixed_latency_range=no ignore_dB=no deferred_volume=yes use_ucm=yes card_properties="module-udev-detect.discovered=1"  
7   module-udev-detect      
8   module-bluetooth-policy     
9   module-bluetooth-discover       
10  module-native-protocol-unix     
11  module-default-device-restore       
12  module-rescue-streams       
13  module-always-sink      
14  module-intended-roles       
15  module-suspend-on-idle      
16  module-systemd-login        
17  module-position-event-sounds        
18  module-filter-heuristics        
19  module-filter-apply     
20  module-x11-publish  display=:0  
21  module-x11-bell display=:0 sample=bell.ogg  
22  module-x11-cork-request display=:0  
23  module-x11-xsmp display=:0 session_manager=local/MELVIN-124833:@/tmp/.ICE-unix/2013,unix/MELVIN-124833:/tmp/.ICE-unix/2013  
0   alsa_output.pci-0000_00_1b.0.analog-stereo  module-alsa-card.c  s16le 2ch 44100Hz   IDLE
1   alsa_output.usb-C-Media_Electronics_Inc._USB_PnP_Sound_Device-00-Device.iec958-stereo   module-alsa-card.c  s16le 2ch 44100Hz   IDLE
0   alsa_output.pci-0000_00_1b.0.analog-stereo.monitor  module-alsa-card.c  s16le 2ch 44100Hz   RUNNING
1   alsa_input.pci-0000_00_1b.0.analog-stereo   module-alsa-card.c  s16le 2ch 44100Hz   RUNNING
2   alsa_output.usb-C-Media_Electronics_Inc._USB_PnP_Sound_Device-00-Device.iec958-stereo.monitor   module-alsa-card.c  s16le 2ch 44100Hz   RUNNING
3   alsa_input.usb-C-Media_Electronics_Inc._USB_PnP_Sound_Device-00-Device.analog-mono  module-alsa-card.c  s16le 1ch 44100Hz   RUNNING
15  0   28  protocol-native.c   float32le 1ch 25Hz
16  1   28  protocol-native.c   float32le 1ch 25Hz
17  2   28  protocol-native.c   float32le 1ch 25Hz
18  3   28  protocol-native.c   float32le 1ch 25Hz
0   module-systemd-login.c  (null)
5   module-x11-xsmp.c   (null)
6   protocol-native.c   gnome-settings-daemon
7   protocol-native.c   gnome-shell
8   protocol-native.c   gnome-shell
9   protocol-native.c   chrome
28  protocol-native.c   pavucontrol
36  protocol-native.c   pactl
0   screen-capture  s16le 2ch 96000Hz   0.872
1   bell-window-system  s16le 2ch 44100Hz   0.749
0   alsa_card.pci-0000_00_1b.0  module-alsa-card.c
1   alsa_card.usb-C-Media_Electronics_Inc._USB_PnP_Sound_Device-00-Device   module-alsa-card.c

$ pactl stats

Currently in use: 12 blocks containing 548.2 KiB bytes total.
Allocated during whole lifetime: 7254422 blocks containing 2.9 GiB bytes total.
Sample cache size: 456.2 KiB
Server String: unix:/run/user/1000/pulse/native
Library Protocol Version: 28
Server Protocol Version: 28
Is Local: yes
Client Index: 37
Tile Size: 65496
User Name: guilmon
Host Name: MELVIN-124833
Server Name: pulseaudio
Server Version: 4.0
Default Sample Specification: s16le 2ch 44100Hz
Default Channel Map: front-left,front-right
Default Sink: alsa_output.usb-C-Media_Electronics_Inc._USB_PnP_Sound_Device-00-Device.iec958-stereo
Default Source: alsa_output.usb-C-Media_Electronics_Inc._USB_PnP_Sound_Device-00-Device.iec958-stereo.monitor
Cookie: 3f2a:1764

enter image description here

Updated Screenshots:

enter image description here enter image description here

$ pactl list sources

Source #0
    State: SUSPENDED
    Name: alsa_output.pci-0000_00_1b.0.analog-stereo.monitor
    Description: Monitor of Built-in Audio Analogue Stereo
    Driver: module-alsa-card.c
    Sample Specification: s16le 2ch 44100Hz
    Channel Map: front-left,front-right
    Owner Module: 5
    Mute: no
    Volume: 0:  20% 1:  20%
            0: -42.50 dB 1: -42.50 dB
            balance 0.00
    Base Volume: 100%
                 0.00 dB
    Monitor of Sink: alsa_output.pci-0000_00_1b.0.analog-stereo
    Latency: 0 usec, configured 0 usec
    Flags: DECIBEL_VOLUME LATENCY 
    Properties:
        device.description = "Monitor of Built-in Audio Analogue Stereo"
        device.class = "monitor"
        alsa.card = "0"
        alsa.card_name = "HDA Intel"
        alsa.long_card_name = "HDA Intel at 0xe4644000 irq 48"
        alsa.driver_name = "snd_hda_intel"
        device.bus_path = "pci-0000:00:1b.0"
        sysfs.path = "/devices/pci0000:00/0000:00:1b.0/sound/card0"
        device.bus = "pci"
        device.vendor.id = "8086"
        device.vendor.name = "Intel Corporation"
        device.product.id = "284b"
        device.product.name = "82801H (ICH8 Family) HD Audio Controller"
        device.form_factor = "internal"
        device.string = "0"
        module-udev-detect.discovered = "1"
        device.icon_name = "audio-card-pci"
    Formats:
        pcm

Source #1
    State: SUSPENDED
    Name: alsa_input.pci-0000_00_1b.0.analog-stereo
    Description: Built-in Audio Analogue Stereo
    Driver: module-alsa-card.c
    Sample Specification: s16le 2ch 44100Hz
    Channel Map: front-left,front-right
    Owner Module: 5
    Mute: no
    Volume: 0:  84% 1:  84%
            0: -4.50 dB 1: -4.50 dB
            balance 0.00
    Base Volume:  13%
                 -52.50 dB
    Monitor of Sink: n/a
    Latency: 0 usec, configured 0 usec
    Flags: HARDWARE HW_MUTE_CTRL HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY 
    Properties:
        alsa.resolution_bits = "16"
        device.api = "alsa"
        device.class = "sound"
        alsa.class = "generic"
        alsa.subclass = "generic-mix"
        alsa.name = "AD198x Analog"
        alsa.id = "AD198x Analog"
        alsa.subdevice = "0"
        alsa.subdevice_name = "subdevice #0"
        alsa.device = "0"
        alsa.card = "0"
        alsa.card_name = "HDA Intel"
        alsa.long_card_name = "HDA Intel at 0xe4644000 irq 48"
        alsa.driver_name = "snd_hda_intel"
        device.bus_path = "pci-0000:00:1b.0"
        sysfs.path = "/devices/pci0000:00/0000:00:1b.0/sound/card0"
        device.bus = "pci"
        device.vendor.id = "8086"
        device.vendor.name = "Intel Corporation"
        device.product.id = "284b"
        device.product.name = "82801H (ICH8 Family) HD Audio Controller"
        device.form_factor = "internal"
        device.string = "front:0"
        device.buffering.buffer_size = "65536"
        device.buffering.fragment_size = "32768"
        device.access_mode = "mmap+timer"
        device.profile.name = "analog-stereo"
        device.profile.description = "Analogue Stereo"
        device.description = "Built-in Audio Analogue Stereo"
        alsa.mixer_name = "Analog Devices AD1981"
        alsa.components = "HDA:11d41981,103c30be,00100200 HDA:14f12c06,103c1379,00100000"
        module-udev-detect.discovered = "1"
        device.icon_name = "audio-card-pci"
    Ports:
        analog-input-microphone-internal: Internal Microphone (priority: 8900)
        analog-input-microphone-dock: Dock Microphone (priority: 7800)
        analog-input-microphone: Microphone (priority: 8700)
    Active Port: analog-input-microphone
    Formats:
        pcm

Source #5
    State: SUSPENDED
    Name: alsa_input.usb-C-Media_Electronics_Inc._USB_PnP_Sound_Device-00-Device.analog-mono
    Description: USB PnP Sound Device Analogue Mono
    Driver: module-alsa-card.c
    Sample Specification: s16le 1ch 48000Hz
    Channel Map: mono
    Owner Module: 26
    Mute: no
    Volume: 0:  85%
            0: -4.10 dB
            balance 0.00
    Base Volume:  40%
                 -23.81 dB
    Monitor of Sink: n/a
    Latency: 0 usec, configured 0 usec
    Flags: HARDWARE HW_MUTE_CTRL HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY 
    Properties:
        alsa.resolution_bits = "16"
        device.api = "alsa"
        device.class = "sound"
        alsa.class = "generic"
        alsa.subclass = "generic-mix"
        alsa.name = "USB Audio"
        alsa.id = "USB Audio"
        alsa.subdevice = "0"
        alsa.subdevice_name = "subdevice #0"
        alsa.device = "0"
        alsa.card = "1"
        alsa.card_name = "USB PnP Sound Device"
        alsa.long_card_name = "C-Media Electronics Inc. USB PnP Sound Device at usb-0000:00:1d.2-2, full speed"
        alsa.driver_name = "snd_usb_audio"
        device.bus_path = "pci-0000:00:1d.2-usb-0:2:1.0"
        sysfs.path = "/devices/pci0000:00/0000:00:1d.2/usb7/7-2/7-2:1.0/sound/card1"
        udev.id = "usb-C-Media_Electronics_Inc._USB_PnP_Sound_Device-00-Device"
        device.bus = "usb"
        device.vendor.id = "0d8c"
        device.vendor.name = "C-Media Electronics, Inc."
        device.product.id = "0139"
        device.product.name = "USB PnP Sound Device"
        device.serial = "C-Media_Electronics_Inc._USB_PnP_Sound_Device"
        device.string = "hw:1"
        device.buffering.buffer_size = "176400"
        device.buffering.fragment_size = "88200"
        device.access_mode = "mmap+timer"
        device.profile.name = "analog-mono"
        device.profile.description = "Analogue Mono"
        device.description = "USB PnP Sound Device Analogue Mono"
        alsa.mixer_name = "USB Mixer"
        alsa.components = "USB0d8c:0139"
        module-udev-detect.discovered = "1"
        device.icon_name = "audio-card-usb"
    Ports:
        analog-input-microphone: Microphone (priority: 8700)
    Active Port: analog-input-microphone
    Formats:
        pcm

Source #8
    State: SUSPENDED
    Name: alsa_output.usb-C-Media_Electronics_Inc._USB_PnP_Sound_Device-00-Device.analog-stereo.monitor
    Description: Monitor of USB PnP Sound Device Analogue Stereo
    Driver: module-alsa-card.c
    Sample Specification: s16le 2ch 44100Hz
    Channel Map: front-left,front-right
    Owner Module: 26
    Mute: no
    Volume: 0: 100% 1: 100%
            0: 0.00 dB 1: 0.00 dB
            balance 0.00
    Base Volume: 100%
                 0.00 dB
    Monitor of Sink: alsa_output.usb-C-Media_Electronics_Inc._USB_PnP_Sound_Device-00-Device.analog-stereo
    Latency: 0 usec, configured 0 usec
    Flags: DECIBEL_VOLUME LATENCY 
    Properties:
        device.description = "Monitor of USB PnP Sound Device Analogue Stereo"
        device.class = "monitor"
        alsa.card = "1"
        alsa.card_name = "USB PnP Sound Device"
        alsa.long_card_name = "C-Media Electronics Inc. USB PnP Sound Device at usb-0000:00:1d.2-2, full speed"
        alsa.driver_name = "snd_usb_audio"
        device.bus_path = "pci-0000:00:1d.2-usb-0:2:1.0"
        sysfs.path = "/devices/pci0000:00/0000:00:1d.2/usb7/7-2/7-2:1.0/sound/card1"
        udev.id = "usb-C-Media_Electronics_Inc._USB_PnP_Sound_Device-00-Device"
        device.bus = "usb"
        device.vendor.id = "0d8c"
        device.vendor.name = "C-Media Electronics, Inc."
        device.product.id = "0139"
        device.product.name = "USB PnP Sound Device"
        device.serial = "C-Media_Electronics_Inc._USB_PnP_Sound_Device"
        device.string = "1"
        module-udev-detect.discovered = "1"
        device.icon_name = "audio-card-usb"
    Formats:
        pcm
Seth
  • 58,122
Melvin Sowah
  • 367
  • 3
  • 10
  • Are you saying you try to record audio from the speakers? That is technically possible, in low quality, if the electronics support it; But probably not what you want. – Volker Siegel Sep 05 '14 at 12:49
  • Great! Thank you! At my case: pactl load-module module-loopback latency_msec=1 \ source=alsa_input.usb-Logitech_Logitech_USB_Headset-00-Headset.analog-mono \ sink=alsa_output.usb-Logitech_Logitech_USB_Headset-00-Headset.analog-stereo –  Sep 05 '14 at 11:59
  • related https://unix.stackexchange.com/questions/3490/how-can-i-record-the-sound-output-with-gtk-recordmydesktop – Ciro Santilli OurBigBook.com Oct 11 '20 at 19:37

3 Answers3

7
  • 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
      
user.dz
  • 48,105
  • 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 – user.dz Jan 26 '14 at 18:06
  • 1
    That didn't work: [pulse @ 0x81a63a0] pa_simple_new failed: Invalid argument alsa_output.usb-C-Media_Electronics_Inc._USB_PnP_Sound_Device-00-Device.analog-‌​stereo.monitor: Input/output error – Melvin Sowah Jan 26 '14 at 18:09
  • @Guilmon, I don't know. it works for me like that, I would like to ask typing by hand (avoid copy paste) last command i gave you and verify very well alsa_output.usb-C-Media_Electronics_Inc._USB_PnP_Sound_Device-00-Device.analog-‌​stereo.monitor no space in it. – user.dz Jan 26 '14 at 18:20
  • 1
    Something changed! I can now hear my system sounds but cannot hear the sound in the microphone... – Melvin Sowah Jan 26 '14 at 18:41
  • 1
    Thanks a lot, it works now! Thing is the microphone sound lags behind the video :/ oh well – Melvin Sowah Jan 26 '14 at 19:23
  • @Guilmon, Fixed by adding latency_msec=1 option to loopback module – user.dz Jan 30 '14 at 01:03
3

-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
xvan
  • 168
0

Note: this is a solution to record your desktop audio and mic audio at the same time, without any regard to the specific problem posted.

Anyways, been pulling my hair out forever googling for an answer that isn't needlessly complicated.

Install and use Open Broadcaster Software (OBS). Seriously, that's it. Googling it should bring up installation instructions tailored to your machine.

Just record with OBS and it will just make a video with your audio. If you only want to record audio, just record without a video source and it will make a blank video with your recording.

(Note this gives you a video file. It doesn't bother me but if you need an audio file like an mp3 you would have to figure out how to convert the video file you made into an audio file (plenty of resources out there to do this).)