Skip to content

Instantly share code, notes, and snippets.

@fdoyle
Created May 7, 2014 20:27
Show Gist options
  • Save fdoyle/588ccaff9df3ad79d351 to your computer and use it in GitHub Desktop.
Save fdoyle/588ccaff9df3ad79d351 to your computer and use it in GitHub Desktop.
#!/bin/bash
VIDEO_LENGTH="10"
VIDEO_NAME="gifme.mp4"
GIF_NAME="gifme.gif"
GIF_OPTIMIZED_NAME="gifme-optimized.gif"
VIDEO_PATH="/sdcard/"$VIDEO_NAME
LOCAL_VIDEO_PATH="./"$VIDEO_NAME
IMGUR_HEADER="\"Authorization:Client-id ddc213b38452760\""
IMGUR_URL="https://api.imgur.com/3/upload"
echo "Gifme"
echo "Recording Video..."
RESULT=$(adb shell screenrecord --time-limit 10 $VIDEO_PATH)
echo "Copying from device..."
RESULT=$(adb pull $VIDEO_PATH $LOCAL_VIDEO_PATH)
echo "Removing from device..."
RESULT=$(adb shell rm $VIDEO_PATH)
echo "Converting to gif..."
RESULT=$(ffmpeg -loglevel panic -i $VIDEO_NAME -vf scale=320:-1 -t $VIDEO_LENGTH -r 10 -pix_fmt rgb24 $GIF_NAME)
echo "Removing Video..."
RESULT=$(rm $LOCAL_VIDEO_PATH)
echo "Optimizing gif..."
RESULT=$(convert -layers Optimize $GIF_NAME $GIF_OPTIMIZED_NAME)
echo "Removing unoptimized gif..."
RESULT=$(rm $GIF_NAME)
echo "Uploading gif..."
RESULT=$(curl --form "image=@"$GIF_OPTIMIZED_NAME --header "Authorization:Client-id ddc213b38452760" $IMGUR_URL)
RESULT=$(echo $RESULT | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["data"]["link"];')
rm $GIF_OPTIMIZED_NAME
echo "Final url: "$RESULT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment