OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/python | |
2 # Copyright (C) 2013 Google Inc. All rights reserved. | |
3 # | |
4 # Redistribution and use in source and binary forms, with or without | |
5 # modification, are permitted provided that the following conditions are | |
6 # met: | |
7 # | |
8 # * Redistributions of source code must retain the above copyright | |
9 # notice, this list of conditions and the following disclaimer. | |
10 # * Redistributions in binary form must reproduce the above | |
11 # copyright notice, this list of conditions and the following disclaimer | |
12 # in the documentation and/or other materials provided with the | |
13 # distribution. | |
14 # * Neither the name of Google Inc. nor the names of its | |
15 # contributors may be used to endorse or promote products derived from | |
16 # this software without specific prior written permission. | |
17 # | |
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 | |
30 """ | |
31 This is a script that generates the content and HTML files for Media Source | |
32 codec config change LayoutTests. | |
33 """ | |
34 import json | |
35 import os | |
36 | |
37 DURATION = 2 | |
38 MEDIA_FORMATS = ['webm', 'mp4'] | |
39 ENCODE_SETTINGS = [ | |
40 ## Video-only files | |
41 # Frame rate changes | |
42 { 'fs': '320x240', 'fr': 24, 'kfr': 8, 'c': '#ff0000', 'vbr': 128, 'abr': 0, 'asr': 0, 'ach': 0, 'afreq': 0 }, | |
scherkus (not reviewing)
2013/06/19 00:10:30
PEP-8 lists extraneous whitespace inside/around {
acolwell GONE FROM CHROMIUM
2013/06/19 00:48:03
Done.
| |
43 { 'fs': '320x240', 'fr': 30, 'kfr': 10, 'c': '#ff0000', 'vbr': 128, 'abr': 0 , 'asr': 0, 'ach': 0, 'afreq': 0 }, | |
44 # Frame size change | |
45 { 'fs': '640x480', 'fr': 30, 'kfr': 10, 'c': '#00ff00', 'vbr': 128, 'abr': 0 , 'asr': 0, 'ach': 0, 'afreq': 0 }, | |
46 # Bitrate change | |
47 { 'fs': '320x240', 'fr': 30, 'kfr': 10, 'c': '#ff00ff', 'vbr': 256, 'abr': 0 , 'asr': 0, 'ach': 0, 'afreq': 0 }, | |
48 | |
49 ## Audio-only files | |
50 # Bitrate/Codebook changes | |
51 { 'fs': '0x0', 'fr': 0, 'kfr': 0, 'c': '#000000', 'vbr': 0, 'abr': 128, 'asr ': 44100, 'ach': 1, 'afreq': 2000 }, | |
52 { 'fs': '0x0', 'fr': 0, 'kfr': 0, 'c': '#000000', 'vbr': 0, 'abr': 192, 'asr ': 44100, 'ach': 1, 'afreq': 4000 }, | |
53 | |
54 ## Audio-Video files | |
55 # Frame size change. | |
56 { 'fs': '320x240', 'fr': 30, 'kfr': 10, 'c': '#ff0000', 'vbr': 256, 'abr': 1 28, 'asr': 44100, 'ach': 1, 'afreq': 2000 }, | |
57 { 'fs': '640x480', 'fr': 30, 'kfr': 10, 'c': '#00ff00', 'vbr': 256, 'abr': 1 28, 'asr': 44100, 'ach': 1, 'afreq': 2000 }, | |
58 # Audio bitrate change. | |
59 { 'fs': '640x480', 'fr': 30, 'kfr': 10, 'c': '#00ff00', 'vbr': 256, 'abr': 1 92, 'asr': 44100, 'ach': 1, 'afreq': 4000 }, | |
60 # Video bitrate change. | |
61 { 'fs': '640x480', 'fr': 30, 'kfr': 10, 'c': '#00ffff', 'vbr': 512, 'abr': 1 28, 'asr': 44100, 'ach': 1, 'afreq': 2000 }, | |
62 ] | |
63 | |
64 CONFIG_CHANGE_TESTS = [ | |
65 ["v-framerate", 0, 1, "Tests %s video-only frame rate changes."], | |
66 ["v-framesize", 1, 2, "Tests %s video-only frame size changes."], | |
67 ["v-bitrate", 1, 3, "Tests %s video-only bitrate changes."], | |
68 ["a-bitrate", 4, 5, "Tests %s audio-only bitrate changes."], | |
69 ["av-framesize", 6, 7, "Tests %s frame size changes in multiplexed content." ], | |
70 ["av-audio-bitrate", 7, 8, "Tests %s audio bitrate changes in multiplexed co ntent."], | |
71 ["av-video-bitrate", 7, 9, "Tests %s video bitrate changes in multiplexed co ntent."] | |
72 ] | |
73 | |
74 def Run(cmd_line): | |
scherkus (not reviewing)
2013/06/19 00:10:30
PEP-8 says function names are unix_hacker not Came
acolwell GONE FROM CHROMIUM
2013/06/19 00:48:03
Done.
| |
75 cmd_line_str = " ".join(cmd_line) | |
76 print cmd_line_str | |
scherkus (not reviewing)
2013/06/19 00:10:30
intentional or for debugging?
acolwell GONE FROM CHROMIUM
2013/06/19 00:48:03
debugging. Removed.
| |
77 os.system(cmd_line_str) | |
78 | |
79 def GenerateManifest(filename, media_filename, media_format, has_audio, has_vide o): | |
80 codecInfo = { | |
81 "mp4": { "audio": "mp4a.40.2", "video": "avc1.4D4001" }, | |
82 "webm": { "audio": "vorbis", "video": "vp8" } | |
83 } | |
84 | |
85 majorType = "audio" | |
86 if has_video : | |
scherkus (not reviewing)
2013/06/19 00:10:30
remove space before :
acolwell GONE FROM CHROMIUM
2013/06/19 00:48:03
Done.
| |
87 majorType = "video" | |
88 | |
89 codecs = [] | |
90 if has_video: | |
91 codecs.append(codecInfo[media_format]["video"]) | |
92 | |
93 if has_audio: | |
94 codecs.append(codecInfo[media_format]["audio"]) | |
95 | |
96 mimetype = "%s/%s;codecs=\"%s\"" % (majorType, media_format, ",".join(codecs )) | |
97 | |
98 manifest = { 'url': media_filename, 'type' : mimetype} | |
99 | |
100 f = open(filename, "wb") | |
101 f.write(json.dumps(manifest, indent=4, separators=(',', ': '))) | |
102 f.close() | |
103 | |
104 def GenerateTestHTML(media_format, config_change_tests, encoding_ids): | |
105 template = """<!DOCTYPE html> | |
scherkus (not reviewing)
2013/06/19 00:10:30
make this a module-level constant?
acolwell GONE FROM CHROMIUM
2013/06/19 00:48:03
Done.
| |
106 <html> | |
107 <head> | |
108 <script src="/w3c/resources/testharness.js"></script> | |
109 <script src="/w3c/resources/testharnessreport.js"></script> | |
110 <script src="mediasource-util.js"></script> | |
111 <script src="mediasource-config-changes.js"></script> | |
112 <link rel="stylesheet" href="/w3c/resources/testharness.css"> | |
113 </head> | |
114 <body> | |
115 <div id="log"></div> | |
116 <script> | |
117 mediaSourceConfigChangeTest("%(media_format)s", "%(idA)s", "%(idB)s" , "%(description)s"); | |
118 </script> | |
119 </body> | |
120 </html> | |
121 """ | |
122 for test_info in config_change_tests : | |
scherkus (not reviewing)
2013/06/19 00:10:30
remove space
acolwell GONE FROM CHROMIUM
2013/06/19 00:48:03
Done.
| |
123 filename = "../../media-source/mediasource-config-change-%s-%s.html" % ( media_format, test_info[0]) | |
124 html = template % { 'media_format': media_format, | |
125 'idA': encoding_ids[test_info[1]], | |
126 'idB': encoding_ids[test_info[2]], | |
127 'description': test_info[3] % (media_format) } | |
128 f = open(filename, "wb") | |
129 f.write(html) | |
130 f.close() | |
131 | |
132 | |
133 def GenerateContent(): | |
134 encoding_ids = [] | |
135 | |
136 for media_format in MEDIA_FORMATS: | |
137 Run(["mkdir ", media_format]) | |
138 | |
139 for settings in ENCODE_SETTINGS: | |
140 video_bitrate = settings['vbr'] | |
141 has_video = (video_bitrate > 0) | |
142 | |
143 audio_bitrate = settings['abr'] | |
144 has_audio = (audio_bitrate > 0) | |
145 bitrate = video_bitrate + audio_bitrate | |
146 | |
147 frame_size = settings['fs'] | |
148 frame_rate = settings['fr'] | |
149 keyframe_rate = settings['kfr'] | |
150 color = settings['c'] | |
151 | |
152 sample_rate = settings['asr'] | |
153 channels = settings['ach'] | |
154 frequency = settings['afreq'] | |
155 | |
156 cmdline = ["ffmpeg", "-y"] | |
157 | |
158 id_prefix = "" | |
159 id_params = "" | |
160 if has_audio: | |
161 id_prefix += "a" | |
162 id_params += "-%sHz-%sch" % (sample_rate, channels) | |
163 | |
164 channel_layout = "FC" | |
165 sin_func = "sin(%s*2*PI*t)" % frequency | |
166 func = sin_func | |
167 if channels == 2: | |
168 channel_layout += "|BC" | |
169 func += "|" + sin_func | |
170 | |
171 cmdline += ["-f", "lavfi", "-i", "aevalsrc=\"%s:s=%s:c=%s:d=%s\" " % (func, sample_rate, channel_layout, DURATION)] | |
172 | |
173 if has_video: | |
174 id_prefix += "v" | |
175 id_params += "-%s-%sfps-%skfr" % (frame_size, frame_rate, keyfra me_rate) | |
176 | |
177 cmdline += ["-f", "lavfi", "-i", "color=%s:duration=%s:size=%s:r ate=%s" % (color, DURATION, frame_size, frame_rate)] | |
178 | |
179 if has_audio: | |
180 cmdline += ["-b:a", "%sk" % audio_bitrate] | |
181 | |
182 if has_video: | |
183 cmdline += ["-b:v", "%sk" % video_bitrate] | |
184 cmdline += ["-keyint_min", "%s" % keyframe_rate] | |
185 cmdline += ["-g", "%s" % keyframe_rate] | |
186 | |
187 | |
188 textOverlayInfo = "'drawtext=fontfile=Mono:fontsize=32:text=Time \\\\:\\\\ %{pts}" | |
189 textOverlayInfo += ",drawtext=fontfile=Mono:fontsize=32:y=32:tex t=Size\\\\:\\\\ %s" % (frame_size) | |
190 textOverlayInfo += ",drawtext=fontfile=Mono:fontsize=32:y=64:tex t=Bitrate\\\\:\\\\ %s" % (bitrate) | |
191 textOverlayInfo += ",drawtext=fontfile=Mono:fontsize=32:y=96:tex t=FrameRate\\\\:\\\\ %s" % (frame_rate) | |
192 textOverlayInfo += ",drawtext=fontfile=Mono:fontsize=32:y=128:te xt=KeyFrameRate\\\\:\\\\ %s" % (keyframe_rate) | |
193 | |
194 if has_audio: | |
195 textOverlayInfo += ",drawtext=fontfile=Mono:fontsize=32:y=16 0:text=SampleRate\\\\:\\\\ %s" % (sample_rate) | |
196 textOverlayInfo += ",drawtext=fontfile=Mono:fontsize=32:y=19 2:text=Channels\\\\:\\\\ %s" % (channels) | |
197 | |
198 textOverlayInfo += "'" | |
199 cmdline += ["-vf", textOverlayInfo] | |
200 | |
201 encoding_id = "%s-%sk%s" % (id_prefix, bitrate, id_params) | |
202 | |
203 if len(encoding_ids) < len(ENCODE_SETTINGS): | |
204 encoding_ids.append(encoding_id) | |
205 | |
206 filename_base = "%s/test-%s" % (media_format, encoding_id) | |
207 media_filename = filename_base + "." + media_format | |
208 manifest_filename = filename_base + "-manifest.json" | |
209 | |
210 cmdline.append(media_filename) | |
211 Run(cmdline) | |
212 | |
213 # Remux file so it conforms to MSE bytestream requirements. | |
214 if media_format == "webm": | |
215 tmp_filename = media_filename + ".tmp" | |
216 Run(["mse_webm_remuxer", media_filename, tmp_filename]) | |
217 Run(["mv", tmp_filename, media_filename]) | |
218 elif media_format == "mp4": | |
219 Run(["MP4Box", "-dash", "250", "-rap", media_filename]) | |
220 Run(["mv", filename_base + "_dash.mp4", media_filename]) | |
221 Run(["rm", filename_base + "_dash.mpd"]) | |
222 | |
223 GenerateManifest(manifest_filename, media_filename, media_format, ha s_audio, has_video) | |
224 GenerateTestHTML(media_format, CONFIG_CHANGE_TESTS, encoding_ids) | |
225 | |
226 GenerateContent() | |
scherkus (not reviewing)
2013/06/19 00:10:30
isn't this usually guarded by a check for __main__
acolwell GONE FROM CHROMIUM
2013/06/19 00:48:03
Done. Copied what was in Tools/Scripts/check-blink
| |
OLD | NEW |