Spaces:
Configuration error
Configuration error
Download src/ffmpeg/planner.js from UUUZCX/video-optimizer-bot: direct link, hf CLI and curl.
- Browser
- Download file 1.51 kB
-
https://huggingface.co/spaces/UUUZCX/video-optimizer-bot/resolve/main/src/ffmpeg/planner.js
- Command line
-
hf download hf://spaces/UUUZCX/video-optimizer-bot/src/ffmpeg/planner.js
-
curl -L -o planner.js https://huggingface.co/spaces/UUUZCX/video-optimizer-bot/resolve/main/src/ffmpeg/planner.js
1.51 kB
| const { config } = require("../config/env"); | |
| const { getPreset } = require("./presets"); | |
| const { chooseEncoder, isHardwareEncoder } = require("./gpu.detector"); | |
| function detectMode(info, requestedMode) { | |
| if (requestedMode && requestedMode !== "auto") return requestedMode; | |
| const pixels = info.width * info.height; | |
| const bitratePerPixel = pixels && info.fps ? info.bitrate / pixels / info.fps : 0; | |
| if (info.width >= 1400 && info.fps <= 35 && bitratePerPixel < 0.08) return "screen"; | |
| if (info.duration > 20 * 60) return "ultra"; | |
| if (info.width >= 1600 || info.height >= 1000) return "ocr"; | |
| if (info.fps > 50) return "camera"; | |
| return config.video.defaultMode; | |
| } | |
| async function buildPlan(info, requestedMode = "auto") { | |
| const mode = detectMode(info, requestedMode); | |
| const preset = getPreset(mode); | |
| const encoder = await chooseEncoder("h264"); | |
| const hw = isHardwareEncoder(encoder); | |
| const targetWidth = Math.min(info.width, preset.maxWidth); | |
| const evenWidth = targetWidth % 2 === 0 ? targetWidth : targetWidth - 1; | |
| const targetFps = Math.min(Math.round(info.fps || preset.fps), preset.fps); | |
| return { | |
| mode, | |
| preset, | |
| encoder, | |
| hardware: hw, | |
| width: evenWidth > 0 ? evenWidth : -2, | |
| fps: Math.max(15, targetFps || 30), | |
| keyint: Math.max(48, Math.round((targetFps || 30) * 2)), | |
| splitSeconds: Math.max(config.video.chunkMinSeconds, Math.min(config.video.chunkMaxSeconds, info.duration > 15 * 60 ? 120 : 180)) | |
| }; | |
| } | |
| module.exports = { detectMode, buildPlan }; | |