blob: 0e0a4f65926b2b523acfca3b908b0062c336e7cc [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
27 parser.add_option('--ref_video', type='string',
28 help='Reference video to compare with (YUV).')
29 parser.add_option('--test_video', type='string',
30 help=('Test video to be comared with the reference '
31 'video (YUV).'))
32 parser.add_option('--frame_analyzer', type='string',
33 help='Path to the frame analyzer executable.')
34 parser.add_option('--stats_file', type='string', default='stats.txt',
35 help=('Path to the temporary stats file to be created and '
36 'used. Default: %default'))
37 parser.add_option('--yuv_frame_width', type='int', default=640,
38 help='Width of the YUV file\'s frames. Default: %default')
39 parser.add_option('--yuv_frame_height', type='int', default=480,
40 help='Height of the YUV file\'s frames. Default: %default')
41 options, _args = parser.parse_args()
42
43 if not options.ref_video:
44 parser.error('You must provide a path to the reference video!')
45 if not os.path.exists(options.ref_video):
46 parser.error('Cannot find the reference video at %s' % options.ref_video)
47
48 if not options.test_video:
49 parser.error('You must provide a path to the test video!')
50 if not os.path.exists(options.test_video):
51 parser.error('Cannot find the test video at %s' % options.test_video)
52
53 if not options.frame_analyzer:
54 parser.error('You must provide the path to the frame analyzer executable!')
55 if not os.path.exists(options.frame_analyzer):
56 parser.error('Cannot find frame analyzer executable at %s!' %
57 options.frame_analyzer)
58 return options
59
60
61def main():
62 """The main function.
63
64 A simple invocation is:
65 ./webrtc/tools/barcode_tools/compare_videos.py
66 --ref_video=<path_and_name_of_reference_video>
67 --test_video=<path_and_name_of_test_video>
68 --frame_analyzer=<path_and_name_of_the_frame_analyzer_executable>
69
70 Notice that the prerequisites for barcode_decoder.py also applies to this
71 script. The means the following executables have to be available in the PATH:
72 * zxing
73 * ffmpeg
74 """
75 options = _ParseArgs()
76
77 # Run barcode decoder on the test video to identify frame numbers.
78 path_to_decoder = os.path.join(SCRIPT_DIR, 'barcode_tools',
79 'barcode_decoder.py')
80 cmd = [
81 sys.executable,
82 path_to_decoder,
83 '--yuv_file=%s' % options.test_video,
84 '--yuv_frame_width=%d' % options.yuv_frame_width,
85 '--yuv_frame_height=%d' % options.yuv_frame_height,
86 '--stats_file=%s' % options.stats_file,
87 ]
88 barcode_decoder = subprocess.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr)
89 barcode_decoder.wait()
90 if barcode_decoder.returncode != 0:
phoglund@webrtc.org84002462013-07-29 11:01:03 +000091 print 'Failed to run barcode decoder script.'
kjellander@webrtc.orga6ff8452013-05-14 09:43:04 +000092 return 1
93
94 # Run frame analyzer to compare the videos and print output.
95 cmd = [
96 options.frame_analyzer,
97 '--reference_file=%s' % options.ref_video,
phoglund@webrtc.org7bcc7e32013-06-27 14:05:26 +000098 '--test_file=%s' % options.test_video,
kjellander@webrtc.orga6ff8452013-05-14 09:43:04 +000099 '--stats_file=%s' % options.stats_file,
100 '--width=%d' % options.yuv_frame_width,
101 '--height=%d' % options.yuv_frame_height,
102 ]
103 frame_analyzer = subprocess.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr)
104 frame_analyzer.wait()
105 if frame_analyzer.returncode != 0:
phoglund@webrtc.org84002462013-07-29 11:01:03 +0000106 print 'Failed to run frame analyzer.'
kjellander@webrtc.orga6ff8452013-05-14 09:43:04 +0000107 return 1
108
109 return 0
110
111if __name__ == '__main__':
112 sys.exit(main())