OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/python | |
2 # Copyright 2013 Google Inc. All Rights Reserved. | |
3 # | |
4 # Licensed under the Apache License, Version 2.0 (the "License"); | |
5 # you may not use this file except in compliance with the License. | |
6 # You may obtain a copy of the License at | |
7 # | |
8 # http://www.apache.org/licenses/LICENSE-2.0 | |
9 # | |
10 # Unless required by applicable law or agreed to in writing, software | |
11 # distributed under the License is distributed on an "AS IS" BASIS, | |
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 # See the License for the specific language governing permissions and | |
14 # limitations under the License. | |
15 | |
16 # This is a script that generates the content and HTML files for Media Source | |
scherkus (not reviewing)
2013/06/18 01:22:09
this is usually a """triple quote string containin
acolwell GONE FROM CHROMIUM
2013/06/18 16:33:45
Done.
| |
17 # codec config change LayoutTests. | |
18 import os | |
19 | |
20 duration = 2 | |
scherkus (not reviewing)
2013/06/18 01:22:09
constants are ALL_CAPS
acolwell GONE FROM CHROMIUM
2013/06/18 16:33:45
Done.
| |
21 formats = ['webm', 'mp4'] | |
22 encode_settings = [ | |
23 ## Video-only files | |
24 # Frame rate changes | |
25 { 'fs': '320x240', 'fr': 24, 'kfr': 8, 'c': '#ff0000', 'vbr': 128, 'abr': 0, ' asr': 0, 'ach': 0, 'afreq': 0 }, | |
26 { 'fs': '320x240', 'fr': 30, 'kfr': 10, 'c': '#ff0000', 'vbr': 128, 'abr': 0, 'asr': 0, 'ach': 0, 'afreq': 0 }, | |
27 # Frame size change | |
28 { 'fs': '640x480', 'fr': 30, 'kfr': 10, 'c': '#00ff00', 'vbr': 128, 'abr': 0, 'asr': 0, 'ach': 0, 'afreq': 0 }, | |
29 # Bitrate change | |
30 { 'fs': '320x240', 'fr': 30, 'kfr': 10, 'c': '#ff00ff', 'vbr': 256, 'abr': 0, 'asr': 0, 'ach': 0, 'afreq': 0 }, | |
31 | |
32 ## Audio-only files | |
33 # Bitrate/Codebook changes | |
34 { 'fs': '0x0', 'fr': 0, 'kfr': 0, 'c': '#000000', 'vbr': 0, 'abr': 128, 'asr': 44100, 'ach': 1, 'afreq': 2000 }, | |
35 { 'fs': '0x0', 'fr': 0, 'kfr': 0, 'c': '#000000', 'vbr': 0, 'abr': 192, 'asr': 44100, 'ach': 1, 'afreq': 4000 }, | |
36 | |
37 ## Audio-Video files | |
38 # Frame size change. | |
39 { 'fs': '320x240', 'fr': 30, 'kfr': 10, 'c': '#ff0000', 'vbr': 256, 'abr': 128 , 'asr': 44100, 'ach': 1, 'afreq': 2000 }, | |
40 { 'fs': '640x480', 'fr': 30, 'kfr': 10, 'c': '#00ff00', 'vbr': 256, 'abr': 128 , 'asr': 44100, 'ach': 1, 'afreq': 2000 }, | |
41 # Audio bitrate change. | |
42 { 'fs': '640x480', 'fr': 30, 'kfr': 10, 'c': '#00ff00', 'vbr': 256, 'abr': 192 , 'asr': 44100, 'ach': 1, 'afreq': 4000 }, | |
43 # Video bitrate change. | |
44 { 'fs': '640x480', 'fr': 30, 'kfr': 10, 'c': '#00ffff', 'vbr': 512, 'abr': 128 , 'asr': 44100, 'ach': 1, 'afreq': 2000 }, | |
45 ] | |
46 | |
47 config_change_tests = [ | |
48 ["v-framerate", 0, 1, "Tests %s video-only frame rate changes."], | |
49 ["v-framesize", 1, 2, "Tests %s video-only frame size changes."], | |
50 ["v-bitrate", 1, 3, "Tests %s video-only bitrate changes."], | |
51 ["a-bitrate", 4, 5, "Tests %s audio-only bitrate changes."], | |
52 ["av-framesize", 6, 7, "Tests %s frame size changes in multiplexed content."], | |
53 ["av-audio-bitrate", 7, 8, "Tests %s audio bitrate changes in multiplexed cont ent."], | |
54 ["av-video-bitrate", 7, 9, "Tests %s video bitrate changes in multiplexed cont ent."] | |
55 ]; | |
56 | |
57 encoding_ids = [] | |
58 | |
59 def Run(cmdline): | |
scherkus (not reviewing)
2013/06/18 01:22:09
the pythonic way of doing command lines is typical
acolwell GONE FROM CHROMIUM
2013/06/18 16:33:45
Done. Used += [...] form in most places since it s
| |
60 print cmdline | |
61 os.system(cmdline) | |
62 | |
63 def GenerateManifest(filename, format, has_audio, has_video): | |
64 # Create JSON manifest | |
scherkus (not reviewing)
2013/06/18 01:22:09
import json module?
acolwell GONE FROM CHROMIUM
2013/06/18 16:33:45
Done.
| |
65 manifest = "{\n" | |
66 manifest += " \"url\": \"" + media_filename + "\",\n" | |
67 | |
68 codecInfo = { | |
69 "mp4": { "audio": "mp4a.40.2", "video": "avc1.4D4001" }, | |
70 "webm": { "audio": "vorbis", "video": "vp8" } | |
71 } | |
72 | |
73 type = "" | |
74 if has_video : | |
75 type += "video" | |
76 else: | |
77 type += "audio" | |
78 | |
79 type += "/" + format + ";codecs=\\\"" | |
80 codecs = [] | |
81 if has_video: | |
82 codecs.append(codecInfo[format]["video"]); | |
83 | |
84 if has_audio: | |
85 codecs.append(codecInfo[format]["audio"]); | |
86 | |
87 type += ",".join(codecs) + "\\\"" | |
88 manifest += " \"type\": \"" + type + "\"\n" | |
89 manifest += "}\n" | |
90 f = open(filename, "wb") | |
91 f.write(manifest) | |
92 f.close() | |
93 | |
94 def GenerateTestHTML(format, config_change_tests, encoding_ids): | |
95 template = "<!DOCTYPE html>\n" | |
scherkus (not reviewing)
2013/06/18 01:22:09
this can be a """triple quote string""" and you ca
acolwell GONE FROM CHROMIUM
2013/06/18 16:33:45
Done.
| |
96 template += "<html>\n" | |
97 template += " <head>\n" | |
98 template += " <script src='/w3c/resources/testharness.js'></script>\n" | |
99 template += " <script src='/w3c/resources/testharnessreport.js'></scrip t>\n" | |
100 template += " <script src='mediasource-util.js'></script>\n" | |
101 template += " <script src='mediasource-config-changes.js'></script>\n" | |
102 template += " <link rel='stylesheet' href='/w3c/resources/testharness.c ss'>\n" | |
103 template += " </head>\n" | |
104 template += " <body>\n" | |
105 template += " <div id='log'></div>\n" | |
106 template += " <script>\n" | |
107 template += " mediasource_configchange_test('%s', '%s', '%s', '%s');\ n" | |
scherkus (not reviewing)
2013/06/18 01:22:09
given this is a pretty hefty string with a couple
acolwell GONE FROM CHROMIUM
2013/06/18 16:33:45
Done.
| |
108 template += " </script>\n" | |
109 template += " </body>\n" | |
110 template += "</html>\n" | |
111 for test_info in config_change_tests : | |
112 filename = "../../media-source/mediasource-config-change-%s-%s.html" % (form at, test_info[0]) | |
113 idA = encoding_ids[test_info[1]] | |
114 idB = encoding_ids[test_info[2]] | |
115 description = test_info[3] % (format) | |
116 html = template % (format, idA, idB, description) | |
117 f = open(filename, "wb") | |
118 f.write(html) | |
119 f.close() | |
120 | |
121 | |
122 for format in formats: | |
123 Run("mkdir " + format) | |
124 | |
125 for settings in encode_settings: | |
126 video_bitrate = settings['vbr'] | |
127 has_video = (video_bitrate > 0) | |
128 | |
129 audio_bitrate = settings['abr'] | |
130 has_audio = (audio_bitrate > 0) | |
131 bitrate = video_bitrate + audio_bitrate | |
132 | |
133 frame_size = settings['fs'] | |
134 frame_rate = settings['fr'] | |
135 keyframe_rate = settings['kfr'] | |
136 color = settings['c'] | |
137 | |
138 sample_rate = settings['asr'] | |
139 channels = settings['ach'] | |
140 frequency = settings['afreq'] | |
141 | |
142 cmdline = "ffmpeg -y" | |
143 | |
144 id_prefix = "" | |
145 id_params = ""; | |
146 if has_audio: | |
147 id_prefix += "a" | |
148 id_params += "-%sHz-%sch" % (sample_rate, channels) | |
149 | |
150 channel_layout = "FC" | |
151 sin_func = "sin(%s*2*PI*t)" % frequency | |
152 func = sin_func | |
153 if channels == 2: | |
154 channel_layout += "|BC" | |
155 func += "|" + sin_func | |
156 | |
157 cmdline += " -f lavfi -i aevalsrc=\"%s:s=%s:c=%s:d=%s\"" % (func, sample_r ate, channel_layout, duration) | |
158 | |
159 if has_video: | |
160 id_prefix += "v" | |
161 id_params += "-%s-%sfps-%skfr" % (frame_size, frame_rate, keyframe_rate) | |
162 | |
163 cmdline += " -f lavfi -i color=%s:duration=%s:size=%s:rate=%s" % (color, d uration, frame_size, frame_rate) | |
164 | |
165 if has_audio: | |
166 cmdline += " -b:a %sk" % audio_bitrate | |
167 | |
168 if has_video: | |
169 cmdline += " -b:v %sk" % video_bitrate | |
170 cmdline += " -keyint_min %s" % keyframe_rate | |
171 cmdline += " -g %s" % keyframe_rate | |
172 | |
173 cmdline += " -vf 'drawtext=fontfile=Mono:fontsize=32:text=Time\\\\:\\\\ %{ pts}" | |
174 cmdline += ",drawtext=fontfile=Mono:fontsize=32:y=32:text=Size\\\\:\\\\ %s " % (frame_size) | |
175 cmdline += ",drawtext=fontfile=Mono:fontsize=32:y=64:text=Bitrate\\\\:\\\\ %s" % (bitrate) | |
176 cmdline += ",drawtext=fontfile=Mono:fontsize=32:y=96:text=FrameRate\\\\:\\ \\ %s" % (frame_rate) | |
177 cmdline += ",drawtext=fontfile=Mono:fontsize=32:y=128:text=KeyFrameRate\\\ \:\\\\ %s" % (keyframe_rate) | |
178 | |
179 if has_audio: | |
180 cmdline += ",drawtext=fontfile=Mono:fontsize=32:y=160:text=SampleRate\\\ \:\\\\ %s" % (sample_rate) | |
181 cmdline += ",drawtext=fontfile=Mono:fontsize=32:y=192:text=Channels\\\\: \\\\ %s" % (channels) | |
182 | |
183 cmdline += "'" | |
184 | |
185 encoding_id = "%s-%sk%s" % (id_prefix, bitrate, id_params) | |
186 | |
187 if len(encoding_ids) < len(encode_settings) : | |
scherkus (not reviewing)
2013/06/18 01:22:09
remove space before :
acolwell GONE FROM CHROMIUM
2013/06/18 16:33:45
Done.
| |
188 encoding_ids.append(encoding_id) | |
189 | |
190 filename_base = "%s/test-%s" % (format, encoding_id) | |
191 media_filename = filename_base + "." + format | |
192 manifest_filename = filename_base + "-manifest.json" | |
193 | |
194 cmdline += " " + media_filename | |
195 Run(cmdline) | |
196 | |
197 # Remux file so it conforms to MSE bytestream requirements. | |
198 if format == "webm": | |
199 tmp_filename = media_filename + ".tmp" | |
200 Run("mse_webm_remuxer " + media_filename + " " + tmp_filename) | |
201 Run("mv " + tmp_filename + " " + media_filename) | |
202 elif format == "mp4": | |
203 Run("MP4Box -dash 250 -rap " + media_filename) | |
204 Run("mv " + filename_base + "_dash.mp4" + " " + media_filename) | |
205 Run("rm " + filename_base + "_dash.mpd") | |
206 | |
207 GenerateManifest(manifest_filename, format, has_audio, has_video) | |
208 | |
209 GenerateTestHTML(format, config_change_tests, encoding_ids) | |
OLD | NEW |