Skip to content

Instantly share code, notes, and snippets.

@yordanoweb
Created February 3, 2026 16:59
Show Gist options
  • Select an option

  • Save yordanoweb/2ef5bdb24674612cfe0a7f2e63294224 to your computer and use it in GitHub Desktop.

Select an option

Save yordanoweb/2ef5bdb24674612cfe0a7f2e63294224 to your computer and use it in GitHub Desktop.
Capture a Screen Region with ffmpeg

Capture a Screen Region with ffmpeg

Install the package slop for calculating the rectangle.

sudo apt install slop

Store in variables the region selected with mouse

read X Y W H < <(slop -f "%x %y %w %h")

Capture the region with ffmpeg

ffmpeg -f x11grab -video_size ${W}x${H} -framerate 30 -grab_x $X -grab_y $Y -i :0 -c:v libx264 -preset ultrafast -crf 18 -pix_fmt yuv420p "$HOME/Videos/output_$(date +%F_%H-%M-%S).mp4"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment