-
Notifications
You must be signed in to change notification settings - Fork 57
/
screen-record.sh
executable file
·85 lines (67 loc) · 2.4 KB
/
screen-record.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
TAG="screen-record ---> "
OUTPUT_DIR="./screen-record/"
MP4_POSTFIX=".mp4"
GIF_POSTFIX=".gif"
fileName=$1
# [Required] Get gif $fileName from 1st arg: . Or else do nothing.
if [ "$fileName" != "" ]
then
echo -e "$TAG specify fileName: $fileName\n"
mobilePath="/sdcard/$fileName"
pcPath="$OUTPUT_DIR$fileName"
# [Optional] Get gif $size from 2nd arg: . default size: "240x400".
size="240x400"
if [ "$2" != "" ]
then
size=$2
echo -e "$TAG specify size: $size\n"
fi
# [Optional] Get gif $time from 3rd arg. default time: 8s.
time=8
if [ "$3" != "" ]
then
time=$3
echo -e "$TAG specify limited time: $time\n"
fi
# [Optional] Get $ffmpegPath from 4th arg. default ffmpegPath: "ffmpeg".
ffmpegPath="ffmpeg"
if [ "$4" != "" ]
then
ffmpegPath=$4
echo -e "$TAG specify ffmpegPath: $ffmpegPath\n"
fi
# Make output dir if absent.
chmod 777 ./mkdir-if-absent.sh
./mkdir-if-absent.sh $OUTPUT_DIR
# Execute cmd screenrecord and then you get a video (XXX.mp4) in your sdcard.
echo -e "$TAG begin screenrecord\n"
adb shell screenrecord "$mobilePath$MP4_POSTFIX" --time-limit $time
echo -e "$TAG end screenrecord\n"
# Upload the video into OUTPUT_DIR of your PC .
adb pull "$mobilePath$MP4_POSTFIX" "$pcPath$MP4_POSTFIX"
# Remove target gif if exists
if [ -f "$pcPath$GIF_POSTFIX" ]; then
rm "$pcPath$GIF_POSTFIX"
fi
# Convert the video (XXX.mp4) to a gif (XXX.gif).
$ffmpegPath -r 20 -i "$pcPath$MP4_POSTFIX" -s $size -b:v 1500k "$pcPath$GIF_POSTFIX"
if [ $? -eq 0 ]; then
# Delete the redundant file (XXX.mp4).
rm "$pcPath$MP4_POSTFIX"
else
echo -e "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
echo -e "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
echo -e "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
echo -e "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
echo -e "$TAG ffmpegPath not found!!!\n"
echo -e "Make sure you have installed ffmpeg!\n"
echo -e "Please specify the ffmpegPath by \"FFMPEG_PATH=XXX\" in gradle.properties.\n"
echo -e "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
echo -e "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
echo -e "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
echo -e "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
exit 1
fi
else
echo -e "$TAG PARAM ERROR! Please specify a fileName (without postfix)!\n"
fi