3

I am trying to capture video and audio from the screen, loudspeakers and microphone. I would like to do that with a command-line command.

So far,

ffmpeg -f x11grab -r 25 -s 800x600 -i :0.0 /tmp/outputFile.mpg

records video, and

ffmpeg -f alsa -ac 2 -i pulse -acodec libmp3lame -ab 128k ~/Videos/outpulse.mp3

records the audio of the microphone.

Both commands can be combined in:

ffmpeg -f x11grab -r 25 -s 800x600 -i :0.0 -f alsa -ac 2 -i pulse -acodec libmp3lame -ab 128k /tmp/outputFile.mpg

which records the screen and the microphone in the same file. This can be useful for tutorials.

How can I adapt the command above to record from the loudspeakers? Or to record microphone + loudspeaker at the same time? For example for a VoIP session. Obviously, the audio from the loudspeakers gets taped by the microphone, but that results in a very poor sound quality.

avconv options are also welcome, but I don't want any tool that's not standard in Linux, GUI based, or not in the repositories.

1

If you are willing to switch to pulseaudio, a script like this will work:

#!/usr/bin/bash

# video information
INRES="1920x1080"                   
OUTRES="1280x720"
FPS="24"  
QUAL="fast"                                 
FILE_OUT="$1"

#audio information
PULSE_IN="alsa_input.pci-0000_00_1b.0.analog-stereo"
PULSE_OUT="alsa_output.pci-0000_00_1b.0.analog-stereo.monitor"

ffmpeg -f x11grab -s "$INRES" -r "$FPS" -i :0.0 \
    -f pulse -i "$PULSE_IN" -f pulse -i "$PULSE_OUT" \
    -filter_complex amerge \
    -vcodec libx264 -crf 30 -preset "$QUAL" -s "$OUTRES" \
    -acodec libmp3lame -ab 96k -ar 44100 -threads 4 -pix_fmt yuv420p \
    -f flv "$FILE_OUT"

The $PULSE_IN and $PULSE_OUT vars are the names of the input (microphone) source and the output (speaker) monitor source. Pulseaudio has things called "monitor sources" that allow you to record the loudspeaker output. You can find the names of the sources with the command pactl list sources | grep 'Name:'

Unfortunately I'm not sure how to enable a stereo mix source in pure alsa, so pulse is probably your best bet.

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.