# MP4 / MOV fixtures (tools/fixtures.py): files made by ffmpeg (MJPEG + AAC MP4, MJPEG + PCM MOV, H.264 with B-frames # + AAC (edit lists), fragmented MP4, MPEG-1 + Opus, MJPEG + FLAC, MJPEG + MP2 MOV) with ffprobe's streams and packets, # ffmpeg's frames (CRC-32; the first raw) and audio (f32). Our MP4 / MOV writer's files are checked in # tools/fixtures/videoenc.py. # tests/gen/mp4_cases.luau { { name, data, streams, packets, frames, yuv, pcm, pcmBytes } } import importlib.util, os, tempfile _spec = importlib.util.spec_from_file_location("_video_helpers", os.path.join(os.path.dirname(os.path.abspath(__file__)), "_video.py")) V = importlib.util.module_from_spec(_spec) _spec.loader.exec_module(V) INPUTS = ["tools/fixtures/_video.py"] SRC = ["-f", "lavfi", "-i", "testsrc2=size=160x120:rate=12"] def aud(rate, ch=1): return ["-f", "lavfi", "-i", "sine=frequency=550:sample_rate=%d" % rate, "-ac", str(ch)] def case(tmp, name): path = os.path.join(tmp, name) c = {"name": name, "data": open(path, "rb").read(), "streams": V.streams(path), "packets": V.packets(path)} vs = [s for s in c["streams"] if s["kind"] == "video"] if vs: frames = V.yuv_frames(path, vs[0]["width"], vs[0]["height"], codec=vs[0]["codec"]) c["frames"] = [V.crc(f) for f in frames] c["yuv"] = frames[:2] if any(s["kind"] == "audio" for s in c["streams"]): pcm = V.pcm_f32(path) c["pcm"] = pcm[:8192 * 4] c["pcmBytes"] = len(pcm) return c def generate(ctx): tmp = tempfile.mkdtemp(prefix="mp4fx_") ff = lambda *a: V.ffmpeg(list(a), cwd=tmp) ff(*SRC, *aud(44100), "-t", "1", "-c:v", "mjpeg", "-q:v", "4", "-c:a", "aac", "-b:a", "96k", "mjpeg_aac.mp4") ff(*SRC, *aud(48000, 2), "-t", "1", "-c:v", "mjpeg", "-c:a", "pcm_s16le", "mjpeg_pcm.mov") ff(*SRC, *aud(44100), "-t", "1", "-c:v", "libx264", "-preset", "veryfast", "-bf", "2", "-g", "6", "-c:a", "aac", "h264_aac.mp4") ff(*SRC, *aud(48000), "-t", "1", "-c:v", "mjpeg", "-c:a", "aac", "-movflags", "frag_keyframe+empty_moov", "fragmented.mp4") ff(*SRC, *aud(48000), "-t", "1", "-r", "25", "-c:v", "mpeg1video", "-c:a", "libopus", "mpeg1_opus.mp4") ff(*SRC, *aud(44100, 2), "-t", "1", "-c:v", "mjpeg", "-c:a", "flac", "mjpeg_flac.mp4") ff(*SRC, *aud(44100), "-t", "1", "-c:v", "mjpeg", "-c:a", "mp2", "mjpeg_mp2.mov") cases = [case(tmp, n) for n in ("mjpeg_aac.mp4", "mjpeg_pcm.mov", "h264_aac.mp4", "fragmented.mp4", "mpeg1_opus.mp4", "mjpeg_flac.mp4", "mjpeg_mp2.mov")] ctx.emit("mp4_cases", cases)