|
| 1 | +// Times common jobs on FATE samples with each core; with FATE_NATIVE=1, also |
| 2 | +// with native `ffmpeg`. |
| 3 | +import { execFileSync } from "node:child_process"; |
| 4 | +import { readFileSync } from "node:fs"; |
| 5 | +import { basename, join } from "node:path"; |
| 6 | +import { test } from "vitest"; |
| 7 | +import { createCore } from "../helpers/core.js"; |
| 8 | +import { exec } from "../helpers/run.js"; |
| 9 | +import { suite } from "./fate.js"; |
| 10 | + |
| 11 | +const H264_1080P = "h264/h264refframeregression.mp4"; |
| 12 | +const VP9_480P = "vp9-test-vectors/vp90-2-15-segkey_adpq.webm"; |
| 13 | +const WAV = "audio-reference/luckynight_2ch_44kHz_s16.wav"; |
| 14 | + |
| 15 | +const JOBS = [ |
| 16 | + ["decode h264 1080p", H264_1080P, ["-f", "null", "-"]], |
| 17 | + ["decode vp9 480p", VP9_480P, ["-f", "null", "-"]], |
| 18 | + ["scale 1080p to 480p", H264_1080P, ["-vf", "scale=854:480", "-f", "null", "-"]], |
| 19 | + ["remux mp4 to mkv", H264_1080P, ["-c", "copy", "-f", "matroska", "/out"]], |
| 20 | + ["x264 veryfast 720p", H264_1080P, ["-t", "2", "-vf", "scale=1280:720", "-c:v", "libx264", "-preset", "veryfast", "-an", "-f", "mp4", "/out"]], |
| 21 | + ["vp9 realtime 480p", VP9_480P, ["-c:v", "libvpx-vp9", "-deadline", "realtime", "-cpu-used", "8", "-f", "webm", "/out"]], |
| 22 | + ["aac encode", WAV, ["-c:a", "aac", "-f", "ipod", "/out"]], |
| 23 | + ["mp3 encode", WAV, ["-f", "mp3", "/out"]], |
| 24 | + ["opus encode", WAV, ["-c:a", "libopus", "-f", "ogg", "/out"]], |
| 25 | +]; |
| 26 | + |
| 27 | +const RUNS = { iterations: 3, time: 0, warmupIterations: 1, warmupTime: 0 }; |
| 28 | + |
| 29 | +const core = await createCore(); |
| 30 | +[H264_1080P, VP9_480P, WAV].forEach((sample) => core.FS.writeFile(`/${basename(sample)}`, readFileSync(join(suite, sample)))); |
| 31 | + |
| 32 | +test.for(JOBS)("%s", async ([, sample, args], { bench }) => { |
| 33 | + const wasm = bench("ffmpeg.wasm", { perProject: true }, () => exec(core, "-i", `/${basename(sample)}`, ...args)); |
| 34 | + const nativeArgs = ["-v", "error", "-y", "-i", join(suite, sample), ...args.map((arg) => (arg === "/out" ? "/dev/null" : arg))]; |
| 35 | + const native = bench("native ffmpeg", () => execFileSync("ffmpeg", nativeArgs, { stdio: "ignore" })); |
| 36 | + await (process.env.FATE_NATIVE ? bench.compare(wasm, native, RUNS) : wasm.run(RUNS)); |
| 37 | +}); |
0 commit comments