Chromium Code Reviews| 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"); | |
|
adamk
2013/06/18 21:54:23
Seems like this should use the standard Blink lice
acolwell GONE FROM CHROMIUM
2013/06/18 23:00:18
Oops. Done. This is all my own code. I just had an
| |
| 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 """ | |
| 17 This is a script that generates the content and HTML files for Media Source | |
| 18 codec config change LayoutTests. | |
| 19 """ | |
| 20 import json | |
| 21 import os | |
| 22 | |
| 23 DURATION = 2 | |
| 24 FORMATS = ['webm', 'mp4'] | |
| 25 ENCODE_SETTINGS = [ | |
| 26 ## Video-only files | |
| 27 # Frame rate changes | |
| 28 { 'fs': '320x240', 'fr': 24, 'kfr': 8, 'c': '#ff0000', 'vbr': 128, 'abr': 0, ' asr': 0, 'ach': 0, 'afreq': 0 }, | |
| 29 { 'fs': '320x240', 'fr': 30, 'kfr': 10, 'c': '#ff0000', 'vbr': 128, 'abr': 0, 'asr': 0, 'ach': 0, 'afreq': 0 }, | |
| 30 # Frame size change | |
| 31 { 'fs': '640x480', 'fr': 30, 'kfr': 10, 'c': '#00ff00', 'vbr': 128, 'abr': 0, 'asr': 0, 'ach': 0, 'afreq': 0 }, | |
| 32 # Bitrate change | |
| 33 { 'fs': '320x240', 'fr': 30, 'kfr': 10, 'c': '#ff00ff', 'vbr': 256, 'abr': 0, 'asr': 0, 'ach': 0, 'afreq': 0 }, | |
| 34 | |
| 35 ## Audio-only files | |
| 36 # Bitrate/Codebook changes | |
| 37 { 'fs': '0x0', 'fr': 0, 'kfr': 0, 'c': '#000000', 'vbr': 0, 'abr': 128, 'asr': 44100, 'ach': 1, 'afreq': 2000 }, | |
| 38 { 'fs': '0x0', 'fr': 0, 'kfr': 0, 'c': '#000000', 'vbr': 0, 'abr': 192, 'asr': 44100, 'ach': 1, 'afreq': 4000 }, | |
| 39 | |
| 40 ## Audio-Video files | |
| 41 # Frame size change. | |
| 42 { 'fs': '320x240', 'fr': 30, 'kfr': 10, 'c': '#ff0000', 'vbr': 256, 'abr': 128 , 'asr': 44100, 'ach': 1, 'afreq': 2000 }, | |
| 43 { 'fs': '640x480', 'fr': 30, 'kfr': 10, 'c': '#00ff00', 'vbr': 256, 'abr': 128 , 'asr': 44100, 'ach': 1, 'afreq': 2000 }, | |
| 44 # Audio bitrate change. | |
| 45 { 'fs': '640x480', 'fr': 30, 'kfr': 10, 'c': '#00ff00', 'vbr': 256, 'abr': 192 , 'asr': 44100, 'ach': 1, 'afreq': 4000 }, | |
| 46 # Video bitrate change. | |
| 47 { 'fs': '640x480', 'fr': 30, 'kfr': 10, 'c': '#00ffff', 'vbr': 512, 'abr': 128 , 'asr': 44100, 'ach': 1, 'afreq': 2000 }, | |
| 48 ] | |
| 49 | |
| 50 CONFIG_CHANGE_TESTS = [ | |
| 51 ["v-framerate", 0, 1, "Tests %s video-only frame rate changes."], | |
| 52 ["v-framesize", 1, 2, "Tests %s video-only frame size changes."], | |
| 53 ["v-bitrate", 1, 3, "Tests %s video-only bitrate changes."], | |
| 54 ["a-bitrate", 4, 5, "Tests %s audio-only bitrate changes."], | |
| 55 ["av-framesize", 6, 7, "Tests %s frame size changes in multiplexed content."], | |
| 56 ["av-audio-bitrate", 7, 8, "Tests %s audio bitrate changes in multiplexed cont ent."], | |
| 57 ["av-video-bitrate", 7, 9, "Tests %s video bitrate changes in multiplexed cont ent."] | |
| 58 ]; | |
| 59 | |
| 60 encoding_ids = [] | |
| 61 | |
| 62 def Run(cmdline): | |
| 63 cmdlineStr = " ".join(cmdline) | |
| 64 print cmdlineStr | |
| 65 os.system(cmdlineStr) | |
| 66 | |
| 67 def GenerateManifest(filename, format, has_audio, has_video): | |
| 68 | |
| 69 codecInfo = { | |
| 70 "mp4": { "audio": "mp4a.40.2", "video": "avc1.4D4001" }, | |
| 71 "webm": { "audio": "vorbis", "video": "vp8" } | |
| 72 } | |
| 73 | |
| 74 majorType = "audio" | |
| 75 if has_video : | |
| 76 majorType = "video" | |
| 77 | |
| 78 codecs = [] | |
| 79 if has_video: | |
| 80 codecs.append(codecInfo[format]["video"]); | |
| 81 | |
| 82 if has_audio: | |
| 83 codecs.append(codecInfo[format]["audio"]); | |
| 84 | |
| 85 type = "%s/%s;codecs=\"%s\"" % (majorType, format, ",".join(codecs)) | |
| 86 | |
| 87 manifest = { 'url': media_filename, 'type' : type} | |
| 88 | |
| 89 f = open(filename, "wb") | |
| 90 f.write(json.dumps(manifest, indent=4, separators=(',', ': '))) | |
| 91 f.close() | |
| 92 | |
| 93 def GenerateTestHTML(format, config_change_tests, encoding_ids): | |
| 94 template = """<!DOCTYPE html> | |
| 95 <html> | |
| 96 <head> | |
| 97 <script src="/w3c/resources/testharness.js"></script> | |
| 98 <script src="/w3c/resources/testharnessreport.js"></script> | |
| 99 <script src="mediasource-util.js"></script> | |
| 100 <script src="mediasource-config-changes.js"></script> | |
| 101 <link rel="stylesheet" href="/w3c/resources/testharness.css"> | |
| 102 </head> | |
| 103 <body> | |
| 104 <div id="log"></div> | |
| 105 <script> | |
| 106 mediasource_configchange_test("%(format)s", "%(idA)s", "%(idB)s", "% (description)s"); | |
| 107 </script> | |
| 108 </body> | |
| 109 </html> | |
| 110 """ | |
| 111 for test_info in config_change_tests : | |
| 112 filename = "../../media-source/mediasource-config-change-%s-%s.html" % (form at, test_info[0]) | |
| 113 html = template % {'format': format, | |
| 114 'idA': encoding_ids[test_info[1]], | |
| 115 'idB': encoding_ids[test_info[2]], | |
| 116 'description': test_info[3] % (format)} | |
| 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_rate, 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, DURATION, 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 | |
| 174 textOverlayInfo = "'drawtext=fontfile=Mono:fontsize=32:text=Time\\\\:\\\\ %{pts}" | |
| 175 textOverlayInfo += ",drawtext=fontfile=Mono:fontsize=32:y=32:text=Size\\\\ :\\\\ %s" % (frame_size) | |
| 176 textOverlayInfo += ",drawtext=fontfile=Mono:fontsize=32:y=64:text=Bitrate\ \\\:\\\\ %s" % (bitrate) | |
| 177 textOverlayInfo += ",drawtext=fontfile=Mono:fontsize=32:y=96:text=FrameRat e\\\\:\\\\ %s" % (frame_rate) | |
| 178 textOverlayInfo += ",drawtext=fontfile=Mono:fontsize=32:y=128:text=KeyFram eRate\\\\:\\\\ %s" % (keyframe_rate) | |
| 179 | |
| 180 if has_audio: | |
| 181 textOverlayInfo += ",drawtext=fontfile=Mono:fontsize=32:y=160:text=Sampl eRate\\\\:\\\\ %s" % (sample_rate) | |
| 182 textOverlayInfo += ",drawtext=fontfile=Mono:fontsize=32:y=192:text=Chann els\\\\:\\\\ %s" % (channels) | |
| 183 | |
| 184 textOverlayInfo += "'" | |
| 185 cmdline += ["-vf", textOverlayInfo] | |
| 186 | |
| 187 encoding_id = "%s-%sk%s" % (id_prefix, bitrate, id_params) | |
| 188 | |
| 189 if len(encoding_ids) < len(ENCODE_SETTINGS): | |
| 190 encoding_ids.append(encoding_id) | |
| 191 | |
| 192 filename_base = "%s/test-%s" % (format, encoding_id) | |
| 193 media_filename = filename_base + "." + format | |
| 194 manifest_filename = filename_base + "-manifest.json" | |
| 195 | |
| 196 cmdline.append(media_filename) | |
| 197 Run(cmdline) | |
| 198 | |
| 199 # Remux file so it conforms to MSE bytestream requirements. | |
| 200 if format == "webm": | |
| 201 tmp_filename = media_filename + ".tmp" | |
| 202 Run(["mse_webm_remuxer", media_filename, tmp_filename]) | |
| 203 Run(["mv", tmp_filename, media_filename]) | |
| 204 elif format == "mp4": | |
| 205 Run(["MP4Box", "-dash", "250", "-rap", media_filename]) | |
| 206 Run(["mv", filename_base + "_dash.mp4", media_filename]) | |
| 207 Run(["rm", filename_base + "_dash.mpd"]) | |
| 208 | |
| 209 GenerateManifest(manifest_filename, format, has_audio, has_video) | |
| 210 | |
| 211 GenerateTestHTML(format, CONFIG_CHANGE_TESTS, encoding_ids) | |
| OLD | NEW |