# Docs inputs for the audio / music / video / subtitle guide pages (tools/fixtures.py; tools/docs_check.py reads them): # tiny ffmpeg test clips (testsrc 64x48, 10 frames at 10 fps, with a sine track): MP4 (H.264 + AAC), AVI (MJPEG + # PCM), WebM (VP8 + Vorbis), MPEG-TS (interlaced MPEG-2 + MP2); a MIDI file written here (SMF 1: a tempo track and a # melody), the SoundFont of tools/fixtures/sf2.py (build_sf2), a ProTracker module from tools/fixtures/mod.py # (song_basic), MultiTracker / MED modules and an Unreal package (tools/fixtures/mtm.py, med.py, s3m.py), and SRT / # WebVTT / ASS subtitles. # tests/gen/docs_av.luau { files = { [name] = bytes }, vars = { mp4Bytes = "clip.mp4", ... } } import importlib.util, os, struct, tempfile INPUTS = ["tools/docs_check.py", "tools/fixtures/sf2.py", "tools/fixtures/mod.py", "tools/fixtures/mtm.py", "tools/fixtures/med.py", "tools/fixtures/s3m.py", "tools/fixtures/_tracker.py"] def load(ctx, name): spec = importlib.util.spec_from_file_location("docs_av_" + name, os.path.join(ctx.root, "tools", name + ".py")) m = importlib.util.module_from_spec(spec) spec.loader.exec_module(m) return m def vlq(n): out = [n & 0x7F] n >>= 7 while n: out.append(0x80 | (n & 0x7F)) n >>= 7 return bytes(reversed(out)) def track(events): body = b"".join(vlq(dt) + data for dt, data in events) + b"\x00\xff\x2f\x00" return b"MTrk" + struct.pack(">I", len(body)) + body def midi(): """SMF 1, 480 ticks per quarter: track 1 = name + tempo 120 bpm, track 2 = an eight-note melody on channel 0""" t1 = track([(0, b"\xff\x03\x05Tempo"), (0, b"\xff\x51\x03" + (500000).to_bytes(3, "big")), (0, b"\xff\x58\x04\x04\x02\x18\x08")]) ev = [(0, b"\xff\x03\x06Melody"), (0, b"\xc0\x00")] for i, note in enumerate([60, 62, 64, 65, 67, 65, 64, 62]): ev.append((0, bytes((0x90, note, 100)))) ev.append((240, bytes((0x80, note, 0)))) t2 = track(ev) return b"MThd" + struct.pack(">IHHH", 6, 1, 2, 480) + t1 + t2 SRT = """1 00:00:00,500 --> 00:00:02,000 Hello, world. 2 00:00:02,500 --> 00:00:04,250 Second line spans two rows. """ VTT = """WEBVTT intro 00:00.500 --> 00:02.000 align:start Hello, world. 00:02.500 --> 00:04.250 Second cue. """ ASS = """[Script Info] Title: Docs ScriptType: v4.00+ PlayResX: 640 PlayResY: 360 [V4+ Styles] Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding Style: Default,Arial,20,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,2,0,2,10,10,10,1 Style: Sign,Arial,16,&H0000FFFF,&H000000FF,&H00000000,&H00000000,-1,0,0,0,100,100,0,0,1,1,0,8,10,10,10,1 [Events] Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text Dialogue: 0,0:00:00.50,0:00:02.00,Default,,0,0,0,,Hello, {\\i1}world{\\i0}. Dialogue: 0,0:00:02.50,0:00:04.25,Sign,,0,0,0,,A sign\\Nwith two lines """ def generate(ctx): dc = load(ctx, "docs_check") files = {} with tempfile.TemporaryDirectory() as d: src = ["-f", "lavfi", "-i", "testsrc=size=64x48:rate=10:duration=1", "-f", "lavfi", "-i", "sine=frequency=440:sample_rate=44100:duration=1"] for name, codec in ( ("clip.mp4", ["-c:v", "libx264", "-profile:v", "baseline", "-pix_fmt", "yuv420p", "-g", "5", "-c:a", "aac", "-b:a", "64k"]), ("clip.avi", ["-c:v", "mjpeg", "-q:v", "4", "-pix_fmt", "yuvj420p", "-c:a", "pcm_s16le"]), ("clip.webm", ["-c:v", "libvpx", "-b:v", "200k", "-g", "5", "-c:a", "libvorbis", "-q:a", "2"]), ("clip.ts", ["-c:v", "mpeg2video", "-b:v", "300k", "-g", "5", "-bf", "2", "-vf", "setfield=tff", "-flags", "+ilme+ildct", "-c:a", "mp2", "-b:a", "64k"]), ): out = os.path.join(d, name) ctx.nix("ffmpeg", ["ffmpeg", "-v", "error", "-y"] + src + codec + ["-shortest", out]) files[name] = open(out, "rb").read() files["tune.mid"] = midi() sf2 = load(ctx, "fixtures/sf2") files["bank.sf2"] = sf2.build_sf2(False)[0] mod = load(ctx, "fixtures/mod") files["song.mod"] = mod.song_basic() # ws-audio2: more tracker formats (tools/fixtures/mtm.py, med.py; an Unreal package around an S3M) files["song.mtm"] = load(ctx, "fixtures/mtm").song_effects() files["song.med"] = load(ctx, "fixtures/med").song_basic(version=1) tracker = load(ctx, "fixtures/_tracker") files["music.umx"] = tracker.write_umx([("Theme", load(ctx, "fixtures/s3m").song_mono())]) files["subs.srt"] = SRT files["subs.vtt"] = VTT files["subs.ass"] = ASS dc.emit_inputs(ctx, files, { "mp4Bytes": "clip.mp4", "aviBytes": "clip.avi", "webmBytes": "clip.webm", "tsBytes": "clip.ts", "midiBytes": "tune.mid", "sf2Bytes": "bank.sf2", "modBytes": "song.mod", "mtmBytes": "song.mtm", "medBytes": "song.med", "umxBytes": "music.umx", "srtText": "subs.srt", "vttText": "subs.vtt", "assText": "subs.ass", })