mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
Lands five integrated branches: pipeline templates (#355), analytics opt-out (#354), 83 conversion presets bringing the catalog to 240 tools (#356), self-hosted positioning (#353), and e2e modernization (#351). Integration fixes: aligned stale web analytics tests with the opt-out/allow-list model, closed 3 CodeQL incomplete-sanitization alerts in the i18n generator, resolved settings/index/docs/format-matrix conflicts, and corrected tool counts to 240.
74 lines
2.0 KiB
TypeScript
74 lines
2.0 KiB
TypeScript
import { resolveEncoder } from "@snapotter/media-engine";
|
|
import type { FastifyInstance } from "fastify";
|
|
import { z } from "zod";
|
|
import { runMediaTool } from "../../lib/media-tool.js";
|
|
import { createToolRoute } from "../tool-factory.js";
|
|
|
|
const settingsSchema = z.object({
|
|
format: z.enum(["mp4", "webm", "mov"]).default("mp4"),
|
|
});
|
|
|
|
const CONTENT_TYPES: Record<string, string> = {
|
|
mp4: "video/mp4",
|
|
webm: "video/webm",
|
|
mov: "video/quicktime",
|
|
};
|
|
|
|
export function registerGifToVideo(app: FastifyInstance) {
|
|
createToolRoute(app, {
|
|
toolId: "gif-to-video",
|
|
settingsSchema,
|
|
process: async () => {
|
|
throw new Error("gif-to-video is v2-only");
|
|
},
|
|
processV2: async (ctx) => {
|
|
const settings = settingsSchema.parse(ctx.settings);
|
|
const base = ctx.inputs[0].filename.replace(/\.[^.]+$/, "");
|
|
const outName = `${base}.${settings.format}`;
|
|
const contentType = CONTENT_TYPES[settings.format];
|
|
|
|
const { outPath } = await runMediaTool(ctx, outName, (inPath, out) => {
|
|
if (settings.format === "webm") {
|
|
return [
|
|
"-i",
|
|
inPath,
|
|
"-vf",
|
|
"scale=trunc(iw/2)*2:trunc(ih/2)*2",
|
|
"-c:v",
|
|
resolveEncoder("vp9"),
|
|
"-b:v",
|
|
"0",
|
|
"-crf",
|
|
"32",
|
|
// GIFs decode to bgra/gbrap (alpha); libvpx-vp9 rejects those pixel
|
|
// formats, so flatten to yuv420p just like the mp4 branch does.
|
|
"-pix_fmt",
|
|
"yuv420p",
|
|
"-an",
|
|
out,
|
|
];
|
|
}
|
|
return [
|
|
"-i",
|
|
inPath,
|
|
"-vf",
|
|
"scale=trunc(iw/2)*2:trunc(ih/2)*2",
|
|
"-c:v",
|
|
resolveEncoder("h264"),
|
|
"-crf",
|
|
"20",
|
|
"-preset",
|
|
"medium",
|
|
"-pix_fmt",
|
|
"yuv420p",
|
|
"-movflags",
|
|
"+faststart",
|
|
"-an",
|
|
out,
|
|
];
|
|
});
|
|
return { scratchPath: outPath, filename: outName, contentType };
|
|
},
|
|
});
|
|
}
|