Created
August 19, 2024 06:25
-
-
Save darko-mesaros/174922f1d88f8c644459c40058ccec1b to your computer and use it in GitHub Desktop.
A simple bash script to capture your screen in Linux using ffmpeg and slop
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
#!/bin/bash | |
# function that shows you how to use this tool | |
usage() { | |
echo "Usage $0 [-o outfile] [-d outdir] [-f fps]" | |
echo " -o: Specify the output file (default: screen_rec_<current_time_and_date>.mp4)" | |
echo " -d: Specify the output directory (default: ./)" | |
echo " -f: Specify the fps (default: 30)" | |
exit 1 | |
} | |
# defaults | |
output_file="screen_rec_$(date "+%Y-%m-%d-%H-%M-%S").mp4" | |
output_dir="./" | |
fps=30 | |
# command line parsing | |
while getopts "o:d:f:h" opt; do | |
case $opt in | |
o) output_file="$OPTARG" ;; | |
d) output_dir="$OPTARG" ;; | |
f) fps="$OPTARG" ;; | |
h) usage ;; | |
\?) usage ;; | |
esac | |
done | |
# check for trailing / at the and of directory path | |
if [[ $output_dir != */ ]] | |
then | |
output_dir=${output_dir}"/" | |
fi | |
output_path="${output_dir}${output_file}" | |
# get selected area | |
selected_area=$(slop -f "%x %y %w %h") | |
# extract the coordinates and dimensions from teh selected_area | |
read -r x y w h <<< "$selected_area" | |
echo "Recording started ..." | |
ffmpeg -f x11grab -framerate "$fps" -video_size "${w}x${h}" -i :0.0+"$x","$y" -c:v libx264 -preset ultrafast -crf 0 "$output_path" | |
echo "Recording saved as $output_path" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment