Skip to content

Instantly share code, notes, and snippets.

@jrialland
Created July 28, 2016 13:54
Show Gist options
  • Select an option

  • Save jrialland/85da03a93e8df026d7e3e0d44c72cedf to your computer and use it in GitHub Desktop.

Select an option

Save jrialland/85da03a93e8df026d7e3e0d44c72cedf to your computer and use it in GitHub Desktop.
capture screen video from a running android device, and convert to animated gif (needs vlc and imagemagick)
#!/bin/bash
set -e
#ADB=`which adb`
ADB=$ANDROID_HOME/platform-tools/adb
TMPMP4=$(mktemp).mp4
TMPFILE=/sdcard/$(basename $TMPMP4)
$ADB -d shell screenrecord $TMPFILE &
PID=$!
echo pid=$PID
read -p "Press any key when done recording ..." -n1 -s
echo ... done
kill -15 $PID > /dev/null
sleep 2s
echo saving video to $TMPMP4 ...
$ADB -d pull $TMPFILE $TMPMP4
$ADB -d shell rm $TMPFILE
echo ... done
TMPDIR=`mktemp -d`
echo splitting video into frames ...
vlc --intf dummy "$TMPMP4" --rate=1 --video-filter=scene --vout=dummy --start-time=0 --scene-format=png --scene-ratio=5 --scene-prefix=snap --scene-path=$TMPDIR vlc://quit 2> /dev/null
echo ... done
echo assembling into animated gif ...
convert -delay 10 -loop 0 $TMPDIR/snap*.png $TMPDIR/animation_big.gif
echo ... done
echo optimizing gif ...
convert -layers Optimize $TMPDIR/animation_big.gif "android_capture.gif"
echo ... done
rm $TMPDIR -rf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment