Skip to content

Commit 81af404

Browse files
rikixu(胥敏)gb112211
authored andcommitted
modify screenrecord.py
1 parent 4a2dd9b commit 81af404

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ Android测试中常用到的脚本
77

88
批量安装应用(支持以中文命名的 apk)、批量卸载、截屏、录制视频、获取当前应用的 apk 文件、包名、Activity 名等。<br>
99

10+
### 2018.05.01
11+
修改 `screenrecord.py` ,原有脚本有时候会出现录制完的视频在 pull 到本地的时候卡死。修改后的脚本需要输入录制时间。
1012

11-
### 2016.7.19
13+
14+
### 2016.07.19
1215
增加部分python脚本对多设备的支持:
1316

1417
![device_id](image/device_id.png)

python/screenrecord.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,25 @@
1414

1515
from scriptUtils import utils
1616

17-
#需要Android4.4及4.4以上版本,运行脚本后可录制设备上的操作,默认使用手机分辨率,时间3min。手动按Enter结束录制
17+
#需要Android4.4及4.4以上版本,运行脚本后可录制设备上的操作,默认使用手机分辨率,手动设置录制时间
1818
#录制结果存放于当前目录下的video目录下
1919

2020
PATH = lambda p: os.path.abspath(p)
2121

2222
def record():
23-
utils.shell("screenrecord /data/local/tmp/video.mp4")
24-
input_key = raw_input("Please press the Enter key to stop recording:\n")
25-
if input_key == "":
26-
utils.adb("kill-server")
27-
28-
print "Get Video file..."
29-
utils.adb("start-server")
30-
time.sleep(1.5)
31-
32-
path = PATH("%s/video" %os.getcwd())
33-
if not os.path.isdir(path):
34-
os.makedirs(path)
35-
36-
utils.adb("pull /data/local/tmp/video.mp4 %s" %PATH("%s/%s.mp4" %(path, utils.timestamp()))).wait()
23+
utils.shell("rm -f /data/local/tmp/video.mp4")
24+
limit_time = raw_input("Please set the maximum recording time, in seconds. Maximum is 180.\n")
25+
if limit_time == "":
26+
utils.shell("screenrecord --time-limit 180 /data/local/tmp/video.mp4")
27+
try:
28+
_limit_time = int(limit_time) + 1
29+
except:
30+
record()
31+
if 0 < _limit_time <= 180:
32+
utils.shell("screenrecord --time-limit %s /data/local/tmp/video.mp4" %limit_time).wait()
33+
else:
34+
print "Please set again!"
35+
record()
3736

3837
if __name__ == "__main__":
3938
sdk = string.atoi(utils.shell("getprop ro.build.version.sdk").stdout.read())
@@ -42,4 +41,12 @@ def record():
4241
sys.exit(0)
4342
else:
4443
record()
44+
print "Get Video file..."
45+
time.sleep(3)
46+
47+
path = PATH("%s/video" %os.getcwd())
48+
if not os.path.isdir(path):
49+
os.makedirs(path)
50+
51+
os.popen("adb pull /data/local/tmp/video.mp4 %s" %PATH("%s/%s.mp4" %(path, utils.timestamp())))
4552
print "Completed"

0 commit comments

Comments
 (0)