Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Captures screen from Android device via ADB and makes a 180x320 GIF
#!/bin/bash
# How to install:
# exo-open "http://developer.android.com/sdk/index.html#Other"
# sudo apt-get install libav-tools imagemagick
# wget https://gist.githubusercontent.com/lorenzos/e8a97c1992cddf9c1142/raw/android-screen-to-gif.sh
# chmod a+x android-screen-to-gif.sh
# Help message
function usage() {
cat << EOF
Captures screen from Android device via ADB and converts it to a 180x320 GIF.
Usage: ./android-screen-to-gif.sh output.gif
EOF
}
# Output file
if [[ ! "$1" ]]; then
usage
exit 1
fi
TMP_MP4="/tmp/android-screen-tmp.mp4"
TMP_FRAMES_DIR="/tmp/android-screen-tmp-frames"
TMP_GIF="/tmp/android-screen-tmp.gif"
# Cleanup
rm -f "$TMP_MP4"
rm -rf "$TMP_FRAMES_DIR"
rm -f "$TMP_GIF"
# Record and pull video
echo "Starting recording, press CTRL+C when you're done..."
trap "echo 'Recording stopped, downloading output...'" INT
adb shell screenrecord --verbose "/sdcard/tmp-android-screen.mp4"
trap - INT
sleep 5
adb pull "/sdcard/tmp-android-screen.mp4" "$TMP_MP4"
sleep 1
adb shell rm "/sdcard/tmp-android-screen.mp4"
# Create frames
echo "Extracting frames..."
mkdir -p "$TMP_FRAMES_DIR"
avconv -i "$TMP_MP4" -pix_fmt rgb24 -s 180x320 "$TMP_FRAMES_DIR/%03d.png"
# Convert to GIF
echo "Converting to GIF..."
convert -loop 0 "$TMP_FRAMES_DIR/*.png" "$TMP_GIF"
convert -layers Optimize "$TMP_GIF" "$1"
exit 0
@ar-g

This comment has been minimized.

Copy link

commented Jan 2, 2016

for mac users
brew install libav

@alekseykarpenko

This comment has been minimized.

Copy link

commented Mar 13, 2017

@ar-g
also brew install imagemagick to support convert

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.