From 115c30466b507ce3264a340b4d2695acabbf7ab0 Mon Sep 17 00:00:00 2001 From: Sam Lavigne Date: Mon, 28 Aug 2023 12:13:42 -0400 Subject: [PATCH] fix audio only filters --- src/stores.js | 10 +++++++++- tests/unit-tests/commandbuilder.js | 31 ++++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/stores.js b/src/stores.js index c87e649..ad1bfa2 100644 --- a/src/stores.js +++ b/src/stores.js @@ -109,9 +109,11 @@ export const previewCommand = derived([edges, nodes], ([$edges, $nodes]) => { finalCommand.push("0:a"); } + finalCommand.push("-map"); if (hasVid) { - finalCommand.push("-map"); 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) { nodes.update((_nodes) => { const index = _nodes.findIndex((n) => n.id === id); diff --git a/tests/unit-tests/commandbuilder.js b/tests/unit-tests/commandbuilder.js index b8e18dc..c75e142 100644 --- a/tests/unit-tests/commandbuilder.js +++ b/tests/unit-tests/commandbuilder.js @@ -1,5 +1,6 @@ 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", () => { test("No params", () => { @@ -38,12 +39,34 @@ describe("Filter param builder", () => { name: "filter", params: [ { 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: "param4", value: 2}, - { name: "param5", value: "p5"}, + { name: "param4", value: 2 }, + { name: "param5", value: "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` + ); + }); +});