kjellander | d2b63cf | 2017-06-30 03:04:59 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # Copyright (c) 2013 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 | import optparse |
| 11 | import os |
kjellander | d2b63cf | 2017-06-30 03:04:59 -0700 | [diff] [blame] | 12 | import subprocess |
| 13 | import sys |
kjellander | d2b63cf | 2017-06-30 03:04:59 -0700 | [diff] [blame] | 14 | |
| 15 | |
| 16 | SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 17 | |
| 18 | # Chrome browsertests will throw away stderr; avoid that output gets lost. |
| 19 | sys.stderr = sys.stdout |
| 20 | |
| 21 | |
| 22 | def _ParseArgs(): |
| 23 | """Registers the command-line options.""" |
| 24 | usage = 'usage: %prog [options]' |
| 25 | parser = optparse.OptionParser(usage=usage) |
| 26 | |
| 27 | parser.add_option('--label', type='string', default='MY_TEST', |
| 28 | help=('Label of the test, used to identify different ' |
| 29 | 'tests. Default: %default')) |
| 30 | parser.add_option('--ref_video', type='string', |
| 31 | help='Reference video to compare with (YUV).') |
| 32 | parser.add_option('--test_video', type='string', |
| 33 | help=('Test video to be compared with the reference ' |
| 34 | 'video (YUV).')) |
| 35 | parser.add_option('--frame_analyzer', type='string', |
| 36 | help='Path to the frame analyzer executable.') |
| 37 | parser.add_option('--barcode_decoder', type='string', |
Magnus Jedvert | d65e143 | 2018-08-24 10:56:05 +0200 | [diff] [blame] | 38 | help=('DEPRECATED')) |
kjellander | d2b63cf | 2017-06-30 03:04:59 -0700 | [diff] [blame] | 39 | parser.add_option('--ffmpeg_path', type='string', |
Magnus Jedvert | d65e143 | 2018-08-24 10:56:05 +0200 | [diff] [blame] | 40 | help=('DEPRECATED')) |
kjellander | d2b63cf | 2017-06-30 03:04:59 -0700 | [diff] [blame] | 41 | parser.add_option('--zxing_path', type='string', |
Magnus Jedvert | d65e143 | 2018-08-24 10:56:05 +0200 | [diff] [blame] | 42 | help=('DEPRECATED')) |
kjellander | d2b63cf | 2017-06-30 03:04:59 -0700 | [diff] [blame] | 43 | parser.add_option('--stats_file_ref', type='string', default='stats_ref.txt', |
Magnus Jedvert | d65e143 | 2018-08-24 10:56:05 +0200 | [diff] [blame] | 44 | help=('DEPRECATED')) |
kjellander | d2b63cf | 2017-06-30 03:04:59 -0700 | [diff] [blame] | 45 | parser.add_option('--stats_file_test', type='string', |
Magnus Jedvert | d65e143 | 2018-08-24 10:56:05 +0200 | [diff] [blame] | 46 | help=('DEPRECATED')) |
kjellander | d2b63cf | 2017-06-30 03:04:59 -0700 | [diff] [blame] | 47 | parser.add_option('--stats_file', type='string', |
| 48 | help=('DEPRECATED')) |
| 49 | parser.add_option('--yuv_frame_width', type='int', default=640, |
Magnus Jedvert | d65e143 | 2018-08-24 10:56:05 +0200 | [diff] [blame] | 50 | help=('DEPRECATED')) |
kjellander | d2b63cf | 2017-06-30 03:04:59 -0700 | [diff] [blame] | 51 | parser.add_option('--yuv_frame_height', type='int', default=480, |
Magnus Jedvert | d65e143 | 2018-08-24 10:56:05 +0200 | [diff] [blame] | 52 | help=('DEPRECATED')) |
Edward Lemur | 2e5966b | 2018-01-30 15:33:02 +0100 | [diff] [blame] | 53 | parser.add_option('--chartjson_result_file', type='str', default=None, |
| 54 | help='Where to store perf results in chartjson format.') |
kjellander | d2b63cf | 2017-06-30 03:04:59 -0700 | [diff] [blame] | 55 | options, _ = parser.parse_args() |
| 56 | |
kjellander | d2b63cf | 2017-06-30 03:04:59 -0700 | [diff] [blame] | 57 | if not options.ref_video: |
| 58 | parser.error('You must provide a path to the reference video!') |
| 59 | if not os.path.exists(options.ref_video): |
| 60 | parser.error('Cannot find the reference video at %s' % options.ref_video) |
| 61 | |
| 62 | if not options.test_video: |
| 63 | parser.error('You must provide a path to the test video!') |
| 64 | if not os.path.exists(options.test_video): |
| 65 | parser.error('Cannot find the test video at %s' % options.test_video) |
| 66 | |
| 67 | if not options.frame_analyzer: |
| 68 | parser.error('You must provide the path to the frame analyzer executable!') |
| 69 | if not os.path.exists(options.frame_analyzer): |
| 70 | parser.error('Cannot find frame analyzer executable at %s!' % |
| 71 | options.frame_analyzer) |
| 72 | return options |
| 73 | |
| 74 | def _DevNull(): |
| 75 | """On Windows, sometimes the inherited stdin handle from the parent process |
| 76 | fails. Workaround this by passing null to stdin to the subprocesses commands. |
| 77 | This function can be used to create the null file handler. |
| 78 | """ |
| 79 | return open(os.devnull, 'r') |
| 80 | |
kjellander | d2b63cf | 2017-06-30 03:04:59 -0700 | [diff] [blame] | 81 | def main(): |
| 82 | """The main function. |
| 83 | |
| 84 | A simple invocation is: |
Magnus Jedvert | d65e143 | 2018-08-24 10:56:05 +0200 | [diff] [blame] | 85 | ./webrtc/rtc_tools/compare_videos.py |
kjellander | d2b63cf | 2017-06-30 03:04:59 -0700 | [diff] [blame] | 86 | --ref_video=<path_and_name_of_reference_video> |
| 87 | --test_video=<path_and_name_of_test_video> |
| 88 | --frame_analyzer=<path_and_name_of_the_frame_analyzer_executable> |
kjellander | d2b63cf | 2017-06-30 03:04:59 -0700 | [diff] [blame] | 89 | """ |
| 90 | options = _ParseArgs() |
| 91 | |
kjellander | d2b63cf | 2017-06-30 03:04:59 -0700 | [diff] [blame] | 92 | # Run frame analyzer to compare the videos and print output. |
| 93 | cmd = [ |
| 94 | options.frame_analyzer, |
| 95 | '--label=%s' % options.label, |
| 96 | '--reference_file=%s' % options.ref_video, |
| 97 | '--test_file=%s' % options.test_video, |
kjellander | d2b63cf | 2017-06-30 03:04:59 -0700 | [diff] [blame] | 98 | ] |
Edward Lemur | 2e5966b | 2018-01-30 15:33:02 +0100 | [diff] [blame] | 99 | if options.chartjson_result_file: |
| 100 | cmd.append('--chartjson_result_file=%s' % options.chartjson_result_file) |
kjellander | d2b63cf | 2017-06-30 03:04:59 -0700 | [diff] [blame] | 101 | frame_analyzer = subprocess.Popen(cmd, stdin=_DevNull(), |
| 102 | stdout=sys.stdout, stderr=sys.stderr) |
| 103 | frame_analyzer.wait() |
| 104 | if frame_analyzer.returncode != 0: |
| 105 | print 'Failed to run frame analyzer.' |
| 106 | return 1 |
| 107 | |
| 108 | return 0 |
| 109 | |
| 110 | if __name__ == '__main__': |
| 111 | sys.exit(main()) |