Spaces:
Configuration error
Configuration error
Download src/ffmpeg/splitter.js from UUUZCX/video-optimizer-bot: direct link, hf CLI and curl.
- Browser
- Download file 1.17 kB
-
https://huggingface.co/spaces/UUUZCX/video-optimizer-bot/resolve/main/src/ffmpeg/splitter.js
- Command line
-
hf download hf://spaces/UUUZCX/video-optimizer-bot/src/ffmpeg/splitter.js
-
curl -L -o splitter.js https://huggingface.co/spaces/UUUZCX/video-optimizer-bot/resolve/main/src/ffmpeg/splitter.js
1.17 kB
| const path = require("node:path"); | |
| const { copySegment } = require("./ffmpeg"); | |
| function planSegments(duration, splitSeconds) { | |
| if (duration <= splitSeconds + 20) return [{ index: 1, start: 0, duration }]; | |
| const segments = []; | |
| let start = 0; | |
| let index = 1; | |
| while (start < duration) { | |
| const remaining = duration - start; | |
| const length = remaining <= splitSeconds + 20 ? remaining : splitSeconds; | |
| segments.push({ index, start, duration: length }); | |
| start += length; | |
| index += 1; | |
| } | |
| return segments; | |
| } | |
| async function splitIfNeeded(inputPath, outDir, info, plan) { | |
| const segments = planSegments(info.duration, plan.splitSeconds); | |
| if (segments.length === 1) return [{ ...segments[0], path: inputPath, copied: false }]; | |
| const width = String(segments.length).length; | |
| const result = []; | |
| for (const segment of segments) { | |
| const output = path.join(outDir, `source_part_${String(segment.index).padStart(width, "0")}.mp4`); | |
| await copySegment(inputPath, output, segment.start, segment.duration); | |
| result.push({ ...segment, path: output, copied: true }); | |
| } | |
| return result; | |
| } | |
| module.exports = { planSegments, splitIfNeeded }; | |