Is there an easy way to capture audio during a screen recording with ffmpeg?

Trenix25

Active Member
Joined
Aug 15, 2017
Messages
163
Reaction score
66
Credits
1,421
I am able to use ffmpeg to capture a screen video and have read the docs for ffmpeg and elsewhere online, but I'm still trying to find a way to capture the audio from the audio output port of the computer with ffmpeg, not the audio input from a microphone, while capturing the screen video. Is there an easy way to do this without having to cross connect the physical connections? I suppose I could use an audio splitter to pass the audio output to the external speakers and the audio input, but that would involve a little external wiring. I have tried to use what the docs say, but it doesn't work. I am using Debian Linux 11.7 and PulseAudio.

This is what I'm currently using to capture just the video part:

Code:
#!/bin/bash
#
# Captures a screen recording.

if [ -z "$1" ] || [ -z "$2" ]; then
     echo "Usage cap <output frame rate> <filename.ext>"
     echo "The type of video file will be determined by the extension."
     exit 1
fi

# Using 15 fps should be sufficient for a tutorial video.

# These values were tested and proven using a .vob video file.

# BITRATE 15M for 5-15 fps
# BITRATE 16M for 20-30 fps

BITRATE="16M"

# BUFSIZE 10M for 5-30 fps

BUFSIZE="10M"

FRAMERATE="$1"

# PROBESIZE 15M for 5-30 fps

PROBESIZE="30M"

PROG="/usr/bin/ffmpeg"
SYNC="/usr/bin/sync"

"$PROG" -f x11grab -r 60 -probesize "$PROBESIZE" -video_size 1920x1200 -i :0.0 -r "$FRAMERATE" -b:v "$BITRATE" -minrate "$BITRATE" -maxrate "$BITRATE" -bufsize "$BUFSIZE" "$2"

"$SYNC"

exit 0

# EOF

My monitor uses 1920x1200@60 fps. I am using an Intel i5 quad-core CPU running at 3.4 GHz. I have 16 GB of physical RAM.

I'd like to be able to record the audio from an existing local video as it is playing. I will also need to be able to record audio from a microphone input too so I can make tutorial videos.

Signed,

Matthew Campbell
 


Something like this should capture your entire desktop and your PCs main audio out:
Bash:
ffmpeg -video_size 1920x1200 -framerate 25 -f x11grab -i :0.0 -f alsa -ac 2 -i hw:0 output.mp4
So if you’re recording your desktop whilst playing a video too, you should be able to see and hear the video.

The only problem then is adding your microphone as an extra audio input.

EDIT: Actually, I think the command I’ve posted will capture video and audio from the built in microphone, if it even works at all!
It was untested and completely off the top of my head!

I’ll have to have a play with ffmpeg when I get some free time. It probably won’t be this week though, because I have a big gig coming up with one of my bands this weekend.
 
Last edited:
Something like this should capture your entire desktop and your PCs main audio out:
Bash:
ffmpeg -video_size 1920x1200 -framerate 25 -f x11grab -i :0.0 -f alsa -ac 2 -i hw:0 output.mp4
So if you’re recording your desktop whilst playing a video too, you should be able to see and hear the video.

The only problem then is adding your microphone as an extra audio input.

EDIT: Actually, I think the command I’ve posted will capture video and audio from the built in microphone, if it even works at all!
It was untested and completely off the top of my head!

I’ll have to have a play with ffmpeg when I get some free time. It probably won’t be this week though, because I have a big gig coming up with one of my bands this weekend.
I'll try it out when I get the chance. Thanks.

Signed,

Matthew Campbell
 

Members online


Top