Skip to content

Instantly share code, notes, and snippets.

@THOUSAND-SKY
Last active February 14, 2024 00:37
Show Gist options
  • Save THOUSAND-SKY/1c8c1d12970bc0d8ce7d8893eb8969f5 to your computer and use it in GitHub Desktop.
Save THOUSAND-SKY/1c8c1d12970bc0d8ce7d8893eb8969f5 to your computer and use it in GitHub Desktop.
X11 screencast area->clipboard snippet
#!/usr/bin/env bash
if pgrep -f "ffmpeg.*\/tmp\/screencast\.webm"
then
pkill -f "ffmpeg.*\/tmp\/screencast\.webm"
exit
fi
rm /tmp/screencast.webm
rm /tmp/screencast.webp
geometry=$(slop -f "-video_size %wx%h -i :0.0+%x,%y")
# 4x speed
ffmpeg -f x11grab $geometry -framerate 25 -c:v libvpx -crf 10 -b:v 1M -filter:v "setpts=0.25*PTS" /tmp/screencast.webm
# if video is less than 5sec long, turn it into animated webp
duration="$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 /tmp/screencast.webm)"
duration=${duration%.*}
if [ "$duration" -lt 5 ]; then
ffmpeg -i /tmp/screencast.webm -loop 0 /tmp/screencast.webp
echo -n "file:///tmp/screencast.webp" | xclip -se c -t 'text/uri-list'
notify-send "webp copied to clipboard"
else
echo -n "file:///tmp/screencast.webm" | xclip -se c -t 'text/uri-list'
notify-send "webm copied to clipboard"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment