Skip to content

Instantly share code, notes, and snippets.

@mirland
Created April 30, 2020 18:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mirland/18411a82ba63a334f7b4e41e804b2e67 to your computer and use it in GitHub Desktop.
Save mirland/18411a82ba63a334f7b4e41e804b2e67 to your computer and use it in GitHub Desktop.
Record a video from an android device
video2gif() {
ffmpeg -y -i "${1}" -vf fps=${3:-10},scale=${2:-320}:-1:flags=lanczos,palettegen "${1}.png"
ffmpeg -i "${1}" -i "${1}.png" -filter_complex "fps=${3:-10},scale=${2:-320}:-1:flags=lanczos[x];[x][1:v]paletteuse" "${1}".gif
rm "${1}.png"
}
record_gif() {
if [ -z "$1" ]; then
VIDEO_NAME=$(date +%F_%H-%M-%S)
else
VIDEO_NAME="$1"
fi
adb shell rm /sdcard/record_gif.mp4 2> /dev/null
adb shell screenrecord /sdcard/record_gif.mp4 &
pid=$!
echo "Start Recording $VIDEO_NAME.mp4 process $pid"
read -rsn1 -p "Press any key to finish the video"
echo -e "\nStoping video recording"
kill -2 $pid &> /dev/null
sleep 1
# Change permissions if needed
adb pull /sdcard/record_gif.mp4 > /dev/null
cp record_gif.mp4 "$VIDEO_NAME.mp4"
rm -f record_gif.mp4
adb shell rm /sdcard/record_gif.mp4
video2gif "$VIDEO_NAME.mp4" 270 15 2> /dev/null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment