| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 # Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
| 3 # | 3 # |
| 4 # Use of this source code is governed by a BSD-style license | 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 | 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 | 6 # tree. An additional intellectual property rights grant can be found |
| 7 # in the file PATENTS. All contributing project authors may | 7 # in the file PATENTS. All contributing project authors may |
| 8 # be found in the AUTHORS file in the root of the source tree. | 8 # be found in the AUTHORS file in the root of the source tree. |
| 9 | 9 |
| 10 import optparse | 10 import optparse |
| 11 import os | 11 import os |
| 12 import subprocess | 12 import subprocess |
| 13 import sys | 13 import sys |
| 14 import time | 14 import time |
| 15 import glob | 15 import glob |
| 16 import re | 16 import re |
| 17 import shutil |
| 17 | 18 |
| 18 # Used to time-stamp output files and directories | 19 # Used to time-stamp output files and directories |
| 19 CURRENT_TIME = time.strftime("%d_%m_%Y-%H:%M:%S") | 20 CURRENT_TIME = time.strftime("%d_%m_%Y-%H:%M:%S") |
| 20 | 21 |
| 22 |
| 23 class Error(Exception): |
| 24 pass |
| 25 |
| 26 |
| 27 class FfmpegError(Error): |
| 28 pass |
| 29 |
| 30 |
| 31 class MagewellError(Error): |
| 32 pass |
| 33 |
| 34 |
| 35 class CompareVideosError(Error): |
| 36 pass |
| 37 |
| 38 |
| 21 def _ParseArgs(): | 39 def _ParseArgs(): |
| 22 """Registers the command-line options.""" | 40 """Registers the command-line options.""" |
| 23 usage = 'usage: %prog [options]' | 41 usage = 'usage: %prog [options]' |
| 24 parser = optparse.OptionParser(usage=usage) | 42 parser = optparse.OptionParser(usage=usage) |
| 25 | 43 |
| 26 parser.add_option('--frame_width', type='string', default='1280', | 44 parser.add_option('--frame_width', type='string', default='1280', |
| 27 help='Width of the recording. Default: %default') | 45 help='Width of the recording. Default: %default') |
| 28 parser.add_option('--frame_height', type='string', default='720', | 46 parser.add_option('--frame_height', type='string', default='720', |
| 29 help='Height of the recording. Default: %default') | 47 help='Height of the recording. Default: %default') |
| 30 parser.add_option('--framerate', type='string', default='60', | 48 parser.add_option('--framerate', type='string', default='60', |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 parser.warning('Cannot find Zebra Xing, no metrics will be generated!') | 122 parser.warning('Cannot find Zebra Xing, no metrics will be generated!') |
| 105 | 123 |
| 106 return options | 124 return options |
| 107 | 125 |
| 108 | 126 |
| 109 def CreateRecordingDirs(options): | 127 def CreateRecordingDirs(options): |
| 110 """Create root + sub directories for reference and test recordings. | 128 """Create root + sub directories for reference and test recordings. |
| 111 | 129 |
| 112 Args: | 130 Args: |
| 113 options(object): Contains all the provided command line options. | 131 options(object): Contains all the provided command line options. |
| 114 Return: | 132 |
| 133 Returns: |
| 115 record_paths(dict): key: value pair with reference and test file | 134 record_paths(dict): key: value pair with reference and test file |
| 116 absolute paths. | 135 absolute paths. |
| 117 """ | 136 """ |
| 118 | 137 |
| 119 # Create root directories for the video recordings. | 138 # Create root directories for the video recordings. |
| 120 if not os.path.isdir(options.ref_rec_dir): | 139 if not os.path.isdir(options.ref_rec_dir): |
| 121 os.makedirs(options.ref_rec_dir) | 140 os.makedirs(options.ref_rec_dir) |
| 122 if not os.path.isdir(options.test_rec_dir): | 141 if not os.path.isdir(options.test_rec_dir): |
| 123 os.makedirs(options.test_rec_dir) | 142 os.makedirs(options.test_rec_dir) |
| 124 | 143 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 140 | 159 |
| 141 | 160 |
| 142 def RestartMagewellDevices(ref_video_device, test_video_device): | 161 def RestartMagewellDevices(ref_video_device, test_video_device): |
| 143 """Reset the USB ports where Magewell capture devices are connected to. | 162 """Reset the USB ports where Magewell capture devices are connected to. |
| 144 | 163 |
| 145 Tries to find the provided ref_video_device and test_video_device devices | 164 Tries to find the provided ref_video_device and test_video_device devices |
| 146 which use video4linux and then do a soft reset by using USB unbind and bind. | 165 which use video4linux and then do a soft reset by using USB unbind and bind. |
| 147 This is due to Magewell capture devices have proven to be unstable after the | 166 This is due to Magewell capture devices have proven to be unstable after the |
| 148 first recording attempt. | 167 first recording attempt. |
| 149 | 168 |
| 150 Args: | 169 Args : |
| 151 ref_video_device(string): reference recording device path. | 170 ref_video_device(string): reference recording device path. |
| 152 test_video_device(string): test recording device path | 171 test_video_device(string): test recording device path |
| 172 |
| 173 Raises: |
| 174 MagewellError: If no magewell devices are found. |
| 153 """ | 175 """ |
| 154 | 176 |
| 155 # Get the dev/videoN device name from the command line arguments. | 177 # Get the dev/videoN device name from the command line arguments. |
| 156 ref_magewell = ref_video_device.split('/')[2] | 178 ref_magewell = ref_video_device.split('/')[2] |
| 157 test_magewell = test_video_device.split('/')[2] | 179 test_magewell = test_video_device.split('/')[2] |
| 158 | 180 |
| 159 # Find the device location including USB and USB Bus ID's. | 181 # Find the device location including USB and USB Bus ID's. |
| 160 device_string = '/sys/bus/usb/devices/usb*/**/**/video4linux/' | 182 device_string = '/sys/bus/usb/devices/usb*/**/**/video4linux/' |
| 161 ref_magewell_device = glob.glob('%s%s' % (device_string, ref_magewell)) | 183 ref_magewell_device = glob.glob('%s%s' % (device_string, ref_magewell)) |
| 162 test_magewell_device = glob.glob('%s%s' % (device_string, test_magewell)) | 184 test_magewell_device = glob.glob('%s%s' % (device_string, test_magewell)) |
| 163 | 185 |
| 164 magewell_usb_ports = [] | 186 magewell_usb_ports = [] |
| 165 | 187 |
| 166 # Figure out the USB bus and port ID for each device. | 188 # Figure out the USB bus and port ID for each device. |
| 167 ref_magewell_path = str(ref_magewell_device).split('/') | 189 ref_magewell_path = str(ref_magewell_device).split('/') |
| 168 for directory in ref_magewell_path: | 190 for directory in ref_magewell_path: |
| 169 | |
| 170 # Find the folder with pattern "N-N", e.g. "4-3" or \ | 191 # Find the folder with pattern "N-N", e.g. "4-3" or \ |
| 171 # "[USB bus ID]-[USB port]" | 192 # "[USB bus ID]-[USB port]" |
| 172 if re.match(r'^\d-\d$', directory): | 193 if re.match(r'^\d-\d$', directory): |
| 173 magewell_usb_ports.append(directory) | 194 magewell_usb_ports.append(directory) |
| 174 | 195 |
| 175 test_magewell_path = str(test_magewell_device).split('/') | 196 test_magewell_path = str(test_magewell_device).split('/') |
| 176 for directory in test_magewell_path: | 197 for directory in test_magewell_path: |
| 177 | |
| 178 # Find the folder with pattern "N-N", e.g. "4-3" or \ | 198 # Find the folder with pattern "N-N", e.g. "4-3" or \ |
| 179 # "[USB bus ID]-[USB port]" | 199 # "[USB bus ID]-[USB port]" |
| 180 if re.match(r'^\d-\d$', directory): | 200 if re.match(r'^\d-\d$', directory): |
| 181 magewell_usb_ports.append(directory) | 201 magewell_usb_ports.append(directory) |
| 182 | 202 |
| 183 print '\nResetting USB ports where magewell devices are connected...' | 203 # Abort early if no devices are found. |
| 184 | 204 if len(magewell_usb_ports) == 0: |
| 185 # Use the USB bus and port ID (e.g. 4-3) to unbind and bind the USB devices | 205 raise MagewellError('No magewell devices found.') |
| 186 # (i.e. soft eject and insert). | 206 else: |
| 187 try: | 207 print '\nResetting USB ports where magewell devices are connected...' |
| 208 # Use the USB bus and port ID (e.g. 4-3) to unbind and bind the USB devices |
| 209 # (i.e. soft eject and insert). |
| 188 for usb_port in magewell_usb_ports: | 210 for usb_port in magewell_usb_ports: |
| 189 echo_cmd = ['echo', usb_port] | 211 echo_cmd = ['echo', usb_port] |
| 190 unbind_cmd = ['sudo', 'tee', '/sys/bus/usb/drivers/usb/unbind'] | 212 unbind_cmd = ['sudo', 'tee', '/sys/bus/usb/drivers/usb/unbind'] |
| 191 bind_cmd = ['sudo', 'tee', '/sys/bus/usb/drivers/usb/bind'] | 213 bind_cmd = ['sudo', 'tee', '/sys/bus/usb/drivers/usb/bind'] |
| 192 | 214 |
| 193 # TODO(jansson) Figure out a way to call on echo once for bind & unbind | 215 # TODO(jansson) Figure out a way to call on echo once for bind & unbind |
| 194 # if possible. | 216 # if possible. |
| 195 echo_unbind = subprocess.Popen(echo_cmd, stdout=subprocess.PIPE) | 217 echo_unbind = subprocess.Popen(echo_cmd, stdout=subprocess.PIPE) |
| 196 unbind = subprocess.Popen(unbind_cmd, stdin=echo_unbind.stdout) | 218 unbind = subprocess.Popen(unbind_cmd, stdin=echo_unbind.stdout) |
| 197 echo_unbind.stdout.close() | 219 echo_unbind.stdout.close() |
| 198 unbind.communicate() | |
| 199 unbind.wait() | 220 unbind.wait() |
| 200 | 221 |
| 201 echo_bind = subprocess.Popen(echo_cmd, stdout=subprocess.PIPE) | 222 echo_bind = subprocess.Popen(echo_cmd, stdout=subprocess.PIPE) |
| 202 bind = subprocess.Popen(bind_cmd, stdin=echo_bind.stdout) | 223 bind = subprocess.Popen(bind_cmd, stdin=echo_bind.stdout) |
| 203 echo_bind.stdout.close() | 224 echo_bind.stdout.close() |
| 204 bind.communicate() | |
| 205 bind.wait() | 225 bind.wait() |
| 206 except OSError as e: | 226 if bind.returncode == 0: |
| 207 print 'Error while resetting magewell devices: ' + e | 227 print 'Reset done!\n' |
| 208 raise | |
| 209 | |
| 210 print 'Reset done!\n' | |
| 211 | 228 |
| 212 | 229 |
| 213 def StartRecording(options, record_paths): | 230 def StartRecording(options, ref_file_location, test_file_location): |
| 214 """Starts recording from the two specified video devices. | 231 """Starts recording from the two specified video devices. |
| 215 | 232 |
| 216 Args: | 233 Args: |
| 217 options(object): Contains all the provided command line options. | 234 options(object): Contains all the provided command line options. |
| 218 record_paths(dict): key: value pair with reference and test file | 235 record_paths(dict): key: value pair with reference and test file |
| 219 absolute paths. | 236 absolute paths. |
| 237 |
| 238 Returns: |
| 239 recording_files_and_time(dict): key: value pair with the path to cropped |
| 240 test and reference video files. |
| 241 |
| 242 Raises: |
| 243 FfmpegError: If the ffmpeg command fails. |
| 220 """ | 244 """ |
| 221 ref_file_name = '%s_%s_ref.%s' % (options.app_name, CURRENT_TIME, | 245 ref_file_name = '%s_%s_ref.%s' % (options.app_name, CURRENT_TIME, |
| 222 options.video_container) | 246 options.video_container) |
| 223 ref_file_location = os.path.join(record_paths['ref_rec_location'], | 247 ref_file = os.path.join(ref_file_location, ref_file_name) |
| 224 ref_file_name) | |
| 225 | 248 |
| 226 test_file_name = '%s_%s_test.%s' % (options.app_name, CURRENT_TIME, | 249 test_file_name = '%s_%s_test.%s' % (options.app_name, CURRENT_TIME, |
| 227 options.video_container) | 250 options.video_container) |
| 228 test_file_location = os.path.join(record_paths['test_rec_location'], | 251 test_file = os.path.join(test_file_location, test_file_name) |
| 229 test_file_name) | |
| 230 | 252 |
| 231 # Reference video recorder command line. | 253 # Reference video recorder command line. |
| 232 ref_cmd = [ | 254 ref_cmd = [ |
| 233 options.ffmpeg, | 255 options.ffmpeg, |
| 234 '-v', 'error', | 256 '-v', 'error', |
| 235 '-s', options.frame_width + 'x' + options.frame_height, | 257 '-s', options.frame_width + 'x' + options.frame_height, |
| 236 '-framerate', options.framerate, | 258 '-framerate', options.framerate, |
| 237 '-f', options.recording_api, | 259 '-f', options.recording_api, |
| 238 '-i', options.ref_video_device, | 260 '-i', options.ref_video_device, |
| 239 '-pix_fmt', options.pixel_format, | 261 '-pix_fmt', options.pixel_format, |
| 240 '-s', options.frame_width + 'x' + options.frame_height, | 262 '-s', options.frame_width + 'x' + options.frame_height, |
| 241 '-t', options.ref_duration, | 263 '-t', options.ref_duration, |
| 242 '-framerate', options.framerate, | 264 '-framerate', options.framerate, |
| 243 ref_file_location | 265 ref_file |
| 244 ] | 266 ] |
| 245 | 267 |
| 246 # Test video recorder command line. | 268 # Test video recorder command line. |
| 247 test_cmd = [ | 269 test_cmd = [ |
| 248 options.ffmpeg, | 270 options.ffmpeg, |
| 249 '-v', 'error', | 271 '-v', 'error', |
| 250 '-s', options.frame_width + 'x' + options.frame_height, | 272 '-s', options.frame_width + 'x' + options.frame_height, |
| 251 '-framerate', options.framerate, | 273 '-framerate', options.framerate, |
| 252 '-f', options.recording_api, | 274 '-f', options.recording_api, |
| 253 '-i', options.test_video_device, | 275 '-i', options.test_video_device, |
| 254 '-pix_fmt', options.pixel_format, | 276 '-pix_fmt', options.pixel_format, |
| 255 '-s', options.frame_width + 'x' + options.frame_height, | 277 '-s', options.frame_width + 'x' + options.frame_height, |
| 256 '-t', options.test_duration, | 278 '-t', options.test_duration, |
| 257 '-framerate', options.framerate, | 279 '-framerate', options.framerate, |
| 258 test_file_location | 280 test_file |
| 259 ] | 281 ] |
| 260 print 'Trying to record from reference recorder...' | 282 print 'Trying to record from reference recorder...' |
| 261 ref_recorder = subprocess.Popen(ref_cmd, stderr=sys.stderr) | 283 ref_recorder = subprocess.Popen(ref_cmd, stderr=sys.stderr) |
| 262 | 284 |
| 263 # Start the 2nd recording a little later to ensure the 1st one has started. | 285 # Start the 2nd recording a little later to ensure the 1st one has started. |
| 264 # TODO(jansson) Check that the ref_recorder output file exists rather than | 286 # TODO(jansson) Check that the ref_recorder output file exists rather than |
| 265 # using sleep. | 287 # using sleep. |
| 266 time.sleep(options.time_between_recordings) | 288 time.sleep(options.time_between_recordings) |
| 267 print 'Trying to record from test recorder...' | 289 print 'Trying to record from test recorder...' |
| 268 test_recorder = subprocess.Popen(test_cmd, stderr=sys.stderr) | 290 test_recorder = subprocess.Popen(test_cmd, stderr=sys.stderr) |
| 269 test_recorder.wait() | 291 test_recorder.wait() |
| 270 ref_recorder.wait() | 292 ref_recorder.wait() |
| 271 | 293 |
| 272 # ffmpeg does not abort when it fails, need to check return code. | 294 # ffmpeg does not abort when it fails, need to check return code. |
| 273 assert ref_recorder.returncode == 0, ( | 295 if ref_recorder.returncode != 0 or test_recorder.returncode != 0: |
| 274 'Ref recording failed, check ffmpeg output and device: %s' | 296 # Cleanup recording directories. |
| 275 % options.ref_video_device) | 297 shutil.rmtree(ref_file_location) |
| 276 assert test_recorder.returncode == 0, ( | 298 shutil.rmtree(test_file_location) |
| 277 'Test recording failed, check ffmpeg output and device: %s' | 299 raise FfmpegError('Recording failed, check ffmpeg output.') |
| 278 % options.test_video_device) | 300 else: |
| 279 | 301 print 'Ref file recorded to: ' + os.path.abspath(ref_file) |
| 280 print 'Ref file recorded to: ' + os.path.abspath(ref_file_location) | 302 print 'Test file recorded to: ' + os.path.abspath(test_file) |
| 281 print 'Test file recorded to: ' + os.path.abspath(test_file_location) | 303 print 'Recording done!\n' |
| 282 print 'Recording done!\n' | 304 return FlipAndCropRecordings(options, test_file_name, test_file_location, |
| 283 return FlipAndCropRecordings(options, test_file_name, | 305 ref_file_name, ref_file_location) |
| 284 record_paths['test_rec_location'], ref_file_name, | |
| 285 record_paths['ref_rec_location']) | |
| 286 | 306 |
| 287 | 307 |
| 288 def FlipAndCropRecordings(options, test_file_name, test_file_location, | 308 def FlipAndCropRecordings(options, test_file_name, test_file_location, |
| 289 ref_file_name, ref_file_location): | 309 ref_file_name, ref_file_location): |
| 290 """Performs a horizontal flip of the reference video to match the test video. | 310 """Performs a horizontal flip of the reference video to match the test video. |
| 291 | 311 |
| 292 This is done to the match orientation and then crops the ref and test videos | 312 This is done to the match orientation and then crops the ref and test videos |
| 293 using the options.test_crop_parameters and options.ref_crop_parameters. | 313 using the options.test_crop_parameters and options.ref_crop_parameters. |
| 294 | 314 |
| 295 Args: | 315 Args: |
| 296 options(object): Contains all the provided command line options. | 316 options(object): Contains all the provided command line options. |
| 297 test_file_name(string): Name of the test video file recording. | 317 test_file_name(string): Name of the test video file recording. |
| 298 test_file_location(string): Path to the test video file recording. | 318 test_file_location(string): Path to the test video file recording. |
| 299 ref_file_name(string): Name of the reference video file recording. | 319 ref_file_name(string): Name of the reference video file recording. |
| 300 ref_file_location(string): Path to the reference video file recording. | 320 ref_file_location(string): Path to the reference video file recording. |
| 301 Return: | 321 |
| 322 Returns: |
| 302 recording_files_and_time(dict): key: value pair with the path to cropped | 323 recording_files_and_time(dict): key: value pair with the path to cropped |
| 303 test and reference video files. | 324 test and reference video files. |
| 325 |
| 326 Raises: |
| 327 FfmpegError: If the ffmpeg command fails. |
| 304 """ | 328 """ |
| 305 print 'Trying to crop videos...' | 329 print 'Trying to crop videos...' |
| 306 | 330 |
| 307 # Ref file cropping. | 331 # Ref file cropping. |
| 308 cropped_ref_file_name = 'cropped_' + ref_file_name | 332 cropped_ref_file_name = 'cropped_' + ref_file_name |
| 309 cropped_ref_file = os.path.abspath( | 333 cropped_ref_file = os.path.abspath( |
| 310 os.path.join(ref_file_location, cropped_ref_file_name)) | 334 os.path.join(ref_file_location, cropped_ref_file_name)) |
| 311 | 335 |
| 312 ref_video_crop_cmd = [ | 336 ref_video_crop_cmd = [ |
| 313 options.ffmpeg, | 337 options.ffmpeg, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 329 '-v', 'error', | 353 '-v', 'error', |
| 330 '-s', options.frame_width + 'x' + options.frame_height, | 354 '-s', options.frame_width + 'x' + options.frame_height, |
| 331 '-i', os.path.join(test_file_location, test_file_name), | 355 '-i', os.path.join(test_file_location, test_file_name), |
| 332 '-vf', options.test_crop_parameters, | 356 '-vf', options.test_crop_parameters, |
| 333 '-c:a', 'copy', | 357 '-c:a', 'copy', |
| 334 cropped_test_file | 358 cropped_test_file |
| 335 ] | 359 ] |
| 336 | 360 |
| 337 ref_crop = subprocess.Popen(ref_video_crop_cmd) | 361 ref_crop = subprocess.Popen(ref_video_crop_cmd) |
| 338 ref_crop.wait() | 362 ref_crop.wait() |
| 339 print 'Ref file cropped to: ' + cropped_ref_file | 363 test_crop = subprocess.Popen(test_video_crop_cmd) |
| 364 test_crop.wait() |
| 340 | 365 |
| 341 try: | 366 # ffmpeg does not abort when it fails, need to check return code. |
| 342 test_crop = subprocess.Popen(test_video_crop_cmd) | 367 if ref_crop.returncode != 0 or test_crop.returncode != 0: |
| 343 test_crop.wait() | 368 # Cleanup recording directories. |
| 369 shutil.rmtree(ref_file_location) |
| 370 shutil.rmtree(test_file_location) |
| 371 raise FfmpegError('Cropping failed, check ffmpeg output.') |
| 372 else: |
| 373 print 'Ref file cropped to: ' + cropped_ref_file |
| 344 print 'Test file cropped to: ' + cropped_test_file | 374 print 'Test file cropped to: ' + cropped_test_file |
| 345 print 'Cropping done!\n' | 375 print 'Cropping done!\n' |
| 346 | 376 |
| 347 # Need to return these so they can be used by other parts. | 377 # Need to return these so they can be used by other parts. |
| 348 cropped_recordings = { | 378 cropped_recordings = { |
| 349 'cropped_test_file' : cropped_test_file, | 379 'cropped_test_file' : cropped_test_file, |
| 350 'cropped_ref_file' : cropped_ref_file | 380 'cropped_ref_file' : cropped_ref_file |
| 351 } | 381 } |
| 352 | |
| 353 return cropped_recordings | 382 return cropped_recordings |
| 354 except subprocess.CalledProcessError as e: | |
| 355 print 'Something went wrong during cropping: ' + e | |
| 356 raise | |
| 357 | 383 |
| 358 | 384 |
| 359 def CompareVideos(options, recording_result): | 385 def CompareVideos(options, cropped_ref_file, cropped_test_file): |
| 360 """Runs the compare_video.py script from src/webrtc/tools using the file path. | 386 """Runs the compare_video.py script from src/webrtc/tools using the file path. |
| 361 | 387 |
| 362 Uses the path from recording_result and writes the output to a file named | 388 Uses the path from recording_result and writes the output to a file named |
| 363 <options.app_name + '_' + CURRENT_TIME + '_result.txt> in the reference video | 389 <options.app_name + '_' + CURRENT_TIME + '_result.txt> in the reference video |
| 364 recording folder taken from recording_result. | 390 recording folder taken from recording_result. |
| 365 | 391 |
| 366 Args: | 392 Args: |
| 367 options(object): Contains all the provided command line options. | 393 options(object): Contains all the provided command line options. |
| 368 recording_files_and_time(dict): key: value pair with the path to cropped | 394 cropped_ref_file(string): Path to cropped reference video file. |
| 369 test and reference video files | 395 cropped_test_file(string): Path to cropped test video file. |
| 396 |
| 397 Raises: |
| 398 CompareVideosError: If compare_videos.py fails. |
| 370 """ | 399 """ |
| 371 print 'Starting comparison...' | 400 print 'Starting comparison...' |
| 372 print 'Grab a coffee, this might take a few minutes...' | 401 print 'Grab a coffee, this might take a few minutes...' |
| 373 cropped_ref_file = recording_result['cropped_ref_file'] | |
| 374 cropped_test_file = recording_result['cropped_test_file'] | |
| 375 compare_videos_script = os.path.abspath(options.compare_videos_script) | 402 compare_videos_script = os.path.abspath(options.compare_videos_script) |
| 376 rec_path = os.path.abspath(os.path.join( | 403 rec_path = os.path.abspath(os.path.join( |
| 377 os.path.dirname(recording_result['cropped_ref_file']))) | 404 os.path.dirname(cropped_test_file))) |
| 378 result_file_name = os.path.join(rec_path, '%s_%s_result.txt') % ( | 405 result_file_name = os.path.join(rec_path, '%s_%s_result.txt') % ( |
| 379 options.app_name, CURRENT_TIME) | 406 options.app_name, CURRENT_TIME) |
| 380 | 407 |
| 381 # Find the crop dimensions (950 and 420) in the ref crop parameter string: | 408 # Find the crop dimensions (e.g. 950 and 420) in the ref crop parameter |
| 382 # 'hflip, crop=950:420:130:56' | 409 # string: 'hflip, crop=950:420:130:56' |
| 383 for param in options.ref_crop_parameters.split('crop'): | 410 for param in options.ref_crop_parameters.split('crop'): |
| 384 if param[0] == '=': | 411 if param[0] == '=': |
| 385 crop_width = param.split(':')[0].split('=')[1] | 412 crop_width = param.split(':')[0].split('=')[1] |
| 386 crop_height = param.split(':')[1] | 413 crop_height = param.split(':')[1] |
| 387 | 414 |
| 388 compare_cmd = [ | 415 compare_cmd = [ |
| 389 sys.executable, | 416 sys.executable, |
| 390 compare_videos_script, | 417 compare_videos_script, |
| 391 '--ref_video', cropped_ref_file, | 418 '--ref_video', cropped_ref_file, |
| 392 '--test_video', cropped_test_file, | 419 '--test_video', cropped_test_file, |
| 393 '--frame_analyzer', os.path.abspath(options.frame_analyzer), | 420 '--frame_analyzer', os.path.abspath(options.frame_analyzer), |
| 394 '--zxing_path', options.zxing_path, | 421 '--zxing_path', options.zxing_path, |
| 395 '--ffmpeg_path', options.ffmpeg, | 422 '--ffmpeg_path', options.ffmpeg, |
| 396 '--stats_file_ref', os.path.join(os.path.dirname(cropped_ref_file), | 423 '--stats_file_ref', os.path.join(os.path.dirname(cropped_ref_file), |
| 397 cropped_ref_file + '_stats.txt'), | 424 cropped_ref_file + '_stats.txt'), |
| 398 '--stats_file_test', os.path.join(os.path.dirname(cropped_test_file), | 425 '--stats_file_test', os.path.join(os.path.dirname(cropped_test_file), |
| 399 cropped_test_file + '_stats.txt'), | 426 cropped_test_file + '_stats.txt'), |
| 400 '--yuv_frame_height', crop_height, | 427 '--yuv_frame_height', crop_height, |
| 401 '--yuv_frame_width', crop_width | 428 '--yuv_frame_width', crop_width |
| 402 ] | 429 ] |
| 403 | 430 |
| 404 try: | 431 with open(result_file_name, 'w') as f: |
| 405 with open(result_file_name, 'w') as f: | 432 compare_video_recordings = subprocess.Popen(compare_cmd, stdout=f) |
| 406 compare_video_recordings = subprocess.Popen(compare_cmd, stdout=f) | 433 compare_video_recordings.wait() |
| 407 compare_video_recordings.wait() | 434 if compare_video_recordings.returncode != 0: |
| 408 print 'Result recorded to: ' + os.path.abspath(result_file_name) | 435 raise CompareVideosError('Failed to perform comparison.') |
| 409 print 'Comparison done!' | 436 else: |
| 410 except subprocess.CalledProcessError as e: | 437 print 'Result recorded to: ' + os.path.abspath(result_file_name) |
| 411 print 'Something went wrong when trying to compare videos: ' + e | 438 print 'Comparison done!' |
| 412 raise | |
| 413 | 439 |
| 414 | 440 |
| 415 def main(): | 441 def main(): |
| 416 """The main function. | 442 """The main function. |
| 417 | 443 |
| 418 A simple invocation is: | 444 A simple invocation is: |
| 419 ./run_video_analysis.py \ | 445 ./run_video_analysis.py \ |
| 420 --app_name AppRTCMobile \ | 446 --app_name AppRTCMobile \ |
| 421 --ffmpeg ./ffmpeg --ref_video_device=/dev/video0 \ | 447 --ffmpeg ./ffmpeg --ref_video_device=/dev/video0 \ |
| 422 --test_video_device=/dev/video1 \ | 448 --test_video_device=/dev/video1 \ |
| (...skipping 12 matching lines...) Expand all Loading... |
| 435 /tmp/ref/cropped_AppRTCMobile_<recording date and time>_ref.yuv | 461 /tmp/ref/cropped_AppRTCMobile_<recording date and time>_ref.yuv |
| 436 /tmp/test/cropped_AppRTCMobile_<recording date and time>_ref.yuv | 462 /tmp/test/cropped_AppRTCMobile_<recording date and time>_ref.yuv |
| 437 | 463 |
| 438 # Comparison metrics from cropped test and ref videos. | 464 # Comparison metrics from cropped test and ref videos. |
| 439 /tmp/test/AppRTCMobile_<recording date and time>_result.text | 465 /tmp/test/AppRTCMobile_<recording date and time>_result.text |
| 440 | 466 |
| 441 """ | 467 """ |
| 442 options = _ParseArgs() | 468 options = _ParseArgs() |
| 443 RestartMagewellDevices(options.ref_video_device, options.test_video_device) | 469 RestartMagewellDevices(options.ref_video_device, options.test_video_device) |
| 444 record_paths = CreateRecordingDirs(options) | 470 record_paths = CreateRecordingDirs(options) |
| 445 recording_result = StartRecording(options, record_paths) | 471 recording_result = StartRecording(options, record_paths['ref_rec_location'], |
| 472 record_paths['test_rec_location']) |
| 446 | 473 |
| 447 # Do not require compare_video.py script to run, no metrics will be generated. | 474 # Do not require compare_video.py script to run, no metrics will be generated. |
| 448 if options.compare_videos_script: | 475 if options.compare_videos_script: |
| 449 CompareVideos(options, recording_result) | 476 CompareVideos(options, recording_result['cropped_ref_file'], |
| 477 recording_result['cropped_test_file']) |
| 450 else: | 478 else: |
| 451 print ('Skipping compare videos step due to compare_videos flag were not ' | 479 print ('Skipping compare videos step due to compare_videos flag were not ' |
| 452 'passed.') | 480 'passed.') |
| 453 | 481 |
| 454 | 482 |
| 455 if __name__ == '__main__': | 483 if __name__ == '__main__': |
| 456 sys.exit(main()) | 484 sys.exit(main()) |
| OLD | NEW |