blob: afdd6a467b85a7c67fb41ed3ed0ef740b6be3d3c [file] [log] [blame]
kjellander@webrtc.orga6ff8452013-05-14 09:43:04 +00001#!/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
12import subprocess
13import sys
14
15
16SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
17
phoglund@webrtc.org84002462013-07-29 11:01:03 +000018# Chrome browsertests will throw away stderr; avoid that output gets lost.
19sys.stderr = sys.stdout
20
kjellander@webrtc.orga6ff8452013-05-14 09:43:04 +000021
22def _ParseArgs():
23 """Registers the command-line options."""
24 usage = 'usage: %prog [options]'
25 parser = optparse.OptionParser(usage=usage)
26
kjellander@webrtc.orgf880f862013-09-10 12:10:01 +000027 parser.add_option('--label', type='string', default="MY_TEST",
28 help=('Label of the test, used to identify different '
29 'tests. Default: %default'))
kjellander@webrtc.orga6ff8452013-05-14 09:43:04 +000030 parser.add_option('--ref_video', type='string',
31 help='Reference video to compare with (YUV).')
32 parser.add_option('--test_video', type='string',
kjellander@webrtc.orgf880f862013-09-10 12:10:01 +000033 help=('Test video to be compared with the reference '
kjellander@webrtc.orga6ff8452013-05-14 09:43:04 +000034 'video (YUV).'))
35 parser.add_option('--frame_analyzer', type='string',
36 help='Path to the frame analyzer executable.')
37 parser.add_option('--stats_file', type='string', default='stats.txt',
38 help=('Path to the temporary stats file to be created and '
39 'used. Default: %default'))
40 parser.add_option('--yuv_frame_width', type='int', default=640,
41 help='Width of the YUV file\'s frames. Default: %default')
42 parser.add_option('--yuv_frame_height', type='int', default=480,
43 help='Height of the YUV file\'s frames. Default: %default')
44 options, _args = parser.parse_args()
45
46 if not options.ref_video:
47 parser.error('You must provide a path to the reference video!')
48 if not os.path.exists(options.ref_video):
49 parser.error('Cannot find the reference video at %s' % options.ref_video)
50
51 if not options.test_video:
52 parser.error('You must provide a path to the test video!')
53 if not os.path.exists(options.test_video):
54 parser.error('Cannot find the test video at %s' % options.test_video)
55
56 if not options.frame_analyzer:
57 parser.error('You must provide the path to the frame analyzer executable!')
58 if not os.path.exists(options.frame_analyzer):
59 parser.error('Cannot find frame analyzer executable at %s!' %
60 options.frame_analyzer)
61 return options
62
63
64def main():
65 """The main function.
66
67 A simple invocation is:
68 ./webrtc/tools/barcode_tools/compare_videos.py
69 --ref_video=<path_and_name_of_reference_video>
70 --test_video=<path_and_name_of_test_video>
71 --frame_analyzer=<path_and_name_of_the_frame_analyzer_executable>
72
73 Notice that the prerequisites for barcode_decoder.py also applies to this
74 script. The means the following executables have to be available in the PATH:
75 * zxing
76 * ffmpeg
77 """
78 options = _ParseArgs()
79
80 # Run barcode decoder on the test video to identify frame numbers.
81 path_to_decoder = os.path.join(SCRIPT_DIR, 'barcode_tools',
82 'barcode_decoder.py')
83 cmd = [
84 sys.executable,
85 path_to_decoder,
86 '--yuv_file=%s' % options.test_video,
87 '--yuv_frame_width=%d' % options.yuv_frame_width,
88 '--yuv_frame_height=%d' % options.yuv_frame_height,
89 '--stats_file=%s' % options.stats_file,
90 ]
91 barcode_decoder = subprocess.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr)
92 barcode_decoder.wait()
93 if barcode_decoder.returncode != 0:
phoglund@webrtc.org84002462013-07-29 11:01:03 +000094 print 'Failed to run barcode decoder script.'
kjellander@webrtc.orga6ff8452013-05-14 09:43:04 +000095 return 1
96
97 # Run frame analyzer to compare the videos and print output.
98 cmd = [
99 options.frame_analyzer,
kjellander@webrtc.orgf880f862013-09-10 12:10:01 +0000100 '--label=%s' % options.label,
kjellander@webrtc.orga6ff8452013-05-14 09:43:04 +0000101 '--reference_file=%s' % options.ref_video,
phoglund@webrtc.org7bcc7e32013-06-27 14:05:26 +0000102 '--test_file=%s' % options.test_video,
kjellander@webrtc.orga6ff8452013-05-14 09:43:04 +0000103 '--stats_file=%s' % options.stats_file,
104 '--width=%d' % options.yuv_frame_width,
105 '--height=%d' % options.yuv_frame_height,
106 ]
107 frame_analyzer = subprocess.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr)
108 frame_analyzer.wait()
109 if frame_analyzer.returncode != 0:
phoglund@webrtc.org84002462013-07-29 11:01:03 +0000110 print 'Failed to run frame analyzer.'
kjellander@webrtc.orga6ff8452013-05-14 09:43:04 +0000111 return 1
112
113 return 0
114
115if __name__ == '__main__':
116 sys.exit(main())