blob: 4748e81f78392f93fbb72c069f47d48892427ce9 [file] [log] [blame]
kjellanderd2b63cf2017-06-30 03:04:59 -07001#!/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
10import optparse
11import os
kjellanderd2b63cf2017-06-30 03:04:59 -070012import subprocess
13import sys
kjellanderd2b63cf2017-06-30 03:04:59 -070014
15
16SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
17
18# Chrome browsertests will throw away stderr; avoid that output gets lost.
19sys.stderr = sys.stdout
20
21
22def _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 Jedvertd65e1432018-08-24 10:56:05 +020038 help=('DEPRECATED'))
kjellanderd2b63cf2017-06-30 03:04:59 -070039 parser.add_option('--ffmpeg_path', type='string',
Magnus Jedvertd65e1432018-08-24 10:56:05 +020040 help=('DEPRECATED'))
kjellanderd2b63cf2017-06-30 03:04:59 -070041 parser.add_option('--zxing_path', type='string',
Magnus Jedvertd65e1432018-08-24 10:56:05 +020042 help=('DEPRECATED'))
kjellanderd2b63cf2017-06-30 03:04:59 -070043 parser.add_option('--stats_file_ref', type='string', default='stats_ref.txt',
Magnus Jedvertd65e1432018-08-24 10:56:05 +020044 help=('DEPRECATED'))
kjellanderd2b63cf2017-06-30 03:04:59 -070045 parser.add_option('--stats_file_test', type='string',
Magnus Jedvertd65e1432018-08-24 10:56:05 +020046 help=('DEPRECATED'))
kjellanderd2b63cf2017-06-30 03:04:59 -070047 parser.add_option('--stats_file', type='string',
48 help=('DEPRECATED'))
49 parser.add_option('--yuv_frame_width', type='int', default=640,
Magnus Jedvertd65e1432018-08-24 10:56:05 +020050 help=('DEPRECATED'))
kjellanderd2b63cf2017-06-30 03:04:59 -070051 parser.add_option('--yuv_frame_height', type='int', default=480,
Magnus Jedvertd65e1432018-08-24 10:56:05 +020052 help=('DEPRECATED'))
Edward Lemur2e5966b2018-01-30 15:33:02 +010053 parser.add_option('--chartjson_result_file', type='str', default=None,
54 help='Where to store perf results in chartjson format.')
kjellanderd2b63cf2017-06-30 03:04:59 -070055 options, _ = parser.parse_args()
56
kjellanderd2b63cf2017-06-30 03:04:59 -070057 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
74def _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
kjellanderd2b63cf2017-06-30 03:04:59 -070081def main():
82 """The main function.
83
84 A simple invocation is:
Magnus Jedvertd65e1432018-08-24 10:56:05 +020085 ./webrtc/rtc_tools/compare_videos.py
kjellanderd2b63cf2017-06-30 03:04:59 -070086 --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>
kjellanderd2b63cf2017-06-30 03:04:59 -070089 """
90 options = _ParseArgs()
91
kjellanderd2b63cf2017-06-30 03:04:59 -070092 # 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,
kjellanderd2b63cf2017-06-30 03:04:59 -070098 ]
Edward Lemur2e5966b2018-01-30 15:33:02 +010099 if options.chartjson_result_file:
100 cmd.append('--chartjson_result_file=%s' % options.chartjson_result_file)
kjellanderd2b63cf2017-06-30 03:04:59 -0700101 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
110if __name__ == '__main__':
111 sys.exit(main())