Last active
April 20, 2024 08:06
-
-
Save fabiolimace/bc578dfb0a63ad0c7606b65908b50919 to your computer and use it in GitHub Desktop.
Record system output audio with FFMPEG on Ubuntu Linux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/bash | |
# | |
# Records the oudio from your browser and other applications. | |
# | |
# USAGE: | |
# | |
# record-system-output-audio.sh DURATION | |
# | |
# Where DURATION is [<HH>:]<MM>:<SS> or <SS>[s] (read ffmpeg-utils manual) | |
# | |
# Recording advices: | |
# 1. Dont open more play more than one video/audio during recordings. | |
# 2. Dont change the system volume during recordings. | |
# | |
# Read: | |
# Recording Browser Audio on Linux with ffmpeg, by Lubos Rendek | |
# https://linuxconfig.org/recording-browser-audio-on-linux-with-ffmpeg | |
# | |
duration="${1:-0}" | |
filename=`date +'%F_%T'`; | |
output="$filename.wav"; | |
monitor=`pactl list sinks | grep $(pactl get-default-sink).monitor | cut -d : -f 2`; | |
record="ffmpeg -loglevel error -t $duration -f pulse -i $monitor $output"; | |
if [[ -n "$monitor" ]]; then | |
echo "---------------" | |
echo "Recording advices:" | |
echo "1. Dont play more than one video/audio during recordings." | |
echo "2. Dont change the system volume during recordings." | |
echo "---------------" | |
echo $record && time $record; | |
else | |
echo "Pulse monitor not found."; | |
exit 1; | |
fi; | |
# Programmer notes: | |
# 1. dont use dots in $filename. Otherwise: "file.name.wav: Protocol not found". | |
# 2. dont use quotes around $monitor. Otherwise: "alsa.monitor: No such process". | |
# 3. dont change de wav extension. Otherwise you'll only hear noise in the output file. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment