Created
February 7, 2019 11:58
-
-
Save jbruchanov/373be69b87c73650df46bad5c8356a57 to your computer and use it in GitHub Desktop.
QA android screen recording script
This file contains hidden or 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 | |
hash adb &> /dev/null | |
if [ $? -eq 1 ]; then | |
echo "adb not found, please contact your favourite android dev for help" | |
exit 1 | |
fi | |
if [ -z ${HOME} ]; then | |
echo "HOME env var not set, please contact your favourite android dev for help" | |
exit 1 | |
fi | |
echo "Select video quality, 1 digit folowed by [ENTER]:" | |
echo "1) Normal quality (DEFAULT)" | |
echo "2) High quality" | |
echo "3) Full display resolution" | |
read -s -n 1 QUALITY | |
if [[ $QUALITY = "" ]]; then | |
QUALITY=1 | |
fi | |
echo | |
echo "Selected quality: $QUALITY" | |
echo | |
if [[ ! $QUALITY =~ ^[0-9]+$ ]] ; then | |
echo "Invalid input, use please only 1,2,3" | |
exit | |
fi | |
if ! ([ $QUALITY -eq 1 ] || [ $QUALITY -eq 2 ] || [ $QUALITY -eq 3 ]) ; then | |
echo "nOK" | |
fi | |
RES=`adb shell wm size | awk '{print $3}'` | |
RES_ARR=(${RES//x/ }) | |
DISP_WIDTH=${RES_ARR[0]} | |
DISP_HEIGHT=${RES_ARR[1]} | |
BITRATE=4000000 | |
while : | |
do | |
case $QUALITY in | |
1) | |
DISP_WIDTH=$((DISP_WIDTH / 3)) | |
DISP_HEIGHT=$((DISP_HEIGHT / 3)) | |
BITRATE=$((BITRATE / 4)) | |
break; | |
;; | |
2) | |
DISP_WIDTH=$((DISP_WIDTH / 2)) | |
DISP_HEIGHT=$((DISP_HEIGHT / 2)) | |
BITRATE=$((BITRATE / 3)) | |
break; | |
;; | |
3) | |
break; | |
;; | |
esac | |
done | |
FILE=`date "+%Y%m%d_%H%M%S"` | |
#start recording | |
adb shell screenrecord "/sdcard/android_$FILE.mp4 --size ${DISP_WIDTH}x${DISP_HEIGHT} --bit-rate $BITRATE" & > /dev/null 2>&1 | |
echo "Recording in process (max length is 3mins)... (press ANY key to stop)" | |
#wait until something is pressed | |
read -s -n 1 | |
#stop recording | |
ps -ef | grep '\d adb shell screenrecord' | awk '{print $2}' | xargs kill -1 2>&1 >/dev/null | |
#if we don't sleep, video is not readable, so i guess some race condition | |
sleep 0.5 | |
#pull file to desktop | |
TARGET_FILE=$HOME/Desktop/android_$FILE.mp4 | |
adb pull "/sdcard/android_$FILE.mp4" "$TARGET_FILE" 2>&1 >/dev/null | |
echo "Done, file:$TARGET_FILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment