Skip to content

Instantly share code, notes, and snippets.

@pollux-
Forked from PaulKinlan/getdeviceart.sh
Created September 3, 2018 09:24
Show Gist options
  • Save pollux-/9e3ebefce9a746df0f79ecd9e6f1102c to your computer and use it in GitHub Desktop.
Save pollux-/9e3ebefce9a746df0f79ecd9e6f1102c to your computer and use it in GitHub Desktop.
Screen Record for Android
#! /bin/bash
mkdir -p ./backgrounds
function get_google_device_art {
local device=$1
# Get the Google Device backgrounds
curl "https://developer.android.com/distribute/marketing-tools/device-art-resources/$1/port_back.png" > "./backgrounds/$1_port_back.png"
curl "https://developer.android.com/distribute/marketing-tools/device-art-resources/$1/port_fore.png" > "./backgrounds/$1_port_fore.png"
curl "https://developer.android.com/distribute/marketing-tools/device-art-resources/$1/port_shadow.png" > "./backgrounds/$1_port_shadow.png"
}
get_google_device_art 'nexus_5x'
get_google_device_art 'nexus_6'
get_google_device_art 'nexus_6p'
get_google_device_art 'nexus_9'
get_google_device_art 'pixel'
get_google_device_art 'pixel_xl'
get_google_device_art 'pixel_2'
get_google_device_art 'pixel_2_xl'
if [ -z "$1" ]; then
shot_path=$(date +%Y-%m-%d-%H-%M-%S).mp4
else
shot_path="$*"
fi
ffmpeg="ffmpeg"
# Get the device id lower case it.
device=$(adb shell getprop ro.product.model | sed 's/ /_/g' | tr '[:upper:]' '[:lower:]')
background_frame="./backgrounds/${device}_port_back.png"
foreground_frame="./backgrounds/${device}_port_fore.png"
shadow_frame="./backgrounds/${device}_port_shadow.png"
trap ctrl_c INT
function ctrl_c() {
echo "** Trapped CTRL-C"
echo "** Downloading screencast"
sleep 2
adb shell am broadcast -a com.android.systemui.demo -e command exit
adb pull /sdcard/Movies/$shot_path .
echo "FFMPEG Location: ${ffmpeg}"
echo "Device frame location: ${frame}"
echo "Device foreground location: ${forground_frame}"
echo "Device background location: ${background_frame}"
echo "Device shadow location: ${shadow_frame}"
if [ -x $(which "$ffmpeg") ] && [ -e "$background_frame" ]
then
echo "Rendering images with background"
$ffmpeg -y \
-f lavfi \
-i color=c=white:s=3840x1800 \
-i $shadow_frame \
-i $background_frame \
-i $shot_path \
-i $foreground_frame \
-filter_complex "[1:v]scale=920:-1[shadow]; \
[2:v]scale=920:-1[frame]; \
[3:v]scale=720:-1[video]; \
[4:v]scale=920:-1[sheen]; \
[0:v][shadow]overlay=shortest=1:x=(main_w-overlay_w)/2:y=(main_h-overlay_h)/2[background]; \
[background][frame]overlay=x=(main_w-overlay_w)/2:y=(main_h-overlay_h)/2[phone]; \
[phone][video]overlay=x=(main_w-overlay_w)/2:y=(main_h-overlay_h)/2[merged]; \
[merged][sheen]overlay=x=(main_w-overlay_w)/2:y=(main_h-overlay_h)/2" $shot_path-frame.mp4
$ffmpeg -y -i $shot_path-frame.mp4 -vf fps=10,scale=320:-1:flags=lanczos,palettegen $shot_path-palette.png
$ffmpeg -i $shot_path-frame.mp4 -i $shot_path-palette.png -filter_complex "fps=30,scale=720:-1:flags=lanczos[x];[x][1:v]paletteuse" $shot_path.gif
fi
alldone
}
function setup() {
adb shell settings put global sysui_demo_allowed 1
adb shell am broadcast -a com.android.systemui.demo -e command network -e mobile show -e datatype lte -e level 4
adb shell am broadcast -a com.android.systemui.demo -e command battery -e level 100 -e plugged false
adb shell am broadcast -a com.android.systemui.demo -e command network -e wifi show -e level 4
# Tweak this if you want the clock to changed
adb shell am broadcast -a com.android.systemui.demo -e command clock -e hhmm 0440
# Remove this if you want notifications to be availalbe
adb shell am broadcast -a com.android.systemui.demo -e command notifications -e visible false
echo When finished, run: adb shell am broadcast -a com.android.systemui.demo -e command exit
}
function alldone() {
adb shell am broadcast -a com.android.systemui.demo -e command exit
}
setup
adb shell screenrecord --bit-rate 16000000 /sdcard/Movies/$shot_path
echo "Finished"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment