mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
feat(tools): 2.0 phase 5 wave 3a - video depth (22 tools) (#221)
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import { extname } from "node:path";
|
||||
import { resolveEncoder } from "@snapotter/media-engine";
|
||||
import type { FastifyInstance } from "fastify";
|
||||
import { z } from "zod";
|
||||
import { runMediaTool, videoContentType } from "../../lib/media-tool.js";
|
||||
import { createToolRoute } from "../tool-factory.js";
|
||||
|
||||
const VF_MAP: Record<string, string> = {
|
||||
cw90: "transpose=1",
|
||||
ccw90: "transpose=2",
|
||||
"180": "transpose=1,transpose=1",
|
||||
hflip: "hflip",
|
||||
vflip: "vflip",
|
||||
};
|
||||
|
||||
const settingsSchema = z.object({
|
||||
transform: z.enum(["cw90", "ccw90", "180", "hflip", "vflip"]),
|
||||
});
|
||||
|
||||
export function registerRotateVideo(app: FastifyInstance) {
|
||||
createToolRoute(app, {
|
||||
toolId: "rotate-video",
|
||||
settingsSchema,
|
||||
process: async () => {
|
||||
throw new Error("rotate-video is v2-only");
|
||||
},
|
||||
processV2: async (ctx) => {
|
||||
const settings = settingsSchema.parse(ctx.settings);
|
||||
const origExt = extname(ctx.inputs[0].filename) || ".mp4";
|
||||
const base = ctx.inputs[0].filename.replace(/\.[^.]+$/, "");
|
||||
const outName = `${base}_rotated${origExt}`;
|
||||
const contentType = videoContentType(origExt);
|
||||
|
||||
const { outPath } = await runMediaTool(ctx, outName, (inPath, out) => [
|
||||
"-i",
|
||||
inPath,
|
||||
"-vf",
|
||||
VF_MAP[settings.transform],
|
||||
"-c:v",
|
||||
resolveEncoder("h264"),
|
||||
"-crf",
|
||||
"20",
|
||||
"-preset",
|
||||
"medium",
|
||||
"-pix_fmt",
|
||||
"yuv420p",
|
||||
"-c:a",
|
||||
"copy",
|
||||
out,
|
||||
]);
|
||||
return { scratchPath: outPath, filename: outName, contentType };
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user