Skip to content

Instantly share code, notes, and snippets.

@lkorth
Created November 14, 2014 20:16
Show Gist options
  • Save lkorth/9146d6aabbe88cb529a6 to your computer and use it in GitHub Desktop.
Save lkorth/9146d6aabbe88cb529a6 to your computer and use it in GitHub Desktop.
Command line script to record a video of your screen on Android and convert it to a animated gif
function process_video {
# let Android finish the recording
sleep 5
# pull the video off the device
adb pull /sdcard/video-to-gif.mp4 .
adb shell rm /sdcard/video-to-gif.mp4
mkdir recorded-gifs
# convert video to images
mplayer -ao null -vo png:z=9:outdir=recorded-gifs video-to-gif.mp4
VIDEO=$?
cd recorded-gifs
# remove half the frames to speed up gif
for file in `find dir -type f | awk 'NR % 2 == 0'`; do
rm $file
done
# convert the pngs to gifs
mkdir gifs
sips -s format gif *.png --out gifs > /dev/null 2> /dev/null
CONVERT=$?
cd gifs
# create an animated gif
gifsicle --colors=256 --delay=0 --loopcount=0 --dither *.gif > recorded.gif
GIF=$?
# cleanup
mv recorded.gif ../../.
cd ../..
rm -rf recorded-gifs
# only delete the original video if everything was successful
if [ $VIDEO -eq 0 ] && [ $CONVERT -eq 0 ] && [ $GIF -eq 0 ]
then
rm -f video-to-gif.mp4
echo "Your gif has been saved to `pwd`/recorded.gif"
else
rm recorded.gif
echo "There was a problem creating your gif, your original video has been saved to `pwd`/video-to-gif.mp4"
fi
}
trap 'echo "\n Processing video now..."; process_video' SIGINT
echo 'Recording video, ctrl-c to stop recording'
adb shell screenrecord /sdcard/video-to-gif.mp4
@lkorth
Copy link
Author

lkorth commented Nov 14, 2014

Requires mplayer and gifsicle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment