Skip to content

Instantly share code, notes, and snippets.

@b3niup
Last active August 29, 2015 14:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save b3niup/85fd5c6d97904e229555 to your computer and use it in GitHub Desktop.
Save b3niup/85fd5c6d97904e229555 to your computer and use it in GitHub Desktop.
Simple script to create gifs and screenshots (depends on out file extension) of selected part of the screen.
#!/bin/bash
#
# Author: Benedykt 'b3niup' Przybyło
# Date: 2015-07-02
#
# Required: curl, scrot, ffmpeg, ffcast (https://github.com/lolilolicon/FFcast)
#
# Simple script to create gifs and screenshots (depends on out file extension) of selected part of the screen.
#
readonly PROGNAME=$(basename $0)
readonly PROGDIR=$(readlink -m $(dirname $0))
readonly ARGS="$@"
readonly IMGUR_CLIENTID="" # register at https://api.imgur.com/oauth2/addclient
usage() {
cat <<- EOF
usage: $PROGNAME [options] <out>
OPTIONS
-d <n> - delay before screenshot/recording
-u - upload to imgur
Depending on out file extension animated gif or static image will be created from selected part of the screen.
EOF
exit 1
}
mkgif() {
local out=$1
local delay=${2:-10}
local tmp_avi=$(mktemp /tmp/outXXXXXXXXXX.avi)
ffcast -s % ffmpeg -y -f x11grab -show_region 1 \
-framerate 15 -video_size %s -i %D+%c -codec:v huffyuv \
-vf crop="iw-mod(iw\\,2):ih-mod(ih\\,2)" $tmp_avi
convert -set delay $delay -layers Optimize $tmp_avi $out
rm $tmp_avi
}
mkscreen() {
local out=$1
scrot -s $out
}
upload() {
local file=$1
local url
local deleteurl
local response
# upload the image
response=$(curl -H "Authorization: Client-ID $IMGUR_CLIENTID" \
-F "image=@$file" https://api.imgur.com/3/upload 2>/dev/null)
if [[ $(grep '"status":200' <<< $response) ]]; then
url=$(sed -e 's/.*"link":"\([^"]*\).*/\1/' -e 's/\\//g' <<< $response)
deleteurl=$(sed -e 's/.*"deletehash":"\([^"]*\).*/\1/' <<< $response)
deleteurl="http://imgur.com/delete/${deleteurl}"
echo "Direct link: $url"
echo "Delete page: $deleteurl"
else
echo $response
exit 3
fi
}
main() {
local o
local delay
local upload
while getopts ":d:u" o; do
case $o in
d)
delay=${OPTARG};;
u)
[[ -z $IMGUR_CLIENTID ]] && echo "You need to define IMGUR_CLIENTID && exit 2
upload=upload;;
esac
done
shift $((OPTIND-1))
local out=$1
[[ -z $out ]] && usage
set -e
case ${out#*.} in
gif)
mkgif $out $delay;;
png|jpg)
mkscreen $out;;
*)
usage;;
esac
[[ $upload ]] && upload $out
set +e
}
main $ARGS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment