add examples to tests

This commit is contained in:
Sam Lavigne 2023-09-04 10:11:25 -04:00
parent 9a3ec7386d
commit ac812c4a79
1 changed files with 141 additions and 90 deletions

View File

@ -1,6 +1,15 @@
const fs = require('fs');
import { expect, test, describe } from "vitest";
import { get } from "svelte/store";
import { addNode, resetNodes, makeFilterArgs, previewCommand } from "../../src/stores.js";
import {
nodes,
edges,
addNode,
resetNodes,
makeFilterArgs,
previewCommand,
auto,
} from "../../src/stores.js";
function makeFilter(name, type) {
const [ins, outs] = type.toLowerCase().split("->");
@ -8,7 +17,7 @@ function makeFilter(name, type) {
name: name,
inputs: ins.split(""),
outputs: outs.split(""),
}
};
}
describe("Filter param builder", () => {
@ -107,4 +116,46 @@ describe("Command builder", () => {
`ffmpeg -i punch.mp4 -filter_complex "[0:v]vfilter[1];[0:a]afilter[out_a];[1]vfilter2[out_v]" -map "[out_a]" -map "[out_v]" out.mp4`
);
});
test("Examples", () => {
const examples = [
[
"crop_trim.json",
`ffmpeg -i punch.mp4 -filter_complex "[0:v]crop=out_w=iw/2,trim=start=1.7:duration=0.5[out_v]" -map "[out_v]" out.gif`,
],
[
"grid.json",
`ffmpeg -i punch.mp4 -i shoe.mp4 -i shoe.mp4 -i punch.mp4 -filter_complex "[1:v][0:v][3:v][2:v]xstack=inputs=4:grid=2x2:shortest=true[out_v]" -map "[out_v]" out.mp4`,
],
[
"scale_overlay.json",
`ffmpeg -i punch.mp4 -i shoe.mp4 -filter_complex "[0:v]scale=w=120:h=120:force_original_aspect_ratio=increase[1];[1:v][1]overlay=x=290:y=50[out_v]" -map "[out_v]" out.mp4`,
],
[
"smooth_slow.json",
`ffmpeg -i punch.mp4 -filter_complex "[0:v]setpts=expr=2*PTS,minterpolate=fps=66[out_v];[0:a]asetpts=expr=2*PTS[out_a]" -map "[out_a]" -map "[out_v]" out.mp4`,
],
[
"speedup.json",
`ffmpeg -i punch.mp4 -filter_complex "[0:v]setpts=expr=0.5*PTS[out_v]" -map "[out_v]" out.mp4`,
],
[
"text.json",
`ffmpeg -i punch.mp4 -filter_complex "[0:v]drawtext=fontfile=comic.ttf:text=LOL:fontcolor=red:bordercolor=white:boxborderw=3:fontsize=100:x=300:y=150:borderw=5[out_v]" -map "[out_v]" -map 0:a out.mp4`,
],
[
"xfade.json",
`ffmpeg -i punch.mp4 -i shoe.mp4 -filter_complex "[0:v][1:v]xfade=transition=radial:duration=3[out_v]" -map "[out_v]" -map 0:a out.mp4`,
],
];
for (const [filename, output] of examples) {
const data = JSON.parse(
fs.readFileSync(`public/examples/${filename}`, "utf8")
);
nodes.set(data.nodes);
edges.set(data.edges);
expect(get(previewCommand).join(" ")).toBe(output);
}
});
});