Ffmpeg Record Selection of Screen
1 min read
July 22, 2023
118 words
Preface
Depends: slop ffmpeg
Here's a script I wrote that lets you select a window or portion of the screen and record it. It uses the ultrafast libx264 video codec to reduce resource consumption. Audio bitrate is capped at 128kb/s and the video is scaled to 720p to further conserve resourse usage.
#!/bin/sh
# Depends: slop ffmpeg
# Records the selected part of the screen
output="$1"
dimensions=$(slop 2>/dev/null)
size=$(echo "$dimensions" | sed 's/+.*//')
offset=$(echo "$dimensions" | cut -d'+' -f2- | sed 's/+/,/g')
[ -z "$output" ] && output="output"
ffmpeg -video_size "$size" \
-framerate 25 \
-f x11grab -i :0.0+"${offset}" \
-crf 28 \
-b:a 128k \
-c:v libx264 -preset ultrafast \
-c:a acc \
-vf scale=-2:720,format=yuv420p \
"$output.mp4"