blob: 725b4c7241994126e8834eb1a48ca660e38c55ae [file] [log] [blame]
mandermoed582f72017-01-23 07:55:42 -08001#!/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"""
11This script is the wrapper that starts a loopback call with stubbed video in
12and out. It then analyses the video quality of the output video against the
13reference input video.
14
15It expect to be given the webrtc output build directory as the first argument
16all other arguments are optional.
17
18It assumes you have a Android device plugged in.
19"""
20
21import argparse
22import logging
23import os
24import shutil
25import subprocess
26import sys
27import tempfile
28
29
30SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
kjellander30292102017-02-09 01:05:54 -080031SRC_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, os.pardir, os.pardir,
32 os.pardir))
mandermoed582f72017-01-23 07:55:42 -080033
34
35def _RunCommand(argv, **kwargs):
36 logging.info('Running %r', argv)
37 subprocess.check_call(argv, **kwargs)
38
39
40def _ParseArgs():
41 parser = argparse.ArgumentParser(description='Start loopback video analysis.')
42 parser.add_argument('--source_dir', default=SRC_DIR,
kjellander30292102017-02-09 01:05:54 -080043 help='The path to the WebRTC source directory. Default: %(default)s.')
mandermoed582f72017-01-23 07:55:42 -080044 parser.add_argument('build_dir_android',
45 help='The path to the build directory for Android.')
46 parser.add_argument('--build_dir_x86',
47 help='The path to the build directory for building locally.')
48 parser.add_argument('--temp_dir',
49 help='A temporary directory to put the output.')
50
51 args = parser.parse_args()
52 return args
53
54
55def main():
56 logging.basicConfig(level=logging.INFO)
57
58 args = _ParseArgs()
59
60 source_dir = args.source_dir
61 build_dir_android = args.build_dir_android
62 build_dir_x86 = args.build_dir_x86
63 temp_dir = args.temp_dir
64 if not temp_dir:
65 temp_dir = tempfile.mkdtemp()
66 else:
67 if not os.path.exists(temp_dir):
68 os.makedirs(temp_dir)
69
70 if not build_dir_x86:
71 build_dir_x86 = os.path.join(temp_dir, 'LocalBuild')
72 _RunCommand(['gn', 'gen', build_dir_x86])
73 _RunCommand(['ninja', '-C', build_dir_x86, 'frame_analyzer'])
74
75 toolchain_dir = os.path.join(source_dir, 'tools-webrtc',
76 'video_quality_toolchain')
77
78 # Download ffmpeg and zxing.
79 download_script = os.path.join(toolchain_dir, 'download.py')
80 _RunCommand([sys.executable, download_script])
81
82 # Run the Espresso code.
83 test_script = os.path.join(build_dir_android,
84 'bin', 'run_AppRTCMobileTestStubbedVideoIO')
85 _RunCommand([sys.executable, test_script])
86
87 # Pull the output video.
88 test_video = os.path.join(temp_dir, 'test_video.y4m')
89 _RunCommand(['adb', 'pull', '/sdcard/output.y4m', test_video])
90
91 test_video_yuv = os.path.join(temp_dir, 'test_video.yuv')
92
93 ffmpeg_path = os.path.join(toolchain_dir, 'linux', 'ffmpeg')
94
95 def convert_video(input_video, output_video):
96 _RunCommand([ffmpeg_path, '-y', '-i', input_video, output_video])
97
98 convert_video(test_video, test_video_yuv)
99
100 reference_video = os.path.join(source_dir,
101 'resources', 'reference_video_640x360_30fps.y4m')
102
103 reference_video_yuv = os.path.join(temp_dir,
104 'reference_video_640x360_30fps.yuv')
105
106 convert_video(reference_video, reference_video_yuv)
107
108 # Run compare script.
109 compare_script = os.path.join(source_dir, 'webrtc', 'tools',
110 'compare_videos.py')
111 zxing_path = os.path.join(toolchain_dir, 'linux', 'zxing')
112
113 # The frame_analyzer binary should be built for local computer and not for
114 # Android
115 frame_analyzer = os.path.join(build_dir_x86, 'frame_analyzer')
116
117 frame_width = 640
118 frame_height = 360
119
120 stats_file_ref = os.path.join(temp_dir, 'stats_ref.txt')
121 stats_file_test = os.path.join(temp_dir, 'stats_test.txt')
122
123 _RunCommand([
124 sys.executable, compare_script, '--ref_video', reference_video_yuv,
125 '--test_video', test_video_yuv, '--yuv_frame_width', str(frame_width),
126 '--yuv_frame_height', str(frame_height),
127 '--stats_file_ref', stats_file_ref,
128 '--stats_file_test', stats_file_test, '--frame_analyzer', frame_analyzer,
129 '--ffmpeg_path', ffmpeg_path, '--zxing_path', zxing_path])
130
131 shutil.rmtree(temp_dir)
132
133
134if __name__ == '__main__':
135 sys.exit(main())
136