fix audio only filters

This commit is contained in:
Sam Lavigne 2023-08-28 12:13:42 -04:00
parent 692490398f
commit 115c30466b
2 changed files with 36 additions and 5 deletions

View File

@ -109,9 +109,11 @@ export const previewCommand = derived([edges, nodes], ([$edges, $nodes]) => {
finalCommand.push("0:a"); finalCommand.push("0:a");
} }
finalCommand.push("-map");
if (hasVid) { if (hasVid) {
finalCommand.push("-map");
finalCommand.push('"[vid_out]"'); finalCommand.push('"[vid_out]"');
} else {
finalCommand.push("0:v");
} }
} }
@ -253,6 +255,12 @@ export function addNode(_data, type) {
}); });
} }
export function resetNodes() {
nodes.set([]);
addNode({ name: "punch.mp4" }, "input");
addNode({ name: "out.mp4" }, "output");
}
export function removeNode(id) { export function removeNode(id) {
nodes.update((_nodes) => { nodes.update((_nodes) => {
const index = _nodes.findIndex((n) => n.id === id); const index = _nodes.findIndex((n) => n.id === id);

View File

@ -1,5 +1,6 @@
import { expect, test, describe } from "vitest"; import { expect, test, describe } from "vitest";
import { makeFilterArgs } from "../../src/stores.js"; import { get } from "svelte/store";
import { nodes, edges, addNode, resetNodes, makeFilterArgs, previewCommand } from "../../src/stores.js";
describe("Filter param builder", () => { describe("Filter param builder", () => {
test("No params", () => { test("No params", () => {
@ -38,12 +39,34 @@ describe("Filter param builder", () => {
name: "filter", name: "filter",
params: [ params: [
{ name: "param1", value: 1, default: 1 }, // should be ignored { name: "param1", value: 1, default: 1 }, // should be ignored
{ name: "param2", value: "", }, // should be ignored { name: "param2", value: "" }, // should be ignored
{ name: "param3", value: 1, default: 2 }, { name: "param3", value: 1, default: 2 },
{ name: "param4", value: 2}, { name: "param4", value: 2 },
{ name: "param5", value: "p5"}, { name: "param5", value: "p5" },
], ],
}); });
expect(results).toBe("filter=param3=1:param4=2:param5=p5"); expect(results).toBe("filter=param3=1:param4=2:param5=p5");
}); });
}); });
describe("Command builder", () => {
test("Defaults", () => {
expect(get(previewCommand)).toBe("ffmpeg -i punch.mp4 out.mp4");
});
test("Simple video filter", () => {
resetNodes();
addNode({ name: "filter", type: "V->V" }, "filter");
expect(get(previewCommand)).toBe(
`ffmpeg -i punch.mp4 -filter_complex "[0:v]filter[vid_out]" -map 0:a -map "[vid_out]" out.mp4`
);
});
test("Simple audio filter", () => {
resetNodes();
addNode({ name: "filter", type: "A->A" }, "filter");
expect(get(previewCommand)).toBe(
`ffmpeg -i punch.mp4 -filter_complex "[0:a]filter[aud_out]" -map "[aud_out]" -map 0:v out.mp4`
);
});
});