blob: 35892bbe03d5ed363b9dbd42d15a4b7196863afd [file] [log] [blame]
jansson1b0e3b82017-03-13 02:15:51 -07001#!/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
Mirko Bonadei67f88a02019-07-25 18:38:54 +020010from __future__ import absolute_import
11from __future__ import division
12from __future__ import print_function
jansson80ff00c2017-04-11 07:40:26 -070013import glob
jansson1b0e3b82017-03-13 02:15:51 -070014import optparse
15import os
jansson80ff00c2017-04-11 07:40:26 -070016import shutil
jansson1b0e3b82017-03-13 02:15:51 -070017import subprocess
18import sys
19import time
jansson80ff00c2017-04-11 07:40:26 -070020
jansson1b0e3b82017-03-13 02:15:51 -070021
22# Used to time-stamp output files and directories
23CURRENT_TIME = time.strftime("%d_%m_%Y-%H:%M:%S")
24
jansson5c7a6232017-03-15 08:27:31 -070025
26class Error(Exception):
27 pass
28
29
30class FfmpegError(Error):
31 pass
32
33
34class MagewellError(Error):
35 pass
36
37
38class CompareVideosError(Error):
39 pass
40
41
jansson1b0e3b82017-03-13 02:15:51 -070042def _ParseArgs():
43 """Registers the command-line options."""
44 usage = 'usage: %prog [options]'
45 parser = optparse.OptionParser(usage=usage)
46
jansson9b932032017-06-02 02:16:27 -070047 parser.add_option('--frame_width', type='int', default=1280,
jansson1b0e3b82017-03-13 02:15:51 -070048 help='Width of the recording. Default: %default')
jansson9b932032017-06-02 02:16:27 -070049 parser.add_option('--frame_height', type='int', default=720,
jansson1b0e3b82017-03-13 02:15:51 -070050 help='Height of the recording. Default: %default')
jansson9b932032017-06-02 02:16:27 -070051 parser.add_option('--framerate', type='int', default=60,
jansson1b0e3b82017-03-13 02:15:51 -070052 help='Recording framerate. Default: %default')
jansson9b932032017-06-02 02:16:27 -070053 parser.add_option('--ref_duration', type='int', default=20,
jansson1b0e3b82017-03-13 02:15:51 -070054 help='Reference recording duration. Default: %default')
jansson9b932032017-06-02 02:16:27 -070055 parser.add_option('--test_duration', type='int', default=10,
jansson1b0e3b82017-03-13 02:15:51 -070056 help='Test recording duration. Default: %default')
jansson9b932032017-06-02 02:16:27 -070057 parser.add_option('--time_between_recordings', type='int', default=5,
jansson1b0e3b82017-03-13 02:15:51 -070058 help='Time between starting test recording after ref.'
59 'Default: %default')
60 parser.add_option('--ref_video_device', type='string', default='/dev/video0',
61 help='Reference recording device. Default: %default')
62 parser.add_option('--test_video_device', type='string', default='/dev/video1',
63 help='Test recording device. Default: %default')
64 parser.add_option('--app_name', type='string',
65 help='Name of the app under test.')
66 parser.add_option('--recording_api', type='string', default='Video4Linux2',
67 help='Recording API to use. Default: %default')
68 parser.add_option('--pixel_format', type='string', default='yuv420p',
69 help='Recording pixel format Default: %default')
70 parser.add_option('--ffmpeg', type='string',
71 help='Path to the ffmpeg executable for the reference '
72 'device.')
73 parser.add_option('--video_container', type='string', default='yuv',
74 help='Video container for the recordings.'
75 'Default: %default')
76 parser.add_option('--compare_videos_script', type='string',
77 default='compare_videos.py',
78 help='Path to script used to compare and generate metrics.'
79 'Default: %default')
80 parser.add_option('--frame_analyzer', type='string',
81 default='../../out/Default/frame_analyzer',
82 help='Path to the frame analyzer executable.'
83 'Default: %default')
84 parser.add_option('--zxing_path', type='string',
Magnus Jedvert165148d2018-10-22 22:19:20 +020085 help='DEPRECATED.')
jansson1b0e3b82017-03-13 02:15:51 -070086 parser.add_option('--ref_rec_dir', type='string', default='ref',
87 help='Path to where reference recordings will be created.'
88 'Ideally keep the ref and test directories on separate'
89 'drives. Default: %default')
90 parser.add_option('--test_rec_dir', type='string', default='test',
91 help='Path to where test recordings will be created.'
92 'Ideally keep the ref and test directories on separate '
93 'drives. Default: %default')
94 parser.add_option('--test_crop_parameters', type='string',
95 help='ffmpeg processing parameters for the test video.')
96 parser.add_option('--ref_crop_parameters', type='string',
97 help='ffmpeg processing parameters for the ref video.')
98
99 options, _ = parser.parse_args()
100
101 if not options.app_name:
102 parser.error('You must provide an application name!')
103
104 if not options.test_crop_parameters or not options.ref_crop_parameters:
105 parser.error('You must provide ref and test crop parameters!')
106
107 # Ensure the crop filter is included in the crop parameters used for ffmpeg.
108 if 'crop' not in options.ref_crop_parameters:
109 parser.error('You must provide a reference crop filter for ffmpeg.')
110 if 'crop' not in options.test_crop_parameters:
111 parser.error('You must provide a test crop filter for ffmpeg.')
112
113 if not options.ffmpeg:
114 parser.error('You most provide location for the ffmpeg executable.')
115 if not os.path.isfile(options.ffmpeg):
116 parser.error('Cannot find the ffmpeg executable.')
117
118 # compare_videos.py dependencies.
119 if not os.path.isfile(options.compare_videos_script):
120 parser.warning('Cannot find compare_videos.py script, no metrics will be '
121 'generated!')
122 if not os.path.isfile(options.frame_analyzer):
123 parser.warning('Cannot find frame_analyzer, no metrics will be generated!')
jansson1b0e3b82017-03-13 02:15:51 -0700124
125 return options
126
127
128def CreateRecordingDirs(options):
129 """Create root + sub directories for reference and test recordings.
130
131 Args:
132 options(object): Contains all the provided command line options.
jansson5c7a6232017-03-15 08:27:31 -0700133
134 Returns:
jansson1b0e3b82017-03-13 02:15:51 -0700135 record_paths(dict): key: value pair with reference and test file
136 absolute paths.
137 """
138
139 # Create root directories for the video recordings.
140 if not os.path.isdir(options.ref_rec_dir):
141 os.makedirs(options.ref_rec_dir)
142 if not os.path.isdir(options.test_rec_dir):
143 os.makedirs(options.test_rec_dir)
144
145 # Create and time-stamp directories for all the output files.
146 ref_rec_dir = os.path.join(options.ref_rec_dir, options.app_name + '_' + \
147 CURRENT_TIME)
148 test_rec_dir = os.path.join(options.test_rec_dir, options.app_name + '_' + \
149 CURRENT_TIME)
150
151 os.makedirs(ref_rec_dir)
152 os.makedirs(test_rec_dir)
153
154 record_paths = {
155 'ref_rec_location' : os.path.abspath(ref_rec_dir),
156 'test_rec_location' : os.path.abspath(test_rec_dir)
157 }
158
159 return record_paths
160
161
jansson80ff00c2017-04-11 07:40:26 -0700162def FindUsbPortForV4lDevices(ref_video_device, test_video_device):
163 """Tries to find the usb port for ref_video_device and test_video_device.
jansson1b0e3b82017-03-13 02:15:51 -0700164
165 Tries to find the provided ref_video_device and test_video_device devices
166 which use video4linux and then do a soft reset by using USB unbind and bind.
jansson80ff00c2017-04-11 07:40:26 -0700167
168 Args:
169 ref_device(string): reference recording device path.
170 test_device(string): test recording device path
171
172 Returns:
173 usb_ports(list): USB ports(string) for the devices found.
174 """
175
176 # Find the device location including USB and USB Bus ID's. Use the usb1
177 # in the path since the driver folder is a symlink which contains all the
178 # usb device port mappings and it's the same in all usbN folders. Tested
179 # on Ubuntu 14.04.
180 v4l_device_path = '/sys/bus/usb/devices/usb1/1-1/driver/**/**/video4linux/'
181 v4l_ref_device = glob.glob('%s%s' % (v4l_device_path, ref_video_device))
182 v4l_test_device = glob.glob('%s%s' % (v4l_device_path, test_video_device))
183 usb_ports = []
184 paths = []
185
186 # Split on the driver folder first since we are only interested in the
187 # folders thereafter.
jansson07e20db2017-04-12 01:36:02 -0700188 try:
189 ref_path = str(v4l_ref_device).split('driver')[1].split('/')
190 test_path = str(v4l_test_device).split('driver')[1].split('/')
191 except IndexError:
Mirko Bonadei67f88a02019-07-25 18:38:54 +0200192 print('Could not find one or both of the specified recording devices.')
jansson07e20db2017-04-12 01:36:02 -0700193 else:
194 paths.append(ref_path)
195 paths.append(test_path)
jansson80ff00c2017-04-11 07:40:26 -0700196
jansson07e20db2017-04-12 01:36:02 -0700197 for path in paths:
198 for usb_id in path:
199 # Look for : separator and then use the first element in the list.
200 # E.g 3-3.1:1.0 split on : and [0] becomes 3-3.1 which can be used
201 # for bind/unbind.
202 if ':' in usb_id:
203 usb_ports.append(usb_id.split(':')[0])
204
jansson80ff00c2017-04-11 07:40:26 -0700205 return usb_ports
206
207
208def RestartMagewellDevices(ref_video_device_path, test_video_device_path):
209 """Reset the USB ports where Magewell capture devices are connected to.
210
211 Performs a soft reset by using USB unbind and bind.
jansson1b0e3b82017-03-13 02:15:51 -0700212 This is due to Magewell capture devices have proven to be unstable after the
213 first recording attempt.
214
jansson80ff00c2017-04-11 07:40:26 -0700215 Args:
216 ref_video_device_path(string): reference recording device path.
217 test_video_device_path(string): test recording device path
jansson5c7a6232017-03-15 08:27:31 -0700218
219 Raises:
220 MagewellError: If no magewell devices are found.
jansson1b0e3b82017-03-13 02:15:51 -0700221 """
222
223 # Get the dev/videoN device name from the command line arguments.
jansson80ff00c2017-04-11 07:40:26 -0700224 ref_magewell_path = ref_video_device_path.split('/')[2]
225 test_magewell_path = test_video_device_path.split('/')[2]
226 magewell_usb_ports = FindUsbPortForV4lDevices(ref_magewell_path,
227 test_magewell_path)
jansson1b0e3b82017-03-13 02:15:51 -0700228
jansson5c7a6232017-03-15 08:27:31 -0700229 # Abort early if no devices are found.
230 if len(magewell_usb_ports) == 0:
231 raise MagewellError('No magewell devices found.')
232 else:
Mirko Bonadei67f88a02019-07-25 18:38:54 +0200233 print('\nResetting USB ports where magewell devices are connected...')
jansson5c7a6232017-03-15 08:27:31 -0700234 # Use the USB bus and port ID (e.g. 4-3) to unbind and bind the USB devices
235 # (i.e. soft eject and insert).
jansson1b0e3b82017-03-13 02:15:51 -0700236 for usb_port in magewell_usb_ports:
237 echo_cmd = ['echo', usb_port]
238 unbind_cmd = ['sudo', 'tee', '/sys/bus/usb/drivers/usb/unbind']
239 bind_cmd = ['sudo', 'tee', '/sys/bus/usb/drivers/usb/bind']
240
241 # TODO(jansson) Figure out a way to call on echo once for bind & unbind
242 # if possible.
243 echo_unbind = subprocess.Popen(echo_cmd, stdout=subprocess.PIPE)
244 unbind = subprocess.Popen(unbind_cmd, stdin=echo_unbind.stdout)
245 echo_unbind.stdout.close()
jansson1b0e3b82017-03-13 02:15:51 -0700246 unbind.wait()
247
248 echo_bind = subprocess.Popen(echo_cmd, stdout=subprocess.PIPE)
249 bind = subprocess.Popen(bind_cmd, stdin=echo_bind.stdout)
250 echo_bind.stdout.close()
jansson1b0e3b82017-03-13 02:15:51 -0700251 bind.wait()
jansson5c7a6232017-03-15 08:27:31 -0700252 if bind.returncode == 0:
Mirko Bonadei67f88a02019-07-25 18:38:54 +0200253 print('Reset done!\n')
jansson1b0e3b82017-03-13 02:15:51 -0700254
255
jansson5c7a6232017-03-15 08:27:31 -0700256def StartRecording(options, ref_file_location, test_file_location):
jansson1b0e3b82017-03-13 02:15:51 -0700257 """Starts recording from the two specified video devices.
258
259 Args:
260 options(object): Contains all the provided command line options.
261 record_paths(dict): key: value pair with reference and test file
262 absolute paths.
jansson5c7a6232017-03-15 08:27:31 -0700263
264 Returns:
265 recording_files_and_time(dict): key: value pair with the path to cropped
266 test and reference video files.
267
268 Raises:
269 FfmpegError: If the ffmpeg command fails.
jansson1b0e3b82017-03-13 02:15:51 -0700270 """
271 ref_file_name = '%s_%s_ref.%s' % (options.app_name, CURRENT_TIME,
272 options.video_container)
jansson5c7a6232017-03-15 08:27:31 -0700273 ref_file = os.path.join(ref_file_location, ref_file_name)
jansson1b0e3b82017-03-13 02:15:51 -0700274
275 test_file_name = '%s_%s_test.%s' % (options.app_name, CURRENT_TIME,
276 options.video_container)
jansson5c7a6232017-03-15 08:27:31 -0700277 test_file = os.path.join(test_file_location, test_file_name)
jansson1b0e3b82017-03-13 02:15:51 -0700278
279 # Reference video recorder command line.
280 ref_cmd = [
281 options.ffmpeg,
282 '-v', 'error',
jansson9b932032017-06-02 02:16:27 -0700283 '-s', '%dx%d' % (options.frame_width, options.frame_height),
284 '-r', '%d' % options.framerate,
285 '-f', '%s' % options.recording_api,
286 '-i', '%s' % options.ref_video_device,
287 '-pix_fmt', '%s' % options.pixel_format,
288 '-s', '%dx%d' % (options.frame_width, options.frame_height),
289 '-t', '%d' % options.ref_duration,
290 '-r', '%d' % options.framerate,
jansson5c7a6232017-03-15 08:27:31 -0700291 ref_file
jansson1b0e3b82017-03-13 02:15:51 -0700292 ]
293
294 # Test video recorder command line.
295 test_cmd = [
296 options.ffmpeg,
297 '-v', 'error',
jansson9b932032017-06-02 02:16:27 -0700298 '-s', '%dx%d' % (options.frame_width, options.frame_height),
299 '-r', '%d' % options.framerate,
300 '-f', '%s' % options.recording_api,
301 '-i', '%s' % options.test_video_device,
302 '-pix_fmt', '%s' % options.pixel_format,
303 '-s', '%dx%d' % (options.frame_width, options.frame_height),
304 '-t', '%d' % options.test_duration,
305 '-r', '%d' % options.framerate,
jansson5c7a6232017-03-15 08:27:31 -0700306 test_file
jansson1b0e3b82017-03-13 02:15:51 -0700307 ]
Mirko Bonadei67f88a02019-07-25 18:38:54 +0200308 print('Trying to record from reference recorder...')
jansson9b932032017-06-02 02:16:27 -0700309 ref_recorder = subprocess.Popen(ref_cmd)
jansson1b0e3b82017-03-13 02:15:51 -0700310
311 # Start the 2nd recording a little later to ensure the 1st one has started.
312 # TODO(jansson) Check that the ref_recorder output file exists rather than
313 # using sleep.
314 time.sleep(options.time_between_recordings)
Mirko Bonadei67f88a02019-07-25 18:38:54 +0200315 print('Trying to record from test recorder...')
jansson9b932032017-06-02 02:16:27 -0700316 test_recorder = subprocess.Popen(test_cmd)
jansson1b0e3b82017-03-13 02:15:51 -0700317 test_recorder.wait()
318 ref_recorder.wait()
319
320 # ffmpeg does not abort when it fails, need to check return code.
jansson5c7a6232017-03-15 08:27:31 -0700321 if ref_recorder.returncode != 0 or test_recorder.returncode != 0:
322 # Cleanup recording directories.
323 shutil.rmtree(ref_file_location)
324 shutil.rmtree(test_file_location)
325 raise FfmpegError('Recording failed, check ffmpeg output.')
326 else:
Mirko Bonadei67f88a02019-07-25 18:38:54 +0200327 print('Ref file recorded to: ' + os.path.abspath(ref_file))
328 print('Test file recorded to: ' + os.path.abspath(test_file))
329 print('Recording done!\n')
jansson5c7a6232017-03-15 08:27:31 -0700330 return FlipAndCropRecordings(options, test_file_name, test_file_location,
331 ref_file_name, ref_file_location)
jansson1b0e3b82017-03-13 02:15:51 -0700332
333
334def FlipAndCropRecordings(options, test_file_name, test_file_location,
335 ref_file_name, ref_file_location):
336 """Performs a horizontal flip of the reference video to match the test video.
337
338 This is done to the match orientation and then crops the ref and test videos
339 using the options.test_crop_parameters and options.ref_crop_parameters.
340
341 Args:
342 options(object): Contains all the provided command line options.
343 test_file_name(string): Name of the test video file recording.
344 test_file_location(string): Path to the test video file recording.
345 ref_file_name(string): Name of the reference video file recording.
346 ref_file_location(string): Path to the reference video file recording.
jansson5c7a6232017-03-15 08:27:31 -0700347
348 Returns:
jansson1b0e3b82017-03-13 02:15:51 -0700349 recording_files_and_time(dict): key: value pair with the path to cropped
350 test and reference video files.
jansson5c7a6232017-03-15 08:27:31 -0700351
352 Raises:
353 FfmpegError: If the ffmpeg command fails.
jansson1b0e3b82017-03-13 02:15:51 -0700354 """
Mirko Bonadei67f88a02019-07-25 18:38:54 +0200355 print('Trying to crop videos...')
jansson1b0e3b82017-03-13 02:15:51 -0700356
357 # Ref file cropping.
358 cropped_ref_file_name = 'cropped_' + ref_file_name
359 cropped_ref_file = os.path.abspath(
360 os.path.join(ref_file_location, cropped_ref_file_name))
361
362 ref_video_crop_cmd = [
363 options.ffmpeg,
364 '-v', 'error',
jansson9b932032017-06-02 02:16:27 -0700365 '-s', '%dx%d' % (options.frame_width, options.frame_height),
366 '-i', '%s' % os.path.join(ref_file_location, ref_file_name),
367 '-vf', '%s' % options.ref_crop_parameters,
jansson1b0e3b82017-03-13 02:15:51 -0700368 '-c:a', 'copy',
369 cropped_ref_file
370 ]
371
372 # Test file cropping.
373 cropped_test_file_name = 'cropped_' + test_file_name
374 cropped_test_file = os.path.abspath(
375 os.path.join(test_file_location, cropped_test_file_name))
376
377 test_video_crop_cmd = [
378 options.ffmpeg,
379 '-v', 'error',
jansson9b932032017-06-02 02:16:27 -0700380 '-s', '%dx%d' % (options.frame_width, options.frame_height),
381 '-i', '%s' % os.path.join(test_file_location, test_file_name),
382 '-vf', '%s' % options.test_crop_parameters,
jansson1b0e3b82017-03-13 02:15:51 -0700383 '-c:a', 'copy',
384 cropped_test_file
385 ]
386
387 ref_crop = subprocess.Popen(ref_video_crop_cmd)
388 ref_crop.wait()
jansson5c7a6232017-03-15 08:27:31 -0700389 test_crop = subprocess.Popen(test_video_crop_cmd)
390 test_crop.wait()
jansson1b0e3b82017-03-13 02:15:51 -0700391
jansson5c7a6232017-03-15 08:27:31 -0700392 # ffmpeg does not abort when it fails, need to check return code.
393 if ref_crop.returncode != 0 or test_crop.returncode != 0:
394 # Cleanup recording directories.
395 shutil.rmtree(ref_file_location)
396 shutil.rmtree(test_file_location)
397 raise FfmpegError('Cropping failed, check ffmpeg output.')
398 else:
Mirko Bonadei67f88a02019-07-25 18:38:54 +0200399 print('Ref file cropped to: ' + cropped_ref_file)
400 print('Test file cropped to: ' + cropped_test_file)
401 print('Cropping done!\n')
jansson1b0e3b82017-03-13 02:15:51 -0700402
403 # Need to return these so they can be used by other parts.
404 cropped_recordings = {
405 'cropped_test_file' : cropped_test_file,
406 'cropped_ref_file' : cropped_ref_file
407 }
jansson1b0e3b82017-03-13 02:15:51 -0700408 return cropped_recordings
jansson1b0e3b82017-03-13 02:15:51 -0700409
410
jansson5c7a6232017-03-15 08:27:31 -0700411def CompareVideos(options, cropped_ref_file, cropped_test_file):
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200412 """Runs the compare_video.py script from src/rtc_tools using path.
jansson1b0e3b82017-03-13 02:15:51 -0700413
414 Uses the path from recording_result and writes the output to a file named
415 <options.app_name + '_' + CURRENT_TIME + '_result.txt> in the reference video
416 recording folder taken from recording_result.
417
418 Args:
419 options(object): Contains all the provided command line options.
jansson5c7a6232017-03-15 08:27:31 -0700420 cropped_ref_file(string): Path to cropped reference video file.
421 cropped_test_file(string): Path to cropped test video file.
422
423 Raises:
424 CompareVideosError: If compare_videos.py fails.
jansson1b0e3b82017-03-13 02:15:51 -0700425 """
Mirko Bonadei67f88a02019-07-25 18:38:54 +0200426 print('Starting comparison...')
427 print('Grab a coffee, this might take a few minutes...')
jansson1b0e3b82017-03-13 02:15:51 -0700428 compare_videos_script = os.path.abspath(options.compare_videos_script)
429 rec_path = os.path.abspath(os.path.join(
jansson5c7a6232017-03-15 08:27:31 -0700430 os.path.dirname(cropped_test_file)))
jansson1b0e3b82017-03-13 02:15:51 -0700431 result_file_name = os.path.join(rec_path, '%s_%s_result.txt') % (
432 options.app_name, CURRENT_TIME)
433
Magnus Jedvert3e169ac2018-08-24 12:44:59 +0000434 # Find the crop dimensions (e.g. 950 and 420) in the ref crop parameter
435 # string: 'hflip, crop=950:420:130:56'
436 for param in options.ref_crop_parameters.split('crop'):
437 if param[0] == '=':
438 crop_width = int(param.split(':')[0].split('=')[1])
439 crop_height = int(param.split(':')[1])
440
jansson1b0e3b82017-03-13 02:15:51 -0700441 compare_cmd = [
jansson1b0e3b82017-03-13 02:15:51 -0700442 compare_videos_script,
jansson9b932032017-06-02 02:16:27 -0700443 '--ref_video=%s' % cropped_ref_file,
444 '--test_video=%s' % cropped_test_file,
445 '--frame_analyzer=%s' % os.path.abspath(options.frame_analyzer),
Magnus Jedvert3e169ac2018-08-24 12:44:59 +0000446 '--yuv_frame_height=%d' % crop_height,
447 '--yuv_frame_width=%d' % crop_width
jansson1b0e3b82017-03-13 02:15:51 -0700448 ]
449
jansson5c7a6232017-03-15 08:27:31 -0700450 with open(result_file_name, 'w') as f:
jansson07e20db2017-04-12 01:36:02 -0700451 try:
452 compare_video_recordings = subprocess.check_output(compare_cmd)
453 f.write(compare_video_recordings)
454 except subprocess.CalledProcessError as error:
455 raise CompareVideosError('Failed to perform comparison: %s' % error)
456 else:
Mirko Bonadei67f88a02019-07-25 18:38:54 +0200457 print('Result recorded to: %s' % os.path.abspath(result_file_name))
458 print('Comparison done!')
jansson07e20db2017-04-12 01:36:02 -0700459 return compare_video_recordings
jansson1b0e3b82017-03-13 02:15:51 -0700460
461
462def main():
463 """The main function.
464
465 A simple invocation is:
466 ./run_video_analysis.py \
467 --app_name AppRTCMobile \
468 --ffmpeg ./ffmpeg --ref_video_device=/dev/video0 \
469 --test_video_device=/dev/video1 \
jansson1b0e3b82017-03-13 02:15:51 -0700470 --test_crop_parameters 'crop=950:420:130:56' \
471 --ref_crop_parameters 'hflip, crop=950:420:130:56' \
472 --ref_rec_dir /tmp/ref \
473 --test_rec_dir /tmp/test
474
475 This will produce the following files if successful:
476 # Original video recordings.
477 /tmp/ref/AppRTCMobile_<recording date and time>_ref.yuv
478 /tmp/test/AppRTCMobile_<recording date and time>_test.yuv
479
480 # Cropped video recordings according to the crop parameters.
481 /tmp/ref/cropped_AppRTCMobile_<recording date and time>_ref.yuv
482 /tmp/test/cropped_AppRTCMobile_<recording date and time>_ref.yuv
483
484 # Comparison metrics from cropped test and ref videos.
485 /tmp/test/AppRTCMobile_<recording date and time>_result.text
486
487 """
488 options = _ParseArgs()
489 RestartMagewellDevices(options.ref_video_device, options.test_video_device)
490 record_paths = CreateRecordingDirs(options)
jansson5c7a6232017-03-15 08:27:31 -0700491 recording_result = StartRecording(options, record_paths['ref_rec_location'],
492 record_paths['test_rec_location'])
jansson1b0e3b82017-03-13 02:15:51 -0700493
494 # Do not require compare_video.py script to run, no metrics will be generated.
495 if options.compare_videos_script:
jansson5c7a6232017-03-15 08:27:31 -0700496 CompareVideos(options, recording_result['cropped_ref_file'],
497 recording_result['cropped_test_file'])
jansson1b0e3b82017-03-13 02:15:51 -0700498 else:
499 print ('Skipping compare videos step due to compare_videos flag were not '
500 'passed.')
501
502
503if __name__ == '__main__':
504 sys.exit(main())