@vibeframe/cli 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +4 -0
- package/.turbo/turbo-lint.log +21 -0
- package/.turbo/turbo-test.log +689 -0
- package/dist/agent/adapters/claude.d.ts +15 -0
- package/dist/agent/adapters/claude.d.ts.map +1 -0
- package/dist/agent/adapters/claude.js +119 -0
- package/dist/agent/adapters/claude.js.map +1 -0
- package/dist/agent/adapters/gemini.d.ts +15 -0
- package/dist/agent/adapters/gemini.d.ts.map +1 -0
- package/dist/agent/adapters/gemini.js +132 -0
- package/dist/agent/adapters/gemini.js.map +1 -0
- package/dist/agent/adapters/index.d.ts +27 -0
- package/dist/agent/adapters/index.d.ts.map +1 -0
- package/dist/agent/adapters/index.js +38 -0
- package/dist/agent/adapters/index.js.map +1 -0
- package/dist/agent/adapters/ollama.d.ts +20 -0
- package/dist/agent/adapters/ollama.d.ts.map +1 -0
- package/dist/agent/adapters/ollama.js +186 -0
- package/dist/agent/adapters/ollama.js.map +1 -0
- package/dist/agent/adapters/openai.d.ts +15 -0
- package/dist/agent/adapters/openai.d.ts.map +1 -0
- package/dist/agent/adapters/openai.js +92 -0
- package/dist/agent/adapters/openai.js.map +1 -0
- package/dist/agent/adapters/xai.d.ts +15 -0
- package/dist/agent/adapters/xai.d.ts.map +1 -0
- package/dist/agent/adapters/xai.js +95 -0
- package/dist/agent/adapters/xai.js.map +1 -0
- package/dist/agent/index.d.ts +69 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +180 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/agent/memory/index.d.ts +70 -0
- package/dist/agent/memory/index.d.ts.map +1 -0
- package/dist/agent/memory/index.js +132 -0
- package/dist/agent/memory/index.js.map +1 -0
- package/dist/agent/prompts/system.d.ts +6 -0
- package/dist/agent/prompts/system.d.ts.map +1 -0
- package/dist/agent/prompts/system.js +103 -0
- package/dist/agent/prompts/system.js.map +1 -0
- package/dist/agent/tools/ai-editing.d.ts +15 -0
- package/dist/agent/tools/ai-editing.d.ts.map +1 -0
- package/dist/agent/tools/ai-editing.js +763 -0
- package/dist/agent/tools/ai-editing.js.map +1 -0
- package/dist/agent/tools/ai-generation.d.ts +13 -0
- package/dist/agent/tools/ai-generation.d.ts.map +1 -0
- package/dist/agent/tools/ai-generation.js +973 -0
- package/dist/agent/tools/ai-generation.js.map +1 -0
- package/dist/agent/tools/ai-pipeline.d.ts +14 -0
- package/dist/agent/tools/ai-pipeline.d.ts.map +1 -0
- package/dist/agent/tools/ai-pipeline.js +961 -0
- package/dist/agent/tools/ai-pipeline.js.map +1 -0
- package/dist/agent/tools/ai.d.ts +13 -0
- package/dist/agent/tools/ai.d.ts.map +1 -0
- package/dist/agent/tools/ai.js +19 -0
- package/dist/agent/tools/ai.js.map +1 -0
- package/dist/agent/tools/batch.d.ts +6 -0
- package/dist/agent/tools/batch.d.ts.map +1 -0
- package/dist/agent/tools/batch.js +383 -0
- package/dist/agent/tools/batch.js.map +1 -0
- package/dist/agent/tools/e2e.test.d.ts +26 -0
- package/dist/agent/tools/e2e.test.d.ts.map +1 -0
- package/dist/agent/tools/e2e.test.js +397 -0
- package/dist/agent/tools/e2e.test.js.map +1 -0
- package/dist/agent/tools/export.d.ts +6 -0
- package/dist/agent/tools/export.d.ts.map +1 -0
- package/dist/agent/tools/export.js +171 -0
- package/dist/agent/tools/export.js.map +1 -0
- package/dist/agent/tools/filesystem.d.ts +6 -0
- package/dist/agent/tools/filesystem.d.ts.map +1 -0
- package/dist/agent/tools/filesystem.js +212 -0
- package/dist/agent/tools/filesystem.js.map +1 -0
- package/dist/agent/tools/index.d.ts +65 -0
- package/dist/agent/tools/index.d.ts.map +1 -0
- package/dist/agent/tools/index.js +120 -0
- package/dist/agent/tools/index.js.map +1 -0
- package/dist/agent/tools/integration.test.d.ts +11 -0
- package/dist/agent/tools/integration.test.d.ts.map +1 -0
- package/dist/agent/tools/integration.test.js +659 -0
- package/dist/agent/tools/integration.test.js.map +1 -0
- package/dist/agent/tools/media.d.ts +6 -0
- package/dist/agent/tools/media.d.ts.map +1 -0
- package/dist/agent/tools/media.js +616 -0
- package/dist/agent/tools/media.js.map +1 -0
- package/dist/agent/tools/project.d.ts +6 -0
- package/dist/agent/tools/project.d.ts.map +1 -0
- package/dist/agent/tools/project.js +284 -0
- package/dist/agent/tools/project.js.map +1 -0
- package/dist/agent/tools/timeline.d.ts +6 -0
- package/dist/agent/tools/timeline.d.ts.map +1 -0
- package/dist/agent/tools/timeline.js +873 -0
- package/dist/agent/tools/timeline.js.map +1 -0
- package/dist/agent/types.d.ts +59 -0
- package/dist/agent/types.d.ts.map +1 -0
- package/dist/agent/types.js +5 -0
- package/dist/agent/types.js.map +1 -0
- package/dist/commands/agent.d.ts +21 -0
- package/dist/commands/agent.d.ts.map +1 -0
- package/dist/commands/agent.js +290 -0
- package/dist/commands/agent.js.map +1 -0
- package/dist/commands/ai-analyze.d.ts +106 -0
- package/dist/commands/ai-analyze.d.ts.map +1 -0
- package/dist/commands/ai-analyze.js +327 -0
- package/dist/commands/ai-analyze.js.map +1 -0
- package/dist/commands/ai-animated-caption.d.ts +64 -0
- package/dist/commands/ai-animated-caption.d.ts.map +1 -0
- package/dist/commands/ai-animated-caption.js +272 -0
- package/dist/commands/ai-animated-caption.js.map +1 -0
- package/dist/commands/ai-audio.d.ts +20 -0
- package/dist/commands/ai-audio.d.ts.map +1 -0
- package/dist/commands/ai-audio.js +808 -0
- package/dist/commands/ai-audio.js.map +1 -0
- package/dist/commands/ai-broll.d.ts +15 -0
- package/dist/commands/ai-broll.d.ts.map +1 -0
- package/dist/commands/ai-broll.js +406 -0
- package/dist/commands/ai-broll.js.map +1 -0
- package/dist/commands/ai-edit-cli.d.ts +14 -0
- package/dist/commands/ai-edit-cli.d.ts.map +1 -0
- package/dist/commands/ai-edit-cli.js +579 -0
- package/dist/commands/ai-edit-cli.js.map +1 -0
- package/dist/commands/ai-edit.d.ts +398 -0
- package/dist/commands/ai-edit.d.ts.map +1 -0
- package/dist/commands/ai-edit.js +1019 -0
- package/dist/commands/ai-edit.js.map +1 -0
- package/dist/commands/ai-fill-gaps.d.ts +14 -0
- package/dist/commands/ai-fill-gaps.d.ts.map +1 -0
- package/dist/commands/ai-fill-gaps.js +451 -0
- package/dist/commands/ai-fill-gaps.js.map +1 -0
- package/dist/commands/ai-helpers.d.ts +20 -0
- package/dist/commands/ai-helpers.d.ts.map +1 -0
- package/dist/commands/ai-helpers.js +59 -0
- package/dist/commands/ai-helpers.js.map +1 -0
- package/dist/commands/ai-highlights.d.ts +127 -0
- package/dist/commands/ai-highlights.d.ts.map +1 -0
- package/dist/commands/ai-highlights.js +1026 -0
- package/dist/commands/ai-highlights.js.map +1 -0
- package/dist/commands/ai-image.d.ts +34 -0
- package/dist/commands/ai-image.d.ts.map +1 -0
- package/dist/commands/ai-image.js +653 -0
- package/dist/commands/ai-image.js.map +1 -0
- package/dist/commands/ai-motion.d.ts +50 -0
- package/dist/commands/ai-motion.d.ts.map +1 -0
- package/dist/commands/ai-motion.js +271 -0
- package/dist/commands/ai-motion.js.map +1 -0
- package/dist/commands/ai-narrate.d.ts +66 -0
- package/dist/commands/ai-narrate.d.ts.map +1 -0
- package/dist/commands/ai-narrate.js +329 -0
- package/dist/commands/ai-narrate.js.map +1 -0
- package/dist/commands/ai-review.d.ts +57 -0
- package/dist/commands/ai-review.d.ts.map +1 -0
- package/dist/commands/ai-review.js +251 -0
- package/dist/commands/ai-review.js.map +1 -0
- package/dist/commands/ai-script-pipeline-cli.d.ts +9 -0
- package/dist/commands/ai-script-pipeline-cli.d.ts.map +1 -0
- package/dist/commands/ai-script-pipeline-cli.js +1494 -0
- package/dist/commands/ai-script-pipeline-cli.js.map +1 -0
- package/dist/commands/ai-script-pipeline.d.ts +259 -0
- package/dist/commands/ai-script-pipeline.d.ts.map +1 -0
- package/dist/commands/ai-script-pipeline.js +1027 -0
- package/dist/commands/ai-script-pipeline.js.map +1 -0
- package/dist/commands/ai-suggest-edit.d.ts +14 -0
- package/dist/commands/ai-suggest-edit.d.ts.map +1 -0
- package/dist/commands/ai-suggest-edit.js +220 -0
- package/dist/commands/ai-suggest-edit.js.map +1 -0
- package/dist/commands/ai-video-fx.d.ts +14 -0
- package/dist/commands/ai-video-fx.d.ts.map +1 -0
- package/dist/commands/ai-video-fx.js +395 -0
- package/dist/commands/ai-video-fx.js.map +1 -0
- package/dist/commands/ai-video.d.ts +15 -0
- package/dist/commands/ai-video.d.ts.map +1 -0
- package/dist/commands/ai-video.js +785 -0
- package/dist/commands/ai-video.js.map +1 -0
- package/dist/commands/ai-viral.d.ts +15 -0
- package/dist/commands/ai-viral.d.ts.map +1 -0
- package/dist/commands/ai-viral.js +519 -0
- package/dist/commands/ai-viral.js.map +1 -0
- package/dist/commands/ai-visual-fx.d.ts +14 -0
- package/dist/commands/ai-visual-fx.d.ts.map +1 -0
- package/dist/commands/ai-visual-fx.js +505 -0
- package/dist/commands/ai-visual-fx.js.map +1 -0
- package/dist/commands/ai.d.ts +38 -0
- package/dist/commands/ai.d.ts.map +1 -0
- package/dist/commands/ai.js +225 -0
- package/dist/commands/ai.js.map +1 -0
- package/dist/commands/ai.test.d.ts +2 -0
- package/dist/commands/ai.test.d.ts.map +1 -0
- package/dist/commands/ai.test.js +554 -0
- package/dist/commands/ai.test.js.map +1 -0
- package/dist/commands/analyze.d.ts +16 -0
- package/dist/commands/analyze.d.ts.map +1 -0
- package/dist/commands/analyze.js +247 -0
- package/dist/commands/analyze.js.map +1 -0
- package/dist/commands/audio.d.ts +18 -0
- package/dist/commands/audio.d.ts.map +1 -0
- package/dist/commands/audio.js +539 -0
- package/dist/commands/audio.js.map +1 -0
- package/dist/commands/batch.d.ts +3 -0
- package/dist/commands/batch.d.ts.map +1 -0
- package/dist/commands/batch.js +366 -0
- package/dist/commands/batch.js.map +1 -0
- package/dist/commands/batch.test.d.ts +2 -0
- package/dist/commands/batch.test.d.ts.map +1 -0
- package/dist/commands/batch.test.js +203 -0
- package/dist/commands/batch.test.js.map +1 -0
- package/dist/commands/detect.d.ts +3 -0
- package/dist/commands/detect.d.ts.map +1 -0
- package/dist/commands/detect.js +273 -0
- package/dist/commands/detect.js.map +1 -0
- package/dist/commands/doctor.d.ts +6 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +191 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/edit-cmd.d.ts +26 -0
- package/dist/commands/edit-cmd.d.ts.map +1 -0
- package/dist/commands/edit-cmd.js +870 -0
- package/dist/commands/edit-cmd.js.map +1 -0
- package/dist/commands/export.d.ts +39 -0
- package/dist/commands/export.d.ts.map +1 -0
- package/dist/commands/export.js +730 -0
- package/dist/commands/export.js.map +1 -0
- package/dist/commands/generate.d.ts +25 -0
- package/dist/commands/generate.d.ts.map +1 -0
- package/dist/commands/generate.js +1885 -0
- package/dist/commands/generate.js.map +1 -0
- package/dist/commands/media.d.ts +3 -0
- package/dist/commands/media.d.ts.map +1 -0
- package/dist/commands/media.js +165 -0
- package/dist/commands/media.js.map +1 -0
- package/dist/commands/output.d.ts +45 -0
- package/dist/commands/output.d.ts.map +1 -0
- package/dist/commands/output.js +122 -0
- package/dist/commands/output.js.map +1 -0
- package/dist/commands/pipeline.d.ts +19 -0
- package/dist/commands/pipeline.d.ts.map +1 -0
- package/dist/commands/pipeline.js +345 -0
- package/dist/commands/pipeline.js.map +1 -0
- package/dist/commands/project.d.ts +3 -0
- package/dist/commands/project.d.ts.map +1 -0
- package/dist/commands/project.js +139 -0
- package/dist/commands/project.js.map +1 -0
- package/dist/commands/project.test.d.ts +2 -0
- package/dist/commands/project.test.d.ts.map +1 -0
- package/dist/commands/project.test.js +105 -0
- package/dist/commands/project.test.js.map +1 -0
- package/dist/commands/sanitize.d.ts +21 -0
- package/dist/commands/sanitize.d.ts.map +1 -0
- package/dist/commands/sanitize.js +56 -0
- package/dist/commands/sanitize.js.map +1 -0
- package/dist/commands/schema.d.ts +11 -0
- package/dist/commands/schema.d.ts.map +1 -0
- package/dist/commands/schema.js +101 -0
- package/dist/commands/schema.js.map +1 -0
- package/dist/commands/setup.d.ts +6 -0
- package/dist/commands/setup.d.ts.map +1 -0
- package/dist/commands/setup.js +440 -0
- package/dist/commands/setup.js.map +1 -0
- package/dist/commands/timeline.d.ts +3 -0
- package/dist/commands/timeline.d.ts.map +1 -0
- package/dist/commands/timeline.js +469 -0
- package/dist/commands/timeline.js.map +1 -0
- package/dist/commands/timeline.test.d.ts +2 -0
- package/dist/commands/timeline.test.d.ts.map +1 -0
- package/dist/commands/timeline.test.js +320 -0
- package/dist/commands/timeline.test.js.map +1 -0
- package/dist/commands/validate.d.ts +32 -0
- package/dist/commands/validate.d.ts.map +1 -0
- package/dist/commands/validate.js +63 -0
- package/dist/commands/validate.js.map +1 -0
- package/dist/config/config.test.d.ts +2 -0
- package/dist/config/config.test.d.ts.map +1 -0
- package/dist/config/config.test.js +164 -0
- package/dist/config/config.test.js.map +1 -0
- package/dist/config/index.d.ts +35 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +101 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/schema.d.ts +43 -0
- package/dist/config/schema.d.ts.map +1 -0
- package/dist/config/schema.js +42 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/engine/index.d.ts +3 -0
- package/dist/engine/index.d.ts.map +1 -0
- package/dist/engine/index.js +2 -0
- package/dist/engine/index.js.map +1 -0
- package/dist/engine/project.d.ts +84 -0
- package/dist/engine/project.d.ts.map +1 -0
- package/dist/engine/project.js +355 -0
- package/dist/engine/project.js.map +1 -0
- package/dist/engine/project.test.d.ts +2 -0
- package/dist/engine/project.test.d.ts.map +1 -0
- package/dist/engine/project.test.js +599 -0
- package/dist/engine/project.test.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +131 -0
- package/dist/index.js.map +1 -0
- package/dist/utils/api-key.d.ts +36 -0
- package/dist/utils/api-key.d.ts.map +1 -0
- package/dist/utils/api-key.js +211 -0
- package/dist/utils/api-key.js.map +1 -0
- package/dist/utils/api-key.test.d.ts +2 -0
- package/dist/utils/api-key.test.d.ts.map +1 -0
- package/dist/utils/api-key.test.js +35 -0
- package/dist/utils/api-key.test.js.map +1 -0
- package/dist/utils/audio.d.ts +23 -0
- package/dist/utils/audio.d.ts.map +1 -0
- package/dist/utils/audio.js +79 -0
- package/dist/utils/audio.js.map +1 -0
- package/dist/utils/exec-safe.d.ts +22 -0
- package/dist/utils/exec-safe.d.ts.map +1 -0
- package/dist/utils/exec-safe.js +62 -0
- package/dist/utils/exec-safe.js.map +1 -0
- package/dist/utils/first-run.d.ts +13 -0
- package/dist/utils/first-run.d.ts.map +1 -0
- package/dist/utils/first-run.js +48 -0
- package/dist/utils/first-run.js.map +1 -0
- package/dist/utils/provider-resolver.d.ts +15 -0
- package/dist/utils/provider-resolver.d.ts.map +1 -0
- package/dist/utils/provider-resolver.js +42 -0
- package/dist/utils/provider-resolver.js.map +1 -0
- package/dist/utils/remotion.d.ts +210 -0
- package/dist/utils/remotion.d.ts.map +1 -0
- package/dist/utils/remotion.js +731 -0
- package/dist/utils/remotion.js.map +1 -0
- package/dist/utils/subtitle.d.ts +65 -0
- package/dist/utils/subtitle.d.ts.map +1 -0
- package/dist/utils/subtitle.js +135 -0
- package/dist/utils/subtitle.js.map +1 -0
- package/dist/utils/subtitle.test.d.ts +2 -0
- package/dist/utils/subtitle.test.d.ts.map +1 -0
- package/dist/utils/subtitle.test.js +175 -0
- package/dist/utils/subtitle.test.js.map +1 -0
- package/dist/utils/tty.d.ts +45 -0
- package/dist/utils/tty.d.ts.map +1 -0
- package/dist/utils/tty.js +172 -0
- package/dist/utils/tty.js.map +1 -0
- package/package.json +102 -0
- package/src/agent/adapters/claude.ts +143 -0
- package/src/agent/adapters/gemini.ts +159 -0
- package/src/agent/adapters/index.ts +61 -0
- package/src/agent/adapters/ollama.ts +231 -0
- package/src/agent/adapters/openai.ts +116 -0
- package/src/agent/adapters/xai.ts +119 -0
- package/src/agent/index.ts +251 -0
- package/src/agent/memory/index.ts +151 -0
- package/src/agent/prompts/system.ts +106 -0
- package/src/agent/tools/ai-editing.ts +845 -0
- package/src/agent/tools/ai-generation.ts +1073 -0
- package/src/agent/tools/ai-pipeline.ts +1055 -0
- package/src/agent/tools/ai.ts +21 -0
- package/src/agent/tools/batch.ts +429 -0
- package/src/agent/tools/e2e.test.ts +545 -0
- package/src/agent/tools/export.ts +184 -0
- package/src/agent/tools/filesystem.ts +237 -0
- package/src/agent/tools/index.ts +150 -0
- package/src/agent/tools/integration.test.ts +775 -0
- package/src/agent/tools/media.ts +697 -0
- package/src/agent/tools/project.ts +313 -0
- package/src/agent/tools/timeline.ts +951 -0
- package/src/agent/types.ts +68 -0
- package/src/commands/agent.ts +340 -0
- package/src/commands/ai-analyze.ts +429 -0
- package/src/commands/ai-animated-caption.ts +390 -0
- package/src/commands/ai-audio.ts +941 -0
- package/src/commands/ai-broll.ts +490 -0
- package/src/commands/ai-edit-cli.ts +658 -0
- package/src/commands/ai-edit.ts +1542 -0
- package/src/commands/ai-fill-gaps.ts +566 -0
- package/src/commands/ai-helpers.ts +65 -0
- package/src/commands/ai-highlights.ts +1303 -0
- package/src/commands/ai-image.ts +761 -0
- package/src/commands/ai-motion.ts +347 -0
- package/src/commands/ai-narrate.ts +451 -0
- package/src/commands/ai-review.ts +309 -0
- package/src/commands/ai-script-pipeline-cli.ts +1710 -0
- package/src/commands/ai-script-pipeline.ts +1365 -0
- package/src/commands/ai-suggest-edit.ts +264 -0
- package/src/commands/ai-video-fx.ts +445 -0
- package/src/commands/ai-video.ts +915 -0
- package/src/commands/ai-viral.ts +595 -0
- package/src/commands/ai-visual-fx.ts +601 -0
- package/src/commands/ai.test.ts +627 -0
- package/src/commands/ai.ts +307 -0
- package/src/commands/analyze.ts +282 -0
- package/src/commands/audio.ts +644 -0
- package/src/commands/batch.test.ts +279 -0
- package/src/commands/batch.ts +440 -0
- package/src/commands/detect.ts +329 -0
- package/src/commands/doctor.ts +237 -0
- package/src/commands/edit-cmd.ts +1014 -0
- package/src/commands/export.ts +918 -0
- package/src/commands/generate.ts +2146 -0
- package/src/commands/media.ts +177 -0
- package/src/commands/output.ts +142 -0
- package/src/commands/pipeline.ts +398 -0
- package/src/commands/project.test.ts +127 -0
- package/src/commands/project.ts +149 -0
- package/src/commands/sanitize.ts +60 -0
- package/src/commands/schema.ts +130 -0
- package/src/commands/setup.ts +509 -0
- package/src/commands/timeline.test.ts +499 -0
- package/src/commands/timeline.ts +529 -0
- package/src/commands/validate.ts +77 -0
- package/src/config/config.test.ts +197 -0
- package/src/config/index.ts +125 -0
- package/src/config/schema.ts +82 -0
- package/src/engine/index.ts +2 -0
- package/src/engine/project.test.ts +702 -0
- package/src/engine/project.ts +439 -0
- package/src/index.ts +146 -0
- package/src/utils/api-key.test.ts +41 -0
- package/src/utils/api-key.ts +247 -0
- package/src/utils/audio.ts +83 -0
- package/src/utils/exec-safe.ts +75 -0
- package/src/utils/first-run.ts +52 -0
- package/src/utils/provider-resolver.ts +56 -0
- package/src/utils/remotion.ts +951 -0
- package/src/utils/subtitle.test.ts +227 -0
- package/src/utils/subtitle.ts +169 -0
- package/src/utils/tty.ts +196 -0
- package/tsconfig.json +20 -0
|
@@ -0,0 +1,1019 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module ai-edit
|
|
3
|
+
*
|
|
4
|
+
* Video/audio editing execute functions and supporting types.
|
|
5
|
+
*
|
|
6
|
+
* CLI commands: silence-cut, jump-cut, caption, noise-reduce, fade,
|
|
7
|
+
* translate-srt, text-overlay
|
|
8
|
+
*
|
|
9
|
+
* Execute functions (also used by agent tools via ai.ts re-exports):
|
|
10
|
+
* executeSilenceCut, executeJumpCut, executeCaption, executeNoiseReduce,
|
|
11
|
+
* executeFade, executeTranslateSrt, applyTextOverlays, executeTextOverlay
|
|
12
|
+
*
|
|
13
|
+
* CLI command registrations live in ai-edit-cli.ts (registerEditCommands).
|
|
14
|
+
* Extracted from ai.ts as part of modularisation.
|
|
15
|
+
*
|
|
16
|
+
* @dependencies FFmpeg, Whisper (OpenAI), Gemini (Google), Claude/OpenAI (translation)
|
|
17
|
+
*/
|
|
18
|
+
import { resolve, dirname, basename, extname, join } from 'node:path';
|
|
19
|
+
import { readFile, writeFile, mkdir } from 'node:fs/promises';
|
|
20
|
+
import { existsSync } from 'node:fs';
|
|
21
|
+
import { GeminiProvider, WhisperProvider, } from '@vibeframe/ai-providers';
|
|
22
|
+
import { getApiKey } from '../utils/api-key.js';
|
|
23
|
+
import { getVideoDuration } from '../utils/audio.js';
|
|
24
|
+
import { formatSRT, parseSRT } from '../utils/subtitle.js';
|
|
25
|
+
import { execSafe, commandExists } from '../utils/exec-safe.js';
|
|
26
|
+
/**
|
|
27
|
+
* Detect silent periods in a media file using FFmpeg silencedetect
|
|
28
|
+
*/
|
|
29
|
+
async function detectSilencePeriods(videoPath, noiseThreshold, minDuration) {
|
|
30
|
+
// Get total duration
|
|
31
|
+
const totalDuration = await getVideoDuration(videoPath);
|
|
32
|
+
// Run silence detection
|
|
33
|
+
const { stdout, stderr } = await execSafe("ffmpeg", [
|
|
34
|
+
"-i", videoPath,
|
|
35
|
+
"-af", `silencedetect=noise=${noiseThreshold}dB:d=${minDuration}`,
|
|
36
|
+
"-f", "null", "-",
|
|
37
|
+
], { maxBuffer: 50 * 1024 * 1024 }).catch((err) => {
|
|
38
|
+
// ffmpeg writes filter output to stderr and exits non-zero with -f null
|
|
39
|
+
if (err.stdout !== undefined || err.stderr !== undefined) {
|
|
40
|
+
return { stdout: err.stdout || "", stderr: err.stderr || "" };
|
|
41
|
+
}
|
|
42
|
+
throw err;
|
|
43
|
+
});
|
|
44
|
+
const silenceOutput = stdout + stderr;
|
|
45
|
+
const periods = [];
|
|
46
|
+
const startRegex = /silence_start: (\d+\.?\d*)/g;
|
|
47
|
+
const endRegex = /silence_end: (\d+\.?\d*) \| silence_duration: (\d+\.?\d*)/g;
|
|
48
|
+
const starts = [];
|
|
49
|
+
let match;
|
|
50
|
+
while ((match = startRegex.exec(silenceOutput)) !== null) {
|
|
51
|
+
starts.push(parseFloat(match[1]));
|
|
52
|
+
}
|
|
53
|
+
let i = 0;
|
|
54
|
+
while ((match = endRegex.exec(silenceOutput)) !== null) {
|
|
55
|
+
const end = parseFloat(match[1]);
|
|
56
|
+
const duration = parseFloat(match[2]);
|
|
57
|
+
const start = i < starts.length ? starts[i] : end - duration;
|
|
58
|
+
periods.push({ start, end, duration });
|
|
59
|
+
i++;
|
|
60
|
+
}
|
|
61
|
+
return { periods, totalDuration };
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Detect silent/dead segments using Gemini Video Understanding (multimodal analysis)
|
|
65
|
+
*/
|
|
66
|
+
async function detectSilencePeriodsWithGemini(videoPath, minDuration, options) {
|
|
67
|
+
const totalDuration = await getVideoDuration(videoPath);
|
|
68
|
+
const geminiApiKey = options.apiKey || await getApiKey("GOOGLE_API_KEY", "Google");
|
|
69
|
+
if (!geminiApiKey) {
|
|
70
|
+
throw new Error("Google API key required for Gemini Video Understanding. Run 'vibe setup' or set GOOGLE_API_KEY in .env");
|
|
71
|
+
}
|
|
72
|
+
const gemini = new GeminiProvider();
|
|
73
|
+
await gemini.initialize({ apiKey: geminiApiKey });
|
|
74
|
+
const videoBuffer = await readFile(videoPath);
|
|
75
|
+
// Map model shorthand to full model ID
|
|
76
|
+
const modelMap = {
|
|
77
|
+
flash: "gemini-3-flash-preview",
|
|
78
|
+
"flash-2.5": "gemini-2.5-flash",
|
|
79
|
+
pro: "gemini-2.5-pro",
|
|
80
|
+
};
|
|
81
|
+
const modelId = options.model ? (modelMap[options.model] || modelMap.flash) : undefined;
|
|
82
|
+
const prompt = `Analyze this video and identify all silent or dead segments where there is NO meaningful content.
|
|
83
|
+
|
|
84
|
+
Detect these as silent/dead segments:
|
|
85
|
+
- Complete silence (no audio at all)
|
|
86
|
+
- Dead air / ambient noise with no speech or meaningful sound
|
|
87
|
+
- Long pauses between speakers or topics (${minDuration}+ seconds)
|
|
88
|
+
- Technical silence (e.g., blank screen with no audio)
|
|
89
|
+
- Sections with only background noise and no intentional content
|
|
90
|
+
|
|
91
|
+
Do NOT mark these as silent (keep them):
|
|
92
|
+
- Intentional dramatic pauses (short, part of storytelling)
|
|
93
|
+
- Music-only sections (background music, intros, outros)
|
|
94
|
+
- Natural breathing pauses within sentences (under ${minDuration} seconds)
|
|
95
|
+
- Applause, laughter, or audience reactions
|
|
96
|
+
- Sound effects or ambient audio that is part of the content
|
|
97
|
+
|
|
98
|
+
Only include segments that are at least ${minDuration} seconds long.
|
|
99
|
+
The video total duration is ${totalDuration.toFixed(1)} seconds.
|
|
100
|
+
|
|
101
|
+
IMPORTANT: Respond ONLY with valid JSON in this exact format:
|
|
102
|
+
{
|
|
103
|
+
"silentSegments": [
|
|
104
|
+
{
|
|
105
|
+
"start": 5.2,
|
|
106
|
+
"end": 8.7,
|
|
107
|
+
"reason": "Dead air between speakers"
|
|
108
|
+
}
|
|
109
|
+
]
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
If there are no silent segments, return: { "silentSegments": [] }`;
|
|
113
|
+
const result = await gemini.analyzeVideo(videoBuffer, prompt, {
|
|
114
|
+
fps: 1,
|
|
115
|
+
lowResolution: options.lowRes,
|
|
116
|
+
...(modelId ? { model: modelId } : {}),
|
|
117
|
+
});
|
|
118
|
+
if (!result.success || !result.response) {
|
|
119
|
+
throw new Error(`Gemini analysis failed: ${result.error || "No response"}`);
|
|
120
|
+
}
|
|
121
|
+
// Parse JSON from Gemini response
|
|
122
|
+
let jsonStr = result.response;
|
|
123
|
+
const jsonMatch = jsonStr.match(/```(?:json)?\s*([\s\S]*?)```/);
|
|
124
|
+
if (jsonMatch)
|
|
125
|
+
jsonStr = jsonMatch[1];
|
|
126
|
+
const objectMatch = jsonStr.match(/\{[\s\S]*"silentSegments"[\s\S]*\}/);
|
|
127
|
+
if (objectMatch)
|
|
128
|
+
jsonStr = objectMatch[0];
|
|
129
|
+
const parsed = JSON.parse(jsonStr);
|
|
130
|
+
const periods = [];
|
|
131
|
+
if (parsed.silentSegments && Array.isArray(parsed.silentSegments)) {
|
|
132
|
+
for (const seg of parsed.silentSegments) {
|
|
133
|
+
const rawStart = Number(seg.start);
|
|
134
|
+
const rawEnd = Number(seg.end);
|
|
135
|
+
if (isNaN(rawStart) || isNaN(rawEnd))
|
|
136
|
+
continue;
|
|
137
|
+
// Clamp to video duration, then validate
|
|
138
|
+
const start = Math.max(0, rawStart);
|
|
139
|
+
const end = Math.min(rawEnd, totalDuration);
|
|
140
|
+
const duration = end - start;
|
|
141
|
+
if (duration >= minDuration) {
|
|
142
|
+
periods.push({ start, end, duration });
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
// Sort by start time
|
|
147
|
+
periods.sort((a, b) => a.start - b.start);
|
|
148
|
+
return { periods, totalDuration };
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Remove silent segments from a video using FFmpeg or Gemini detection.
|
|
152
|
+
*
|
|
153
|
+
* Detects silence via FFmpeg silencedetect (default) or Gemini multimodal
|
|
154
|
+
* analysis, then trims and concatenates the non-silent segments.
|
|
155
|
+
*
|
|
156
|
+
* @param options - Silence cut configuration
|
|
157
|
+
* @returns Result with output path and detected silent periods
|
|
158
|
+
*/
|
|
159
|
+
export async function executeSilenceCut(options) {
|
|
160
|
+
const { videoPath, outputPath, noiseThreshold = -30, minDuration = 0.5, padding = 0.1, analyzeOnly = false, useGemini = false, } = options;
|
|
161
|
+
if (!existsSync(videoPath)) {
|
|
162
|
+
return { success: false, error: `Video not found: ${videoPath}` };
|
|
163
|
+
}
|
|
164
|
+
if (!commandExists("ffmpeg")) {
|
|
165
|
+
return { success: false, error: "FFmpeg not found. Please install FFmpeg." };
|
|
166
|
+
}
|
|
167
|
+
const method = useGemini ? "gemini" : "ffmpeg";
|
|
168
|
+
try {
|
|
169
|
+
const { periods, totalDuration } = useGemini
|
|
170
|
+
? await detectSilencePeriodsWithGemini(videoPath, minDuration, {
|
|
171
|
+
model: options.model,
|
|
172
|
+
lowRes: options.lowRes,
|
|
173
|
+
apiKey: options.apiKey,
|
|
174
|
+
})
|
|
175
|
+
: await detectSilencePeriods(videoPath, noiseThreshold, minDuration);
|
|
176
|
+
const silentDuration = periods.reduce((sum, p) => sum + p.duration, 0);
|
|
177
|
+
if (analyzeOnly || periods.length === 0) {
|
|
178
|
+
return {
|
|
179
|
+
success: true,
|
|
180
|
+
totalDuration,
|
|
181
|
+
silentPeriods: periods,
|
|
182
|
+
silentDuration,
|
|
183
|
+
method,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
// Compute non-silent segments with padding
|
|
187
|
+
const segments = [];
|
|
188
|
+
let cursor = 0;
|
|
189
|
+
for (const period of periods) {
|
|
190
|
+
const segEnd = Math.min(period.start + padding, totalDuration);
|
|
191
|
+
if (segEnd > cursor) {
|
|
192
|
+
segments.push({ start: Math.max(0, cursor - padding), end: segEnd });
|
|
193
|
+
}
|
|
194
|
+
cursor = period.end;
|
|
195
|
+
}
|
|
196
|
+
// Add final segment after last silence
|
|
197
|
+
if (cursor < totalDuration) {
|
|
198
|
+
segments.push({ start: Math.max(0, cursor - padding), end: totalDuration });
|
|
199
|
+
}
|
|
200
|
+
if (segments.length === 0) {
|
|
201
|
+
return { success: false, error: "No non-silent segments found" };
|
|
202
|
+
}
|
|
203
|
+
// Build filter_complex with trim+concat per segment.
|
|
204
|
+
// aselect is broken on FFmpeg 8.x (audio duration unchanged), so we use
|
|
205
|
+
// atrim/trim per segment and concat them all.
|
|
206
|
+
const vParts = [];
|
|
207
|
+
const aParts = [];
|
|
208
|
+
const concatInputs = [];
|
|
209
|
+
for (let i = 0; i < segments.length; i++) {
|
|
210
|
+
const s = segments[i].start.toFixed(4);
|
|
211
|
+
const e = segments[i].end.toFixed(4);
|
|
212
|
+
vParts.push(`[0:v]trim=${s}:${e},setpts=PTS-STARTPTS[v${i}]`);
|
|
213
|
+
aParts.push(`[0:a]atrim=${s}:${e},asetpts=PTS-STARTPTS[a${i}]`);
|
|
214
|
+
concatInputs.push(`[v${i}][a${i}]`);
|
|
215
|
+
}
|
|
216
|
+
const filterComplex = [
|
|
217
|
+
...vParts,
|
|
218
|
+
...aParts,
|
|
219
|
+
`${concatInputs.join("")}concat=n=${segments.length}:v=1:a=1[outv][outa]`,
|
|
220
|
+
].join(";");
|
|
221
|
+
await execSafe("ffmpeg", [
|
|
222
|
+
"-i", videoPath,
|
|
223
|
+
"-filter_complex", filterComplex,
|
|
224
|
+
"-map", "[outv]", "-map", "[outa]",
|
|
225
|
+
"-c:v", "libx264", "-preset", "fast", "-crf", "18",
|
|
226
|
+
"-c:a", "aac", "-b:a", "192k",
|
|
227
|
+
outputPath, "-y",
|
|
228
|
+
], { timeout: 600000, maxBuffer: 50 * 1024 * 1024 });
|
|
229
|
+
return {
|
|
230
|
+
success: true,
|
|
231
|
+
outputPath,
|
|
232
|
+
totalDuration,
|
|
233
|
+
silentPeriods: periods,
|
|
234
|
+
silentDuration,
|
|
235
|
+
method,
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
catch (error) {
|
|
239
|
+
return {
|
|
240
|
+
success: false,
|
|
241
|
+
error: `Silence cut failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
/** Default set of filler words detected by jump-cut. */
|
|
246
|
+
export const DEFAULT_FILLER_WORDS = [
|
|
247
|
+
"um", "uh", "uh-huh", "hmm", "like", "you know", "so",
|
|
248
|
+
"basically", "literally", "right", "okay", "well", "i mean", "actually",
|
|
249
|
+
];
|
|
250
|
+
/**
|
|
251
|
+
* Transcribe audio with word-level timestamps using Whisper API directly.
|
|
252
|
+
* Uses timestamp_granularities[]=word for filler detection.
|
|
253
|
+
*/
|
|
254
|
+
export async function transcribeWithWords(audioPath, apiKey, language) {
|
|
255
|
+
const audioBuffer = await readFile(audioPath);
|
|
256
|
+
const audioBlob = new Blob([audioBuffer]);
|
|
257
|
+
const formData = new FormData();
|
|
258
|
+
formData.append("file", audioBlob, "audio.wav");
|
|
259
|
+
formData.append("model", "whisper-1");
|
|
260
|
+
formData.append("response_format", "verbose_json");
|
|
261
|
+
formData.append("timestamp_granularities[]", "word");
|
|
262
|
+
if (language) {
|
|
263
|
+
formData.append("language", language);
|
|
264
|
+
}
|
|
265
|
+
const response = await fetch("https://api.openai.com/v1/audio/transcriptions", {
|
|
266
|
+
method: "POST",
|
|
267
|
+
headers: {
|
|
268
|
+
Authorization: `Bearer ${apiKey}`,
|
|
269
|
+
},
|
|
270
|
+
body: formData,
|
|
271
|
+
});
|
|
272
|
+
if (!response.ok) {
|
|
273
|
+
const error = await response.text();
|
|
274
|
+
throw new Error(`Whisper transcription failed: ${error}`);
|
|
275
|
+
}
|
|
276
|
+
const data = await response.json();
|
|
277
|
+
return {
|
|
278
|
+
words: data.words || [],
|
|
279
|
+
text: data.text,
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Detect filler word ranges and merge adjacent ones within padding distance.
|
|
284
|
+
*
|
|
285
|
+
* @param words - Word-level transcript with timestamps
|
|
286
|
+
* @param fillers - List of filler words/phrases to match
|
|
287
|
+
* @param padding - Maximum gap in seconds to merge adjacent fillers
|
|
288
|
+
* @returns Merged filler word ranges sorted by start time
|
|
289
|
+
*/
|
|
290
|
+
export function detectFillerRanges(words, fillers, padding) {
|
|
291
|
+
const fillerSet = new Set(fillers.map((f) => f.toLowerCase().trim()));
|
|
292
|
+
// Find individual filler words
|
|
293
|
+
const matches = [];
|
|
294
|
+
for (const w of words) {
|
|
295
|
+
const cleaned = w.word.toLowerCase().replace(/[^a-z\s-]/g, "").trim();
|
|
296
|
+
if (fillerSet.has(cleaned)) {
|
|
297
|
+
matches.push({ word: w.word, start: w.start, end: w.end });
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
if (matches.length === 0)
|
|
301
|
+
return [];
|
|
302
|
+
// Merge adjacent filler ranges (within padding distance)
|
|
303
|
+
const merged = [{ ...matches[0] }];
|
|
304
|
+
for (let i = 1; i < matches.length; i++) {
|
|
305
|
+
const last = merged[merged.length - 1];
|
|
306
|
+
if (matches[i].start - last.end <= padding * 2) {
|
|
307
|
+
last.end = matches[i].end;
|
|
308
|
+
last.word += ` ${matches[i].word}`;
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
merged.push({ ...matches[i] });
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
return merged;
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Remove filler words from a video using Whisper word-level timestamps + FFmpeg concat.
|
|
318
|
+
*
|
|
319
|
+
* Pipeline: extract audio -> Whisper transcription (word-level) -> detect fillers ->
|
|
320
|
+
* invert to keep-segments -> FFmpeg stream-copy concat.
|
|
321
|
+
*
|
|
322
|
+
* @param options - Jump cut configuration
|
|
323
|
+
* @returns Result with output path and detected fillers
|
|
324
|
+
*/
|
|
325
|
+
export async function executeJumpCut(options) {
|
|
326
|
+
const { videoPath, outputPath, fillers = DEFAULT_FILLER_WORDS, padding = 0.05, language, analyzeOnly = false, apiKey, } = options;
|
|
327
|
+
if (!existsSync(videoPath)) {
|
|
328
|
+
return { success: false, error: `Video not found: ${videoPath}` };
|
|
329
|
+
}
|
|
330
|
+
if (!commandExists("ffmpeg")) {
|
|
331
|
+
return { success: false, error: "FFmpeg not found. Please install FFmpeg." };
|
|
332
|
+
}
|
|
333
|
+
const openaiKey = apiKey || process.env.OPENAI_API_KEY;
|
|
334
|
+
if (!openaiKey) {
|
|
335
|
+
return { success: false, error: "OpenAI API key required for Whisper transcription. Run 'vibe setup' or set OPENAI_API_KEY in .env" };
|
|
336
|
+
}
|
|
337
|
+
try {
|
|
338
|
+
const tmpDir = `/tmp/vibe_jumpcut_${Date.now()}`;
|
|
339
|
+
await mkdir(tmpDir, { recursive: true });
|
|
340
|
+
const audioPath = join(tmpDir, "audio.wav");
|
|
341
|
+
try {
|
|
342
|
+
// Step 1: Extract audio
|
|
343
|
+
await execSafe("ffmpeg", [
|
|
344
|
+
"-i", videoPath, "-vn", "-acodec", "pcm_s16le", "-ar", "16000", "-ac", "1", audioPath, "-y",
|
|
345
|
+
], { timeout: 300000, maxBuffer: 50 * 1024 * 1024 });
|
|
346
|
+
// Step 2: Transcribe with word-level timestamps
|
|
347
|
+
const { words } = await transcribeWithWords(audioPath, openaiKey, language);
|
|
348
|
+
if (words.length === 0) {
|
|
349
|
+
return { success: false, error: "No words detected in audio" };
|
|
350
|
+
}
|
|
351
|
+
// Step 3: Detect filler ranges
|
|
352
|
+
const fillerRanges = detectFillerRanges(words, fillers, padding);
|
|
353
|
+
const totalDuration = await getVideoDuration(videoPath);
|
|
354
|
+
const fillerDuration = fillerRanges.reduce((sum, f) => sum + (f.end - f.start), 0);
|
|
355
|
+
if (analyzeOnly || fillerRanges.length === 0) {
|
|
356
|
+
return {
|
|
357
|
+
success: true,
|
|
358
|
+
totalDuration,
|
|
359
|
+
fillerCount: fillerRanges.length,
|
|
360
|
+
fillerDuration,
|
|
361
|
+
fillers: fillerRanges,
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
// Step 4: Compute keep-segments (invert filler ranges)
|
|
365
|
+
const segments = [];
|
|
366
|
+
let cursor = 0;
|
|
367
|
+
for (const filler of fillerRanges) {
|
|
368
|
+
const segStart = Math.max(0, cursor);
|
|
369
|
+
const segEnd = Math.max(segStart, filler.start - padding);
|
|
370
|
+
if (segEnd > segStart) {
|
|
371
|
+
segments.push({ start: segStart, end: segEnd });
|
|
372
|
+
}
|
|
373
|
+
cursor = filler.end + padding;
|
|
374
|
+
}
|
|
375
|
+
// Add final segment after last filler
|
|
376
|
+
if (cursor < totalDuration) {
|
|
377
|
+
segments.push({ start: cursor, end: totalDuration });
|
|
378
|
+
}
|
|
379
|
+
if (segments.length === 0) {
|
|
380
|
+
return { success: false, error: "No non-filler segments found" };
|
|
381
|
+
}
|
|
382
|
+
// Step 5: Extract segments and concat with FFmpeg (stream copy)
|
|
383
|
+
const segmentPaths = [];
|
|
384
|
+
for (let i = 0; i < segments.length; i++) {
|
|
385
|
+
const seg = segments[i];
|
|
386
|
+
const segPath = join(tmpDir, `seg-${i.toString().padStart(4, "0")}.ts`);
|
|
387
|
+
const duration = seg.end - seg.start;
|
|
388
|
+
await execSafe("ffmpeg", [
|
|
389
|
+
"-i", videoPath, "-ss", String(seg.start), "-t", String(duration),
|
|
390
|
+
"-c", "copy", "-avoid_negative_ts", "make_zero", segPath, "-y",
|
|
391
|
+
], { timeout: 300000, maxBuffer: 50 * 1024 * 1024 });
|
|
392
|
+
segmentPaths.push(segPath);
|
|
393
|
+
}
|
|
394
|
+
// Create concat list
|
|
395
|
+
const concatList = segmentPaths.map((p) => `file '${p}'`).join("\n");
|
|
396
|
+
const listPath = join(tmpDir, "concat.txt");
|
|
397
|
+
await writeFile(listPath, concatList);
|
|
398
|
+
// Concat segments
|
|
399
|
+
await execSafe("ffmpeg", [
|
|
400
|
+
"-f", "concat", "-safe", "0", "-i", listPath, "-c", "copy", outputPath, "-y",
|
|
401
|
+
], { timeout: 300000, maxBuffer: 50 * 1024 * 1024 });
|
|
402
|
+
return {
|
|
403
|
+
success: true,
|
|
404
|
+
outputPath,
|
|
405
|
+
totalDuration,
|
|
406
|
+
fillerCount: fillerRanges.length,
|
|
407
|
+
fillerDuration,
|
|
408
|
+
fillers: fillerRanges,
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
finally {
|
|
412
|
+
// Cleanup temp files
|
|
413
|
+
try {
|
|
414
|
+
const { rm } = await import("node:fs/promises");
|
|
415
|
+
await rm(tmpDir, { recursive: true, force: true });
|
|
416
|
+
}
|
|
417
|
+
catch {
|
|
418
|
+
// Ignore cleanup errors
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
catch (error) {
|
|
423
|
+
return {
|
|
424
|
+
success: false,
|
|
425
|
+
error: `Jump cut failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Get ASS force_style string for caption preset
|
|
431
|
+
*/
|
|
432
|
+
function getCaptionForceStyle(style, fontSize, fontColor, position) {
|
|
433
|
+
// ASS alignment: 1-3 bottom, 4-6 middle, 7-9 top (left/center/right)
|
|
434
|
+
const alignment = position === "top" ? 8 : position === "center" ? 5 : 2;
|
|
435
|
+
const marginV = position === "center" ? 0 : 30;
|
|
436
|
+
switch (style) {
|
|
437
|
+
case "minimal":
|
|
438
|
+
return `FontSize=${fontSize},FontName=Arial,PrimaryColour=&H00FFFFFF,OutlineColour=&H80000000,Outline=1,Shadow=0,Alignment=${alignment},MarginV=${marginV}`;
|
|
439
|
+
case "bold":
|
|
440
|
+
return `FontSize=${fontSize},FontName=Arial,Bold=1,PrimaryColour=&H00${fontColor === "yellow" ? "00FFFF" : "FFFFFF"},OutlineColour=&H00000000,Outline=3,Shadow=1,Alignment=${alignment},MarginV=${marginV}`;
|
|
441
|
+
case "outline":
|
|
442
|
+
return `FontSize=${fontSize},FontName=Arial,Bold=1,PrimaryColour=&H00FFFFFF,OutlineColour=&H000000FF,Outline=4,Shadow=0,Alignment=${alignment},MarginV=${marginV}`;
|
|
443
|
+
case "karaoke":
|
|
444
|
+
return `FontSize=${fontSize},FontName=Arial,Bold=1,PrimaryColour=&H0000FFFF,OutlineColour=&H00000000,Outline=2,Shadow=1,Alignment=${alignment},MarginV=${marginV}`;
|
|
445
|
+
default:
|
|
446
|
+
return `FontSize=${fontSize},FontName=Arial,Bold=1,PrimaryColour=&H00FFFFFF,OutlineColour=&H00000000,Outline=3,Shadow=1,Alignment=${alignment},MarginV=${marginV}`;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Transcribe video audio and burn styled captions using Whisper + FFmpeg.
|
|
451
|
+
*
|
|
452
|
+
* Pipeline: extract audio -> Whisper transcription -> generate SRT ->
|
|
453
|
+
* burn captions via FFmpeg subtitles filter (or Remotion fallback).
|
|
454
|
+
*
|
|
455
|
+
* @param options - Caption configuration
|
|
456
|
+
* @returns Result with output video path and SRT path
|
|
457
|
+
*/
|
|
458
|
+
export async function executeCaption(options) {
|
|
459
|
+
const { videoPath, outputPath, style = "bold", fontSize: customFontSize, fontColor = "white", language, position = "bottom", apiKey, } = options;
|
|
460
|
+
if (!existsSync(videoPath)) {
|
|
461
|
+
return { success: false, error: `Video not found: ${videoPath}` };
|
|
462
|
+
}
|
|
463
|
+
if (!commandExists("ffmpeg")) {
|
|
464
|
+
return { success: false, error: "FFmpeg not found. Please install FFmpeg." };
|
|
465
|
+
}
|
|
466
|
+
const openaiKey = apiKey || process.env.OPENAI_API_KEY;
|
|
467
|
+
if (!openaiKey) {
|
|
468
|
+
return { success: false, error: "OpenAI API key required for Whisper transcription. Run 'vibe setup' or set OPENAI_API_KEY in .env" };
|
|
469
|
+
}
|
|
470
|
+
try {
|
|
471
|
+
// Step 1: Extract audio from video
|
|
472
|
+
const tmpDir = `/tmp/vibe_caption_${Date.now()}`;
|
|
473
|
+
await mkdir(tmpDir, { recursive: true });
|
|
474
|
+
const audioPath = join(tmpDir, "audio.wav");
|
|
475
|
+
const srtPath = join(tmpDir, "captions.srt");
|
|
476
|
+
try {
|
|
477
|
+
await execSafe("ffmpeg", [
|
|
478
|
+
"-i", videoPath, "-vn", "-acodec", "pcm_s16le", "-ar", "16000", "-ac", "1", audioPath, "-y",
|
|
479
|
+
], { timeout: 300000, maxBuffer: 50 * 1024 * 1024 });
|
|
480
|
+
// Step 2: Transcribe with Whisper
|
|
481
|
+
const whisper = new WhisperProvider();
|
|
482
|
+
await whisper.initialize({ apiKey: openaiKey });
|
|
483
|
+
const audioBuffer = await readFile(audioPath);
|
|
484
|
+
const audioBlob = new Blob([audioBuffer]);
|
|
485
|
+
const transcriptResult = await whisper.transcribe(audioBlob, language);
|
|
486
|
+
if (transcriptResult.status === "failed" || !transcriptResult.segments || transcriptResult.segments.length === 0) {
|
|
487
|
+
return { success: false, error: `Transcription failed: ${transcriptResult.error || "No segments detected"}` };
|
|
488
|
+
}
|
|
489
|
+
// Step 3: Generate SRT
|
|
490
|
+
const srtContent = formatSRT(transcriptResult.segments);
|
|
491
|
+
await writeFile(srtPath, srtContent);
|
|
492
|
+
// Step 4: Get video resolution for auto font size
|
|
493
|
+
const { width, height } = await getVideoResolution(videoPath);
|
|
494
|
+
const fontSize = customFontSize || Math.round(height / 18);
|
|
495
|
+
// Step 5: Check FFmpeg subtitle filter support
|
|
496
|
+
let hasSubtitles = false;
|
|
497
|
+
try {
|
|
498
|
+
const { stdout: filterList } = await execSafe("ffmpeg", ["-filters"], { maxBuffer: 10 * 1024 * 1024 });
|
|
499
|
+
hasSubtitles = filterList.includes("subtitles");
|
|
500
|
+
}
|
|
501
|
+
catch {
|
|
502
|
+
// If filter check fails, continue and let FFmpeg error naturally
|
|
503
|
+
}
|
|
504
|
+
// Step 6: Burn captions
|
|
505
|
+
if (hasSubtitles) {
|
|
506
|
+
// Fast path: FFmpeg subtitles filter (requires libass)
|
|
507
|
+
const forceStyle = getCaptionForceStyle(style, fontSize, fontColor, position);
|
|
508
|
+
const escapedSrtPath = srtPath.replace(/\\/g, "/").replace(/:/g, "\\:");
|
|
509
|
+
await execSafe("ffmpeg", [
|
|
510
|
+
"-i", videoPath, "-vf", `subtitles=${escapedSrtPath}:force_style='${forceStyle}'`,
|
|
511
|
+
"-c:a", "copy", outputPath, "-y",
|
|
512
|
+
], { timeout: 600000, maxBuffer: 50 * 1024 * 1024 });
|
|
513
|
+
}
|
|
514
|
+
else {
|
|
515
|
+
// Remotion fallback: embed video + captions in a single Remotion composition
|
|
516
|
+
console.log("FFmpeg missing subtitles filter (libass) — using Remotion fallback...");
|
|
517
|
+
const { generateCaptionComponent, renderWithEmbeddedVideo, ensureRemotionInstalled } = await import("../utils/remotion.js");
|
|
518
|
+
const remotionErr = await ensureRemotionInstalled();
|
|
519
|
+
if (remotionErr) {
|
|
520
|
+
// Save SRT so the user still gets something
|
|
521
|
+
const outputDir = dirname(outputPath);
|
|
522
|
+
const outputSrtPath = join(outputDir, basename(outputPath, extname(outputPath)) + ".srt");
|
|
523
|
+
await writeFile(outputSrtPath, srtContent);
|
|
524
|
+
return { success: false, error: `${remotionErr}\nSRT saved to: ${outputSrtPath}` };
|
|
525
|
+
}
|
|
526
|
+
const videoDuration = await getVideoDuration(videoPath);
|
|
527
|
+
const fps = 30;
|
|
528
|
+
const durationInFrames = Math.ceil(videoDuration * fps);
|
|
529
|
+
const videoFileName = "source_video.mp4";
|
|
530
|
+
const { code, name } = generateCaptionComponent({
|
|
531
|
+
segments: transcriptResult.segments.map((s) => ({
|
|
532
|
+
start: s.startTime,
|
|
533
|
+
end: s.endTime,
|
|
534
|
+
text: s.text,
|
|
535
|
+
})),
|
|
536
|
+
style,
|
|
537
|
+
fontSize,
|
|
538
|
+
fontColor,
|
|
539
|
+
position,
|
|
540
|
+
width,
|
|
541
|
+
height,
|
|
542
|
+
videoFileName,
|
|
543
|
+
});
|
|
544
|
+
const renderResult = await renderWithEmbeddedVideo({
|
|
545
|
+
componentCode: code,
|
|
546
|
+
componentName: name,
|
|
547
|
+
width,
|
|
548
|
+
height,
|
|
549
|
+
fps,
|
|
550
|
+
durationInFrames,
|
|
551
|
+
videoPath,
|
|
552
|
+
videoFileName,
|
|
553
|
+
outputPath,
|
|
554
|
+
});
|
|
555
|
+
if (!renderResult.success) {
|
|
556
|
+
const outputDir = dirname(outputPath);
|
|
557
|
+
const outputSrtPath = join(outputDir, basename(outputPath, extname(outputPath)) + ".srt");
|
|
558
|
+
await writeFile(outputSrtPath, srtContent);
|
|
559
|
+
return { success: false, error: `${renderResult.error}\nSRT saved to: ${outputSrtPath}` };
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
// Copy SRT to output directory for user reference
|
|
563
|
+
const outputDir = dirname(outputPath);
|
|
564
|
+
const outputSrtPath = join(outputDir, basename(outputPath, extname(outputPath)) + ".srt");
|
|
565
|
+
await writeFile(outputSrtPath, srtContent);
|
|
566
|
+
return {
|
|
567
|
+
success: true,
|
|
568
|
+
outputPath,
|
|
569
|
+
srtPath: outputSrtPath,
|
|
570
|
+
segmentCount: transcriptResult.segments.length,
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
finally {
|
|
574
|
+
// Cleanup temp files
|
|
575
|
+
try {
|
|
576
|
+
const { rm } = await import("node:fs/promises");
|
|
577
|
+
await rm(tmpDir, { recursive: true, force: true });
|
|
578
|
+
}
|
|
579
|
+
catch {
|
|
580
|
+
// Ignore cleanup errors
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
catch (error) {
|
|
585
|
+
return {
|
|
586
|
+
success: false,
|
|
587
|
+
error: `Caption failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
588
|
+
};
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
592
|
+
* Reduce audio noise in a video or audio file using FFmpeg afftdn filter.
|
|
593
|
+
*
|
|
594
|
+
* Supports three strength presets (low/medium/high) with optional highpass/lowpass
|
|
595
|
+
* for the "high" setting. Video streams are copied without re-encoding.
|
|
596
|
+
*
|
|
597
|
+
* @param options - Noise reduction configuration
|
|
598
|
+
* @returns Result with output path and input duration
|
|
599
|
+
*/
|
|
600
|
+
export async function executeNoiseReduce(options) {
|
|
601
|
+
const { inputPath, outputPath, strength = "medium", noiseFloor, } = options;
|
|
602
|
+
if (!existsSync(inputPath)) {
|
|
603
|
+
return { success: false, error: `File not found: ${inputPath}` };
|
|
604
|
+
}
|
|
605
|
+
if (!commandExists("ffmpeg")) {
|
|
606
|
+
return { success: false, error: "FFmpeg not found. Please install FFmpeg." };
|
|
607
|
+
}
|
|
608
|
+
try {
|
|
609
|
+
const inputDuration = await getVideoDuration(inputPath);
|
|
610
|
+
// Map strength to noise floor dB value
|
|
611
|
+
const nf = noiseFloor ?? (strength === "low" ? -20 : strength === "high" ? -35 : -25);
|
|
612
|
+
// Build audio filter
|
|
613
|
+
let audioFilter = `afftdn=nf=${nf}`;
|
|
614
|
+
if (strength === "high") {
|
|
615
|
+
audioFilter = `${audioFilter},highpass=f=80,lowpass=f=12000`;
|
|
616
|
+
}
|
|
617
|
+
// Check if input has video stream
|
|
618
|
+
let hasVideo = false;
|
|
619
|
+
try {
|
|
620
|
+
const { stdout } = await execSafe("ffprobe", [
|
|
621
|
+
"-v", "error", "-select_streams", "v", "-show_entries", "stream=codec_type", "-of", "csv=p=0", inputPath,
|
|
622
|
+
], { maxBuffer: 10 * 1024 * 1024 });
|
|
623
|
+
hasVideo = stdout.trim().includes("video");
|
|
624
|
+
}
|
|
625
|
+
catch {
|
|
626
|
+
// No video stream
|
|
627
|
+
}
|
|
628
|
+
const args = ["-i", inputPath, "-af", audioFilter];
|
|
629
|
+
if (hasVideo)
|
|
630
|
+
args.push("-c:v", "copy");
|
|
631
|
+
args.push(outputPath, "-y");
|
|
632
|
+
await execSafe("ffmpeg", args, { timeout: 600000, maxBuffer: 50 * 1024 * 1024 });
|
|
633
|
+
return {
|
|
634
|
+
success: true,
|
|
635
|
+
outputPath,
|
|
636
|
+
inputDuration,
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
catch (error) {
|
|
640
|
+
return {
|
|
641
|
+
success: false,
|
|
642
|
+
error: `Noise reduction failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
/**
|
|
647
|
+
* Apply fade-in and/or fade-out effects to video and/or audio using FFmpeg.
|
|
648
|
+
*
|
|
649
|
+
* @param options - Fade configuration
|
|
650
|
+
* @returns Result with output path and which fades were applied
|
|
651
|
+
*/
|
|
652
|
+
export async function executeFade(options) {
|
|
653
|
+
const { videoPath, outputPath, fadeIn = 1, fadeOut = 1, audioOnly = false, videoOnly = false, } = options;
|
|
654
|
+
if (!existsSync(videoPath)) {
|
|
655
|
+
return { success: false, error: `Video not found: ${videoPath}` };
|
|
656
|
+
}
|
|
657
|
+
if (!commandExists("ffmpeg")) {
|
|
658
|
+
return { success: false, error: "FFmpeg not found. Please install FFmpeg." };
|
|
659
|
+
}
|
|
660
|
+
try {
|
|
661
|
+
const totalDuration = await getVideoDuration(videoPath);
|
|
662
|
+
const videoFilters = [];
|
|
663
|
+
const audioFilters = [];
|
|
664
|
+
// Video fade filters
|
|
665
|
+
if (!audioOnly) {
|
|
666
|
+
if (fadeIn > 0) {
|
|
667
|
+
videoFilters.push(`fade=t=in:st=0:d=${fadeIn}`);
|
|
668
|
+
}
|
|
669
|
+
if (fadeOut > 0) {
|
|
670
|
+
const fadeOutStart = Math.max(0, totalDuration - fadeOut);
|
|
671
|
+
videoFilters.push(`fade=t=out:st=${fadeOutStart}:d=${fadeOut}`);
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
// Audio fade filters
|
|
675
|
+
if (!videoOnly) {
|
|
676
|
+
if (fadeIn > 0) {
|
|
677
|
+
audioFilters.push(`afade=t=in:st=0:d=${fadeIn}`);
|
|
678
|
+
}
|
|
679
|
+
if (fadeOut > 0) {
|
|
680
|
+
const fadeOutStart = Math.max(0, totalDuration - fadeOut);
|
|
681
|
+
audioFilters.push(`afade=t=out:st=${fadeOutStart}:d=${fadeOut}`);
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
// Build FFmpeg command
|
|
685
|
+
const ffmpegArgs = ["-i", videoPath];
|
|
686
|
+
if (videoFilters.length > 0) {
|
|
687
|
+
ffmpegArgs.push("-vf", videoFilters.join(","));
|
|
688
|
+
}
|
|
689
|
+
else if (audioOnly) {
|
|
690
|
+
ffmpegArgs.push("-c:v", "copy");
|
|
691
|
+
}
|
|
692
|
+
if (audioFilters.length > 0) {
|
|
693
|
+
ffmpegArgs.push("-af", audioFilters.join(","));
|
|
694
|
+
}
|
|
695
|
+
else if (videoOnly) {
|
|
696
|
+
ffmpegArgs.push("-c:a", "copy");
|
|
697
|
+
}
|
|
698
|
+
ffmpegArgs.push(outputPath, "-y");
|
|
699
|
+
await execSafe("ffmpeg", ffmpegArgs, { timeout: 600000, maxBuffer: 50 * 1024 * 1024 });
|
|
700
|
+
return {
|
|
701
|
+
success: true,
|
|
702
|
+
outputPath,
|
|
703
|
+
totalDuration,
|
|
704
|
+
fadeInApplied: fadeIn > 0,
|
|
705
|
+
fadeOutApplied: fadeOut > 0,
|
|
706
|
+
};
|
|
707
|
+
}
|
|
708
|
+
catch (error) {
|
|
709
|
+
return {
|
|
710
|
+
success: false,
|
|
711
|
+
error: `Fade failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
/**
|
|
716
|
+
* Translate an SRT subtitle file to a target language using Claude or OpenAI.
|
|
717
|
+
*
|
|
718
|
+
* Segments are batched (~30 at a time) for efficient API usage. Preserves
|
|
719
|
+
* original timestamps; only text content is translated.
|
|
720
|
+
*
|
|
721
|
+
* @param options - Translation configuration
|
|
722
|
+
* @returns Result with output path and segment count
|
|
723
|
+
*/
|
|
724
|
+
export async function executeTranslateSrt(options) {
|
|
725
|
+
const { srtPath, outputPath, targetLanguage, provider = "claude", sourceLanguage, apiKey, } = options;
|
|
726
|
+
if (!existsSync(srtPath)) {
|
|
727
|
+
return { success: false, error: `SRT file not found: ${srtPath}` };
|
|
728
|
+
}
|
|
729
|
+
try {
|
|
730
|
+
const srtContent = await readFile(srtPath, "utf-8");
|
|
731
|
+
const segments = parseSRT(srtContent);
|
|
732
|
+
if (segments.length === 0) {
|
|
733
|
+
return { success: false, error: "No subtitle segments found in SRT file" };
|
|
734
|
+
}
|
|
735
|
+
// Batch translate segments (~30 at a time)
|
|
736
|
+
const batchSize = 30;
|
|
737
|
+
const translatedSegments = [];
|
|
738
|
+
for (let i = 0; i < segments.length; i += batchSize) {
|
|
739
|
+
const batch = segments.slice(i, i + batchSize);
|
|
740
|
+
const textsToTranslate = batch.map((s, idx) => `[${idx}] ${s.text}`).join("\n");
|
|
741
|
+
const translatePrompt = `Translate the following subtitle texts to ${targetLanguage}.` +
|
|
742
|
+
(sourceLanguage ? ` The source language is ${sourceLanguage}.` : "") +
|
|
743
|
+
` Return ONLY the translated texts, one per line, preserving the [N] prefix format exactly. ` +
|
|
744
|
+
`Do not add explanations.\n\n${textsToTranslate}`;
|
|
745
|
+
let translatedText;
|
|
746
|
+
if (provider === "openai") {
|
|
747
|
+
const openaiKey = apiKey || process.env.OPENAI_API_KEY;
|
|
748
|
+
if (!openaiKey) {
|
|
749
|
+
return { success: false, error: "OpenAI API key required for translation. Run 'vibe setup' or set OPENAI_API_KEY in .env" };
|
|
750
|
+
}
|
|
751
|
+
const response = await fetch("https://api.openai.com/v1/chat/completions", {
|
|
752
|
+
method: "POST",
|
|
753
|
+
headers: {
|
|
754
|
+
"Content-Type": "application/json",
|
|
755
|
+
Authorization: `Bearer ${openaiKey}`,
|
|
756
|
+
},
|
|
757
|
+
body: JSON.stringify({
|
|
758
|
+
model: "gpt-5-mini",
|
|
759
|
+
messages: [{ role: "user", content: translatePrompt }],
|
|
760
|
+
temperature: 0.3,
|
|
761
|
+
}),
|
|
762
|
+
});
|
|
763
|
+
if (!response.ok) {
|
|
764
|
+
return { success: false, error: `OpenAI API error: ${response.status} ${response.statusText}` };
|
|
765
|
+
}
|
|
766
|
+
const data = await response.json();
|
|
767
|
+
translatedText = data.choices[0]?.message?.content || "";
|
|
768
|
+
}
|
|
769
|
+
else {
|
|
770
|
+
const claudeKey = apiKey || process.env.ANTHROPIC_API_KEY;
|
|
771
|
+
if (!claudeKey) {
|
|
772
|
+
return { success: false, error: "Anthropic API key required for translation. Run 'vibe setup' or set ANTHROPIC_API_KEY in .env" };
|
|
773
|
+
}
|
|
774
|
+
const response = await fetch("https://api.anthropic.com/v1/messages", {
|
|
775
|
+
method: "POST",
|
|
776
|
+
headers: {
|
|
777
|
+
"Content-Type": "application/json",
|
|
778
|
+
"x-api-key": claudeKey,
|
|
779
|
+
"anthropic-version": "2023-06-01",
|
|
780
|
+
},
|
|
781
|
+
body: JSON.stringify({
|
|
782
|
+
model: "claude-sonnet-4-6-20250514",
|
|
783
|
+
max_tokens: 4096,
|
|
784
|
+
messages: [{ role: "user", content: translatePrompt }],
|
|
785
|
+
}),
|
|
786
|
+
});
|
|
787
|
+
if (!response.ok) {
|
|
788
|
+
return { success: false, error: `Claude API error: ${response.status} ${response.statusText}` };
|
|
789
|
+
}
|
|
790
|
+
const data = await response.json();
|
|
791
|
+
translatedText = data.content?.find((c) => c.type === "text")?.text || "";
|
|
792
|
+
}
|
|
793
|
+
// Parse translated lines
|
|
794
|
+
const translatedLines = translatedText.trim().split("\n");
|
|
795
|
+
for (let j = 0; j < batch.length; j++) {
|
|
796
|
+
const seg = batch[j];
|
|
797
|
+
// Try to match [N] prefix
|
|
798
|
+
const line = translatedLines[j];
|
|
799
|
+
let text;
|
|
800
|
+
if (line) {
|
|
801
|
+
text = line.replace(/^\[\d+\]\s*/, "").trim();
|
|
802
|
+
}
|
|
803
|
+
else {
|
|
804
|
+
// Fallback: use original text if translation is missing
|
|
805
|
+
text = seg.text;
|
|
806
|
+
}
|
|
807
|
+
translatedSegments.push({
|
|
808
|
+
startTime: seg.startTime,
|
|
809
|
+
endTime: seg.endTime,
|
|
810
|
+
text,
|
|
811
|
+
});
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
// Format as SRT and write
|
|
815
|
+
const translatedSrt = formatSRT(translatedSegments);
|
|
816
|
+
await writeFile(outputPath, translatedSrt);
|
|
817
|
+
return {
|
|
818
|
+
success: true,
|
|
819
|
+
outputPath,
|
|
820
|
+
segmentCount: translatedSegments.length,
|
|
821
|
+
sourceLanguage: sourceLanguage || "auto",
|
|
822
|
+
targetLanguage,
|
|
823
|
+
};
|
|
824
|
+
}
|
|
825
|
+
catch (error) {
|
|
826
|
+
return {
|
|
827
|
+
success: false,
|
|
828
|
+
error: `Translation failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
829
|
+
};
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
/**
|
|
833
|
+
* Detect system font path for FFmpeg drawtext
|
|
834
|
+
*/
|
|
835
|
+
function detectSystemFont() {
|
|
836
|
+
const platform = process.platform;
|
|
837
|
+
if (platform === "darwin") {
|
|
838
|
+
const candidates = [
|
|
839
|
+
"/System/Library/Fonts/Helvetica.ttc",
|
|
840
|
+
"/System/Library/Fonts/HelveticaNeue.ttc",
|
|
841
|
+
"/Library/Fonts/Arial.ttf",
|
|
842
|
+
];
|
|
843
|
+
for (const f of candidates) {
|
|
844
|
+
if (existsSync(f))
|
|
845
|
+
return f;
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
else if (platform === "linux") {
|
|
849
|
+
const candidates = [
|
|
850
|
+
"/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf",
|
|
851
|
+
"/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
|
|
852
|
+
"/usr/share/fonts/TTF/DejaVuSans-Bold.ttf",
|
|
853
|
+
];
|
|
854
|
+
for (const f of candidates) {
|
|
855
|
+
if (existsSync(f))
|
|
856
|
+
return f;
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
else if (platform === "win32") {
|
|
860
|
+
const candidates = [
|
|
861
|
+
"C:\\Windows\\Fonts\\arial.ttf",
|
|
862
|
+
"C:\\Windows\\Fonts\\segoeui.ttf",
|
|
863
|
+
];
|
|
864
|
+
for (const f of candidates) {
|
|
865
|
+
if (existsSync(f))
|
|
866
|
+
return f;
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
return null;
|
|
870
|
+
}
|
|
871
|
+
/**
|
|
872
|
+
* Get video resolution via ffprobe
|
|
873
|
+
*/
|
|
874
|
+
async function getVideoResolution(videoPath) {
|
|
875
|
+
const { stdout } = await execSafe("ffprobe", [
|
|
876
|
+
"-v", "error", "-select_streams", "v:0", "-show_entries", "stream=width,height", "-of", "csv=p=0", videoPath,
|
|
877
|
+
]);
|
|
878
|
+
const [w, h] = stdout.trim().split(",").map(Number);
|
|
879
|
+
return { width: w || 1920, height: h || 1080 };
|
|
880
|
+
}
|
|
881
|
+
/**
|
|
882
|
+
* Escape text for FFmpeg drawtext filter
|
|
883
|
+
*/
|
|
884
|
+
function escapeDrawtext(text) {
|
|
885
|
+
return text
|
|
886
|
+
.replace(/\\/g, "\\\\\\\\")
|
|
887
|
+
.replace(/'/g, "'\\\\\\''")
|
|
888
|
+
.replace(/:/g, "\\\\:")
|
|
889
|
+
.replace(/%/g, "\\\\%");
|
|
890
|
+
}
|
|
891
|
+
/**
|
|
892
|
+
* Apply text overlays to a video using FFmpeg drawtext filter.
|
|
893
|
+
*
|
|
894
|
+
* Supports multiple text lines with configurable style, position, font,
|
|
895
|
+
* and fade-in/out. Auto-detects system fonts across macOS, Linux, and Windows.
|
|
896
|
+
*
|
|
897
|
+
* @param options - Text overlay configuration
|
|
898
|
+
* @returns Result with absolute output path
|
|
899
|
+
*/
|
|
900
|
+
export async function applyTextOverlays(options) {
|
|
901
|
+
const { videoPath, texts, outputPath, style = "lower-third", fontSize: customFontSize, fontColor = "white", fadeDuration = 0.3, startTime = 0, } = options;
|
|
902
|
+
if (!texts || texts.length === 0) {
|
|
903
|
+
return { success: false, error: "No texts provided" };
|
|
904
|
+
}
|
|
905
|
+
const absVideoPath = resolve(process.cwd(), videoPath);
|
|
906
|
+
const absOutputPath = resolve(process.cwd(), outputPath);
|
|
907
|
+
// Check video exists
|
|
908
|
+
if (!existsSync(absVideoPath)) {
|
|
909
|
+
return { success: false, error: `Video not found: ${absVideoPath}` };
|
|
910
|
+
}
|
|
911
|
+
// Check FFmpeg
|
|
912
|
+
if (!commandExists("ffmpeg")) {
|
|
913
|
+
return { success: false, error: "FFmpeg not found. Please install FFmpeg." };
|
|
914
|
+
}
|
|
915
|
+
// Check drawtext filter availability
|
|
916
|
+
try {
|
|
917
|
+
const { stdout } = await execSafe("ffmpeg", ["-filters"]);
|
|
918
|
+
if (!stdout.includes("drawtext")) {
|
|
919
|
+
const platform = process.platform;
|
|
920
|
+
let hint = "";
|
|
921
|
+
if (platform === "darwin") {
|
|
922
|
+
hint = "\n\nFix: brew uninstall ffmpeg && brew install ffmpeg\n(The default homebrew formula includes libfreetype)";
|
|
923
|
+
}
|
|
924
|
+
else if (platform === "linux") {
|
|
925
|
+
hint = "\n\nFix: sudo apt install ffmpeg (Ubuntu/Debian)\n or rebuild FFmpeg with --enable-libfreetype";
|
|
926
|
+
}
|
|
927
|
+
return {
|
|
928
|
+
success: false,
|
|
929
|
+
error: `FFmpeg 'drawtext' filter not available. Your FFmpeg was built without libfreetype.${hint}`,
|
|
930
|
+
};
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
catch {
|
|
934
|
+
// If filter check fails, continue and let FFmpeg error naturally
|
|
935
|
+
}
|
|
936
|
+
// Get video resolution for scaling
|
|
937
|
+
const { width, height } = await getVideoResolution(absVideoPath);
|
|
938
|
+
const baseFontSize = customFontSize || Math.round(height / 20);
|
|
939
|
+
// Get video duration for endTime default
|
|
940
|
+
const videoDuration = await getVideoDuration(absVideoPath);
|
|
941
|
+
const endTime = options.endTime ?? videoDuration;
|
|
942
|
+
// Detect font
|
|
943
|
+
const fontPath = detectSystemFont();
|
|
944
|
+
const fontFile = fontPath ? `fontfile=${fontPath}:` : "";
|
|
945
|
+
// Build drawtext filters based on style
|
|
946
|
+
const filters = [];
|
|
947
|
+
for (let i = 0; i < texts.length; i++) {
|
|
948
|
+
const escaped = escapeDrawtext(texts[i]);
|
|
949
|
+
let x;
|
|
950
|
+
let y;
|
|
951
|
+
let fs;
|
|
952
|
+
let fc = fontColor;
|
|
953
|
+
let boxEnabled = 0;
|
|
954
|
+
let boxColor = "black@0.5";
|
|
955
|
+
let borderW = 0;
|
|
956
|
+
switch (style) {
|
|
957
|
+
case "center-bold":
|
|
958
|
+
x = "(w-text_w)/2";
|
|
959
|
+
y = `(h-text_h)/2+${i * Math.round(baseFontSize * 1.4)}`;
|
|
960
|
+
fs = Math.round(baseFontSize * 1.5);
|
|
961
|
+
borderW = 3;
|
|
962
|
+
break;
|
|
963
|
+
case "subtitle":
|
|
964
|
+
x = "(w-text_w)/2";
|
|
965
|
+
y = `h-${Math.round(height * 0.12)}+${i * Math.round(baseFontSize * 1.3)}`;
|
|
966
|
+
fs = baseFontSize;
|
|
967
|
+
boxEnabled = 1;
|
|
968
|
+
boxColor = "black@0.6";
|
|
969
|
+
break;
|
|
970
|
+
case "minimal":
|
|
971
|
+
x = `${Math.round(width * 0.05)}`;
|
|
972
|
+
y = `${Math.round(height * 0.05)}+${i * Math.round(baseFontSize * 1.3)}`;
|
|
973
|
+
fs = Math.round(baseFontSize * 0.8);
|
|
974
|
+
fc = "white@0.85";
|
|
975
|
+
break;
|
|
976
|
+
case "lower-third":
|
|
977
|
+
default:
|
|
978
|
+
x = `${Math.round(width * 0.05)}`;
|
|
979
|
+
y = `h-${Math.round(height * 0.18)}+${i * Math.round(baseFontSize * 1.3)}`;
|
|
980
|
+
fs = i === 0 ? Math.round(baseFontSize * 1.2) : baseFontSize;
|
|
981
|
+
boxEnabled = 1;
|
|
982
|
+
boxColor = "black@0.5";
|
|
983
|
+
break;
|
|
984
|
+
}
|
|
985
|
+
// Build alpha expression for fade in/out
|
|
986
|
+
const fadeIn = `if(lt(t-${startTime}\\,${fadeDuration})\\,(t-${startTime})/${fadeDuration}\\,1)`;
|
|
987
|
+
const fadeOut = `if(gt(t\\,${endTime - fadeDuration})\\,( ${endTime}-t)/${fadeDuration}\\,1)`;
|
|
988
|
+
const alpha = `min(${fadeIn}\\,${fadeOut})`;
|
|
989
|
+
let filter = `drawtext=${fontFile}text='${escaped}':fontsize=${fs}:fontcolor=${fc}:x=${x}:y=${y}:borderw=${borderW}:enable='between(t\\,${startTime}\\,${endTime})'`;
|
|
990
|
+
filter += `:alpha='${alpha}'`;
|
|
991
|
+
if (boxEnabled) {
|
|
992
|
+
filter += `:box=1:boxcolor=${boxColor}:boxborderw=8`;
|
|
993
|
+
}
|
|
994
|
+
filters.push(filter);
|
|
995
|
+
}
|
|
996
|
+
const filterChain = filters.join(",");
|
|
997
|
+
try {
|
|
998
|
+
await execSafe("ffmpeg", [
|
|
999
|
+
"-i", absVideoPath, "-vf", filterChain, "-c:a", "copy", absOutputPath, "-y",
|
|
1000
|
+
], { timeout: 600000, maxBuffer: 50 * 1024 * 1024 });
|
|
1001
|
+
return { success: true, outputPath: absOutputPath };
|
|
1002
|
+
}
|
|
1003
|
+
catch (error) {
|
|
1004
|
+
return {
|
|
1005
|
+
success: false,
|
|
1006
|
+
error: `FFmpeg failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
1007
|
+
};
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
/**
|
|
1011
|
+
* Execute text overlay for CLI/Agent usage. Delegates to {@link applyTextOverlays}.
|
|
1012
|
+
*
|
|
1013
|
+
* @param options - Text overlay configuration
|
|
1014
|
+
* @returns Result with absolute output path
|
|
1015
|
+
*/
|
|
1016
|
+
export async function executeTextOverlay(options) {
|
|
1017
|
+
return applyTextOverlays(options);
|
|
1018
|
+
}
|
|
1019
|
+
//# sourceMappingURL=ai-edit.js.map
|