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

Trenix25

Well-Known Member
Joined
Aug 15, 2017
Messages
673
Reaction score
367
Credits
6,139
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
 
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
In this script, the -f pulse -ac 2 -i default part captures the audio from the default PulseAudio device. This should allow you to capture the audio output without needing to cross-connect physical connections

https://rmauro.dev/how-to-record-video-and-audio-with-ffmpeg-a-minimalist-approach/
(How to Record Video and Audio with FFmpeg:
A Minimalist Approach)

Give it a try and let me know how it works for you!

https://trac.ffmpeg.org/wiki/Capture/Desktop
(Capture/Desktop – FFmpeg)
 
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.
Your reply was thoughtful! you shared a practical approach to capturing both video and audio output.

Here's a way to include both the system audio and microphone input in your recording:
///Code:

Bash:
#!/bin/bash
#
# Captures a screen recording with system audio and microphone.

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

BITRATE="16M"
BUFSIZE="10M"
FRAMERATE="$1"
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" -f pulse -ac 2 -i default -f pulse -ac 2 -i alsa_input.pci-0000_00_1b.0.analog-stereo -filter_complex "[0:a][1:a]amerge=inputs=2[a]" -map 0:v -map "[a]" "$2"

"$SYNC"

exit 0

# EOF
//

In this script, the -f pulse -ac 2 -i default captures the system audio, and the -f pulse -ac 2 -i alsa_input.pci-0000_00_1b.0.analog-stereo captures the microphone input.
The -filter_complexge=inputs=2[a]"
part merges the two audio streams together.

Feel free to try this approach and see if it meets your needs.
 
In this script, the -f pulse -ac 2 -i default part captures the audio from the default PulseAudio device. This should allow you to capture the audio output without needing to cross-connect physical connectionshttps://trac.ffmpeg.org/wiki/Capture/Desktop "1"https://rmauro.dev/how-to-record-video-and-audio-with-ffmpeg-a-minimalist-approach/ "2".

Give it a try and let me know how it works for you!

trac.ffmpeg.org/wiki/Capture/Desktop (Capture/Desktop – FFmpeg)

rmauro.dev/how-to-record-video-and-audio-with-ffmpeg-a-minimalist-approach/
(How to Record Video and Audio with FFmpeg:
A Minimalist Approach)
I just loaded that page and there was nothing there, just a white screen.

Signed,

Matthew Campbell
 
Your reply was thoughtful! you shared a practical approach to capturing both video and audio output.

Here's a way to include both the system audio and microphone input in your recording:
///Code:

Bash:
#!/bin/bash
#
# Captures a screen recording with system audio and microphone.

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

BITRATE="16M"
BUFSIZE="10M"
FRAMERATE="$1"
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" -f pulse -ac 2 -i default -f pulse -ac 2 -i alsa_input.pci-0000_00_1b.0.analog-stereo -filter_complex "[0:a][1:a]amerge=inputs=2[a]" -map 0:v -map "[a]" "$2"

"$SYNC"

exit 0

# EOF
//

In this script, the -f pulse -ac 2 -i default captures the system audio, and the -f pulse -ac 2 -i alsa_input.pci-0000_00_1b.0.analog-stereo captures the microphone input.
The -filter_complexge=inputs=2[a]"
part merges the two audio streams together.

Feel free to try this approach and see if it meets your needs.
I would really want to keep the two audio sources separate, in two different audio streams.

Signed,

Matthew Campbell
 
I would really want to keep the two audio sources separate, in two different audio streams.

Signed,

Matthew Campbell
and encoding together also not source mixes/mixed/mixing? this is impossible. I think your sound card if have special mode or capable of that ffmpeg csn do this. normally not. or if your device have 2 sound device record it one by one but not mixes. maybe this possible

this is not possible. some phones. bcz. if record with 1 device 1 mic source. sounds is mşxed not separated. bcz input is 1. using AI or very special spatial device but this impossible.
and
second approach of un/possibility ı said other comments. 2 device in same device or diff device have. and record together but one of record sink ır source input other dev is record another voice. but this if available it is useless. bcz for example if you record separately but saved in same file how you listen this record separately/separate/d voice? . human ears have and separate very and many and vary voices but not this like type record.when ypu listen all of 2 mixes up in your head like s one voice or stereo joşmt like mono voice.

this is like a this thing.

for example let me explain.

you have one source to record.

but you must 2 isolated from voices to not mix or interfere by other sources/voices etc from outer.
2 rooms must have.
1 of room record 1
second room record second voice
mean elimine other voice but not mixes up.

then record one by one.

and you have must separated mean own itself earphone/speakarr to listen separately recorded voices to listenable separated recorded voices

you understood what I mean

maybe like that possible.

mean like sound studio.


also you if you mean two different audio stream mean. same sound record at the same time 2 file type record?

mean 1 sound but record at same time as a mp3 and flac?.


if say yes this is also useless.
bcz glac better all kf sound file type formats.
it uses losless record/saving.

when you save it if lossless in originally
you can convert it another audio format which you want.


sorry I am turkish boy.
my English maybe hard or easy to...
but very advanced talking to you.

or maybe last possibility maybe not.

you can open ffmpeg or another me not know app or cli etc.

opening in two Windows page/ 2 separated terminal page at same time and running code together.
1 save only 1
other save other voice.

save separately.

this is crazy idea.


what you made my mind about ideas.

woow I am flied now ..

with unique ideas , approaches and thoughts about to answered questions by me.
 
Last edited:
also you if you mean two different audio stream mean. same sound record at the same time 2 file type record?

mean 1 sound but record at same time as a mp3 and flac?.


if say yes this is also useless.
bcz glac better all kf sound file type formats.
it uses losless record/saving.

when you save it if lossless in originally
you can convert it another audio format which you want.


sorry I am turkish boy.
my English maybe hard or easy to...
but very advanced talking to you.
The idea is that I'd like to keep the system audio separate from the microphone audio, but still in the same output file. The output file for the screen video would have the video stream, the system audio stream, and the microphone audio stream. So the output file would have at least three streams.

Signed,

Matthew Campbell
 
The idea is that I'd like to keep the system audio separate from the microphone audio, but still in the same output file. The output file for the screen video would have the video stream, the system audio stream, and the microphone audio stream. So the output file would have at least three streams.

Signed,

Matthew Campbell
I combined all reply in one. and deleted other comments more. fixed url look at again to my long reply.
 
There is one input port for the microphone and another input port for the line audio, then another port for sound output.

Signed,

Matthew Campbell
 


Members online


Top