Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(135)

Side by Side Diff: webrtc/tools/video_analysis.py

Issue 2921463005: Change all numerical string inputs to int and remove unused stderr (Closed)
Patch Set: change float to int Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 glob 10 import glob
(...skipping 23 matching lines...) Expand all
34 34
35 class CompareVideosError(Error): 35 class CompareVideosError(Error):
36 pass 36 pass
37 37
38 38
39 def _ParseArgs(): 39 def _ParseArgs():
40 """Registers the command-line options.""" 40 """Registers the command-line options."""
41 usage = 'usage: %prog [options]' 41 usage = 'usage: %prog [options]'
42 parser = optparse.OptionParser(usage=usage) 42 parser = optparse.OptionParser(usage=usage)
43 43
44 parser.add_option('--frame_width', type='string', default='1280', 44 parser.add_option('--frame_width', type='int', default=1280,
45 help='Width of the recording. Default: %default') 45 help='Width of the recording. Default: %default')
46 parser.add_option('--frame_height', type='string', default='720', 46 parser.add_option('--frame_height', type='int', default=720,
47 help='Height of the recording. Default: %default') 47 help='Height of the recording. Default: %default')
48 parser.add_option('--framerate', type='string', default='60', 48 parser.add_option('--framerate', type='int', default=60,
49 help='Recording framerate. Default: %default') 49 help='Recording framerate. Default: %default')
50 parser.add_option('--ref_duration', type='string', default='20', 50 parser.add_option('--ref_duration', type='int', default=20,
51 help='Reference recording duration. Default: %default') 51 help='Reference recording duration. Default: %default')
52 parser.add_option('--test_duration', type='string', default='10', 52 parser.add_option('--test_duration', type='int', default=10,
53 help='Test recording duration. Default: %default') 53 help='Test recording duration. Default: %default')
54 parser.add_option('--time_between_recordings', type=float, default=5, 54 parser.add_option('--time_between_recordings', type='int', default=5,
55 help='Time between starting test recording after ref.' 55 help='Time between starting test recording after ref.'
56 'Default: %default') 56 'Default: %default')
57 parser.add_option('--ref_video_device', type='string', default='/dev/video0', 57 parser.add_option('--ref_video_device', type='string', default='/dev/video0',
58 help='Reference recording device. Default: %default') 58 help='Reference recording device. Default: %default')
59 parser.add_option('--test_video_device', type='string', default='/dev/video1', 59 parser.add_option('--test_video_device', type='string', default='/dev/video1',
60 help='Test recording device. Default: %default') 60 help='Test recording device. Default: %default')
61 parser.add_option('--app_name', type='string', 61 parser.add_option('--app_name', type='string',
62 help='Name of the app under test.') 62 help='Name of the app under test.')
63 parser.add_option('--recording_api', type='string', default='Video4Linux2', 63 parser.add_option('--recording_api', type='string', default='Video4Linux2',
64 help='Recording API to use. Default: %default') 64 help='Recording API to use. Default: %default')
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 ref_file = os.path.join(ref_file_location, ref_file_name) 272 ref_file = os.path.join(ref_file_location, ref_file_name)
273 273
274 test_file_name = '%s_%s_test.%s' % (options.app_name, CURRENT_TIME, 274 test_file_name = '%s_%s_test.%s' % (options.app_name, CURRENT_TIME,
275 options.video_container) 275 options.video_container)
276 test_file = os.path.join(test_file_location, test_file_name) 276 test_file = os.path.join(test_file_location, test_file_name)
277 277
278 # Reference video recorder command line. 278 # Reference video recorder command line.
279 ref_cmd = [ 279 ref_cmd = [
280 options.ffmpeg, 280 options.ffmpeg,
281 '-v', 'error', 281 '-v', 'error',
282 '-s', options.frame_width + 'x' + options.frame_height, 282 '-s', '%dx%d' % (options.frame_width, options.frame_height),
283 '-framerate', options.framerate, 283 '-r', '%d' % options.framerate,
284 '-f', options.recording_api, 284 '-f', '%s' % options.recording_api,
285 '-i', options.ref_video_device, 285 '-i', '%s' % options.ref_video_device,
286 '-pix_fmt', options.pixel_format, 286 '-pix_fmt', '%s' % options.pixel_format,
287 '-s', options.frame_width + 'x' + options.frame_height, 287 '-s', '%dx%d' % (options.frame_width, options.frame_height),
288 '-t', options.ref_duration, 288 '-t', '%d' % options.ref_duration,
289 '-framerate', options.framerate, 289 '-r', '%d' % options.framerate,
290 ref_file 290 ref_file
291 ] 291 ]
292 292
293 # Test video recorder command line. 293 # Test video recorder command line.
294 test_cmd = [ 294 test_cmd = [
295 options.ffmpeg, 295 options.ffmpeg,
296 '-v', 'error', 296 '-v', 'error',
297 '-s', options.frame_width + 'x' + options.frame_height, 297 '-s', '%dx%d' % (options.frame_width, options.frame_height),
298 '-framerate', options.framerate, 298 '-r', '%d' % options.framerate,
299 '-f', options.recording_api, 299 '-f', '%s' % options.recording_api,
300 '-i', options.test_video_device, 300 '-i', '%s' % options.test_video_device,
301 '-pix_fmt', options.pixel_format, 301 '-pix_fmt', '%s' % options.pixel_format,
302 '-s', options.frame_width + 'x' + options.frame_height, 302 '-s', '%dx%d' % (options.frame_width, options.frame_height),
303 '-t', options.test_duration, 303 '-t', '%d' % options.test_duration,
304 '-framerate', options.framerate, 304 '-r', '%d' % options.framerate,
305 test_file 305 test_file
306 ] 306 ]
307 print 'Trying to record from reference recorder...' 307 print 'Trying to record from reference recorder...'
308 ref_recorder = subprocess.Popen(ref_cmd, stderr=sys.stderr) 308 ref_recorder = subprocess.Popen(ref_cmd)
309 309
310 # Start the 2nd recording a little later to ensure the 1st one has started. 310 # Start the 2nd recording a little later to ensure the 1st one has started.
311 # TODO(jansson) Check that the ref_recorder output file exists rather than 311 # TODO(jansson) Check that the ref_recorder output file exists rather than
312 # using sleep. 312 # using sleep.
313 time.sleep(options.time_between_recordings) 313 time.sleep(options.time_between_recordings)
314 print 'Trying to record from test recorder...' 314 print 'Trying to record from test recorder...'
315 test_recorder = subprocess.Popen(test_cmd, stderr=sys.stderr) 315 test_recorder = subprocess.Popen(test_cmd)
316 test_recorder.wait() 316 test_recorder.wait()
317 ref_recorder.wait() 317 ref_recorder.wait()
318 318
319 # ffmpeg does not abort when it fails, need to check return code. 319 # ffmpeg does not abort when it fails, need to check return code.
320 if ref_recorder.returncode != 0 or test_recorder.returncode != 0: 320 if ref_recorder.returncode != 0 or test_recorder.returncode != 0:
321 # Cleanup recording directories. 321 # Cleanup recording directories.
322 shutil.rmtree(ref_file_location) 322 shutil.rmtree(ref_file_location)
323 shutil.rmtree(test_file_location) 323 shutil.rmtree(test_file_location)
324 raise FfmpegError('Recording failed, check ffmpeg output.') 324 raise FfmpegError('Recording failed, check ffmpeg output.')
325 else: 325 else:
(...skipping 28 matching lines...) Expand all
354 print 'Trying to crop videos...' 354 print 'Trying to crop videos...'
355 355
356 # Ref file cropping. 356 # Ref file cropping.
357 cropped_ref_file_name = 'cropped_' + ref_file_name 357 cropped_ref_file_name = 'cropped_' + ref_file_name
358 cropped_ref_file = os.path.abspath( 358 cropped_ref_file = os.path.abspath(
359 os.path.join(ref_file_location, cropped_ref_file_name)) 359 os.path.join(ref_file_location, cropped_ref_file_name))
360 360
361 ref_video_crop_cmd = [ 361 ref_video_crop_cmd = [
362 options.ffmpeg, 362 options.ffmpeg,
363 '-v', 'error', 363 '-v', 'error',
364 '-s', options.frame_width + 'x' + options.frame_height, 364 '-s', '%dx%d' % (options.frame_width, options.frame_height),
365 '-i', os.path.join(ref_file_location, ref_file_name), 365 '-i', '%s' % os.path.join(ref_file_location, ref_file_name),
366 '-vf', options.ref_crop_parameters, 366 '-vf', '%s' % options.ref_crop_parameters,
367 '-c:a', 'copy', 367 '-c:a', 'copy',
368 cropped_ref_file 368 cropped_ref_file
369 ] 369 ]
370 370
371 # Test file cropping. 371 # Test file cropping.
372 cropped_test_file_name = 'cropped_' + test_file_name 372 cropped_test_file_name = 'cropped_' + test_file_name
373 cropped_test_file = os.path.abspath( 373 cropped_test_file = os.path.abspath(
374 os.path.join(test_file_location, cropped_test_file_name)) 374 os.path.join(test_file_location, cropped_test_file_name))
375 375
376 test_video_crop_cmd = [ 376 test_video_crop_cmd = [
377 options.ffmpeg, 377 options.ffmpeg,
378 '-v', 'error', 378 '-v', 'error',
379 '-s', options.frame_width + 'x' + options.frame_height, 379 '-s', '%dx%d' % (options.frame_width, options.frame_height),
380 '-i', os.path.join(test_file_location, test_file_name), 380 '-i', '%s' % os.path.join(test_file_location, test_file_name),
381 '-vf', options.test_crop_parameters, 381 '-vf', '%s' % options.test_crop_parameters,
382 '-c:a', 'copy', 382 '-c:a', 'copy',
383 cropped_test_file 383 cropped_test_file
384 ] 384 ]
385 385
386 ref_crop = subprocess.Popen(ref_video_crop_cmd) 386 ref_crop = subprocess.Popen(ref_video_crop_cmd)
387 ref_crop.wait() 387 ref_crop.wait()
388 test_crop = subprocess.Popen(test_video_crop_cmd) 388 test_crop = subprocess.Popen(test_video_crop_cmd)
389 test_crop.wait() 389 test_crop.wait()
390 390
391 # ffmpeg does not abort when it fails, need to check return code. 391 # ffmpeg does not abort when it fails, need to check return code.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 compare_videos_script = os.path.abspath(options.compare_videos_script) 427 compare_videos_script = os.path.abspath(options.compare_videos_script)
428 rec_path = os.path.abspath(os.path.join( 428 rec_path = os.path.abspath(os.path.join(
429 os.path.dirname(cropped_test_file))) 429 os.path.dirname(cropped_test_file)))
430 result_file_name = os.path.join(rec_path, '%s_%s_result.txt') % ( 430 result_file_name = os.path.join(rec_path, '%s_%s_result.txt') % (
431 options.app_name, CURRENT_TIME) 431 options.app_name, CURRENT_TIME)
432 432
433 # Find the crop dimensions (e.g. 950 and 420) in the ref crop parameter 433 # Find the crop dimensions (e.g. 950 and 420) in the ref crop parameter
434 # string: 'hflip, crop=950:420:130:56' 434 # string: 'hflip, crop=950:420:130:56'
435 for param in options.ref_crop_parameters.split('crop'): 435 for param in options.ref_crop_parameters.split('crop'):
436 if param[0] == '=': 436 if param[0] == '=':
437 crop_width = param.split(':')[0].split('=')[1] 437 crop_width = int(param.split(':')[0].split('=')[1])
438 crop_height = param.split(':')[1] 438 crop_height = int(param.split(':')[1])
439 439
440 compare_cmd = [ 440 compare_cmd = [
441 compare_videos_script, 441 compare_videos_script,
442 '--ref_video', cropped_ref_file, 442 '--ref_video=%s' % cropped_ref_file,
443 '--test_video', cropped_test_file, 443 '--test_video=%s' % cropped_test_file,
444 '--frame_analyzer', os.path.abspath(options.frame_analyzer), 444 '--frame_analyzer=%s' % os.path.abspath(options.frame_analyzer),
445 '--zxing_path', options.zxing_path, 445 '--zxing_path=%s' % options.zxing_path,
446 '--ffmpeg_path', options.ffmpeg, 446 '--ffmpeg_path=%s' % options.ffmpeg,
447 '--stats_file_ref', os.path.join(os.path.dirname(cropped_ref_file), 447 '--stats_file_ref=%s_stats.txt' %
448 cropped_ref_file + '_stats.txt'), 448 os.path.join(os.path.dirname(cropped_ref_file), cropped_ref_file),
449 '--stats_file_test', os.path.join(os.path.dirname(cropped_test_file), 449 '--stats_file_test=%s_stats.txt' %
450 cropped_test_file + '_stats.txt'), 450 os.path.join(os.path.dirname(cropped_test_file), cropped_test_file),
451 '--yuv_frame_height', crop_height, 451 '--yuv_frame_height=%d' % crop_height,
452 '--yuv_frame_width', crop_width 452 '--yuv_frame_width=%d' % crop_width
453 ] 453 ]
454 454
455 with open(result_file_name, 'w') as f: 455 with open(result_file_name, 'w') as f:
456 try: 456 try:
457 compare_video_recordings = subprocess.check_output(compare_cmd) 457 compare_video_recordings = subprocess.check_output(compare_cmd)
458 f.write(compare_video_recordings) 458 f.write(compare_video_recordings)
459 except subprocess.CalledProcessError as error: 459 except subprocess.CalledProcessError as error:
460 raise CompareVideosError('Failed to perform comparison: %s' % error) 460 raise CompareVideosError('Failed to perform comparison: %s' % error)
461 else: 461 else:
462 print 'Result recorded to: %s' % os.path.abspath(result_file_name) 462 print 'Result recorded to: %s' % os.path.abspath(result_file_name)
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 if options.compare_videos_script: 501 if options.compare_videos_script:
502 CompareVideos(options, recording_result['cropped_ref_file'], 502 CompareVideos(options, recording_result['cropped_ref_file'],
503 recording_result['cropped_test_file']) 503 recording_result['cropped_test_file'])
504 else: 504 else:
505 print ('Skipping compare videos step due to compare_videos flag were not ' 505 print ('Skipping compare videos step due to compare_videos flag were not '
506 'passed.') 506 'passed.')
507 507
508 508
509 if __name__ == '__main__': 509 if __name__ == '__main__':
510 sys.exit(main()) 510 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698