-
-
Save paour/0e0454ea63cbe19e91ac to your computer and use it in GitHub Desktop.
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 -x | |
# How to install: | |
# exo-open "http://developer.android.com/sdk/index.html#Other" | |
# brew install libav-tools imagemagick ffmpeg | |
# wget https://gist.githubusercontent.com/paour/0e0454ea63cbe19e91ac/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 GIF. | |
Usage: ./android-screen-to-gif.sh output.gif [adb parameters] | |
EOF | |
} | |
# Output file | |
if [[ ! "$1" ]]; then | |
usage | |
exit 1 | |
fi | |
TMP_MP4="/tmp/android-screen-tmp.mp4" | |
TMP_PALETTE="/tmp/android-screen-tmp.png" | |
OUT_GIF=$1 | |
shift | |
echo $1 | |
echo "$@" | |
# Cleanup | |
rm -f "$TMP_MP4" "$TMP_PALETTE" | |
# 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" | |
# Convert to GIF | |
echo "Converting to GIF..." | |
FILTERS="fps=10,scale=640:-1:flags=lanczos" | |
ffmpeg -i $TMP_MP4 -vf "$FILTERS,palettegen" -y $TMP_PALETTE | |
ffmpeg -i $TMP_MP4 -i $TMP_PALETTE -lavfi "$FILTERS [x]; [x][1:v] paletteuse" -y $OUT_GIF | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment