OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | |
3 # | |
4 # Use of this source code is governed by a BSD-style license | |
5 # that can be found in the LICENSE file in the root of the source | |
6 # tree. An additional intellectual property rights grant can be found | |
7 # in the file PATENTS. All contributing project authors may | |
8 # be found in the AUTHORS file in the root of the source tree. | |
9 | |
10 """ | |
11 This script is the wrapper that starts a loopback call with stubbed video in | |
12 and out. It then analyses the video quality of the output video against the | |
13 reference input video. | |
14 | |
15 It expect to be given the webrtc output build directory as the first argument | |
16 all other arguments are optional. | |
17 | |
18 It assumes you have a Android device plugged in and that you have installed | |
19 AppRTCMobile.apk and AppRTCMobileTestStubbedVideoIO.apk on the device. | |
kjellander_webrtc
2017/01/20 08:18:56
These don't need to be installed, it will be taken
mandermo
2017/01/23 09:09:30
Ok, have removed that from the help text.
| |
20 """ | |
21 | |
22 import argparse | |
23 import os | |
24 import shutil | |
25 import subprocess | |
26 import sys | |
27 import tempfile | |
28 | |
29 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | |
30 | |
31 SRC_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, os.pardir, os.pardir)) | |
32 | |
33 | |
34 def _ParseArgs(): | |
35 parser = argparse.ArgumentParser(description='Start loopback video analysis') | |
36 parser.add_argument('--source_dir', | |
37 default=SRC_DIR, help='The path to the WebRTC source directory') | |
38 parser.add_argument('build_dir_android', | |
39 help='The path to the build directory for Android') | |
40 parser.add_argument('--build_dir_x86', | |
41 help='The path to the build directory for building locally') | |
42 parser.add_argument('--temp_dir', | |
43 help='A temporary directory to put the output') | |
44 | |
45 args = parser.parse_args() | |
46 return args | |
47 | |
48 | |
49 def main(): | |
50 args = _ParseArgs() | |
51 | |
52 source_dir = args.source_dir | |
53 build_dir_android = args.build_dir_android | |
54 build_dir_x86 = args.build_dir_x86 | |
55 temp_dir = args.temp_dir | |
56 if not temp_dir: | |
57 temp_dir = tempfile.mkdtemp() | |
58 else: | |
59 if not os.path.exists(temp_dir): | |
60 os.makedirs(temp_dir) | |
61 | |
62 if not build_dir_x86: | |
63 build_dir_x86 = os.path.join(temp_dir, 'LocalBuild') | |
64 subprocess.check_call(['gn', 'gen', build_dir_x86]) | |
kjellander_webrtc
2017/01/20 08:18:56
It'll be hard to debug what's going on if a comman
mandermo
2017/01/23 09:09:30
Done. Where is best to call logging.basicConfig(le
kjellander_webrtc
2017/01/23 10:31:47
You can do it anywhere as long as it executes befo
mandermo
2017/01/23 12:54:55
Moved to top of main().
| |
65 subprocess.check_call(['ninja', '-C', build_dir_x86, 'frame_analyzer']) | |
66 | |
67 toolchain_dir = os.path.join(source_dir, 'tools-webrtc', | |
68 'video_quality_toolchain') | |
69 | |
70 # Download ffmpeg and zxing. | |
71 download_script = os.path.join(toolchain_dir, 'download.py') | |
72 subprocess.check_call([download_script]) | |
73 | |
74 # Run the Espresso code. | |
75 espresso_target = os.path.join(build_dir_android, | |
76 'bin', 'run_AppRTCMobileTestStubbedVideoIO') | |
77 subprocess.check_call([espresso_target]) | |
78 | |
79 # Pull the output video. | |
80 test_video = os.path.join(temp_dir, 'test_video.y4m') | |
81 subprocess.check_call(['adb', 'pull', '/sdcard/output.y4m', test_video]) | |
82 | |
83 test_video_yuv = os.path.join(temp_dir, 'test_video.yuv') | |
84 | |
85 ffmpeg_path = os.path.join(toolchain_dir, 'linux', 'ffmpeg') | |
86 | |
87 def convert_video(input_video, output_video): | |
88 subprocess.check_call([ffmpeg_path, '-y', '-i', input_video, output_video]) | |
89 | |
90 convert_video(test_video, test_video_yuv) | |
91 | |
92 reference_video = os.path.join(source_dir, | |
93 'resources', 'reference_video_640x360_30fps.y4m') | |
94 | |
95 reference_video_yuv = os.path.join(temp_dir, | |
96 'reference_video_640x360_30fps.yuv') | |
97 | |
98 convert_video(reference_video, reference_video_yuv) | |
99 | |
100 # Run compare script. | |
101 compare_script = os.path.join(source_dir, 'webrtc', 'tools', | |
102 'compare_videos.py') | |
103 zxing_path = os.path.join(toolchain_dir, 'linux', 'zxing') | |
104 | |
105 # The frame_analyzer binary should be built for local computer and not for | |
106 # Android | |
107 frame_analyzer = os.path.join(build_dir_x86, 'frame_analyzer') | |
108 | |
109 frame_width = 640 | |
110 frame_height = 360 | |
111 | |
112 stats_file_ref = os.path.join(temp_dir, 'stats_ref.txt') | |
113 stats_file_test = os.path.join(temp_dir, 'stats_test.txt') | |
114 | |
115 subprocess.check_call([ | |
116 compare_script, '--ref_video', reference_video_yuv, | |
117 '--test_video', test_video_yuv, '--yuv_frame_width', str(frame_width), | |
118 '--yuv_frame_height', str(frame_height), | |
119 '--stats_file_ref', stats_file_ref, | |
120 '--stats_file_test', stats_file_test, '--frame_analyzer', frame_analyzer, | |
121 '--ffmpeg_path', ffmpeg_path, '--zxing_path', zxing_path]) | |
122 | |
123 shutil.rmtree(temp_dir) | |
124 | |
125 | |
126 if __name__ == '__main__': | |
127 sys.exit(main()) | |
128 | |
OLD | NEW |