Last active
March 12, 2025 14:16
-
-
Save lorenzos/e8a97c1992cddf9c1142 to your computer and use it in GitHub Desktop.
Captures screen from Android device via ADB and makes a 180x320 GIF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for mac users
brew install libav