Open source CapCut alternative.
TypeScript
fix(app): encode video with h264_videotoolbox, not the absent libx264
David Leae595632cae4
diff --git a/apps/Donkey/Sources/DonkeyRuntime/CaptionOrchestrator.swift b/apps/Donkey/Sources/DonkeyRuntime/CaptionOrchestrator.swiftindex c693db3b..a8dac048 100644--- a/apps/Donkey/Sources/DonkeyRuntime/CaptionOrchestrator.swift+++ b/apps/Donkey/Sources/DonkeyRuntime/CaptionOrchestrator.swift@@ -11,14 +11,15 @@ import Foundation/// encoder, so it probes `ffmpeg -encoders`; a `-c copy` trim of a webm yields the wrong duration, so it/// runs eight `ffprobe`s to debug — every probe a full-context LLM round-trip. Here the timings come from/// on-device transcription, the SRT is built from them (never parsed back from a model), the trim re-encodes-/// for an accurate span, and the burn pins `libx264 -pix_fmt yuv420p -c:a aac` so the video stream is never-/// dropped. The only model call is the optional translation.+/// for an accurate span, and the burn pins `h264_videotoolbox -pix_fmt yuv420p -c:a aac` so the video stream+/// is never dropped (VideoToolbox is the bundled LGPL ffmpeg's H.264 encoder — it has no libx264). The only+/// model call is the optional translation.////// ```/// resolve source (yt-dlp, with --download-sections for a URL span)/// → [trim local span] → extract audio → transcribe (on-device)/// → [translate cue texts] ← the ONE model call, only when a language is asked for-/// → build SRT in code → burn (libx264/yuv420p/aac) → verify+/// → build SRT in code → burn (h264_videotoolbox/yuv420p/aac) → verify/// ```public struct CaptionOrchestrator: Sendable {public typealias TranslateCues = @Sendable (_ lines: [String], _ targetLanguage: String) async -> [String]?@@ -92,7 +93,7 @@ public struct CaptionOrchestrator: Sendable {let burn = MediaPipeline.runStep("ffmpeg",["-y", "-i", base, "-vf", "subtitles=\((srtPath as NSString).lastPathComponent)",- "-c:v", "libx264", "-pix_fmt", "yuv420p", "-c:a", "aac", output],+ "-c:v", "h264_videotoolbox", "-pix_fmt", "yuv420p", "-c:a", "aac", output],workingDirectory: workdir, expecting: output, using: runTool)if case .ok = burn {@@ -158,7 +159,7 @@ public struct CaptionOrchestrator: Sendable {let trim = MediaPipeline.runStep("ffmpeg",["-y", "-i", resolved, "-ss", MediaSubtitles.seconds(startSec), "-t", MediaSubtitles.seconds(durationSec),- "-c:v", "libx264", "-preset", "veryfast", "-crf", "20", "-c:a", "aac", clip],+ "-c:v", "h264_videotoolbox", "-c:a", "aac", clip],workingDirectory: workdir, expecting: clip, using: runTool)if case let .failed(reason) = trim { return .failed(reason: "Could not cut the requested span: \(reason)") }diff --git a/apps/Donkey/Sources/DonkeyRuntime/Resources/BuiltInSkills/media/SKILL.md b/apps/Donkey/Sources/DonkeyRuntime/Resources/BuiltInSkills/media/SKILL.mdindex 577c00b1..0d110353 100644--- a/apps/Donkey/Sources/DonkeyRuntime/Resources/BuiltInSkills/media/SKILL.md+++ b/apps/Donkey/Sources/DonkeyRuntime/Resources/BuiltInSkills/media/SKILL.md@@ -52,7 +52,7 @@ filter script, and debugging encoders and durations — dozens of round-trips fois built to avoid exactly that.Reach for raw ffmpeg only to apply a subtitle file the user already has:-- Burn-in: `ffmpeg -i clip.mp4 -vf "subtitles=subs.srt" -c:v libx264 -pix_fmt yuv420p -c:a aac out.mp4`.+- Burn-in: `ffmpeg -i clip.mp4 -vf "subtitles=subs.srt" -c:v h264_videotoolbox -pix_fmt yuv420p -c:a aac out.mp4`. The bundled ffmpeg is the LGPL build with **no `libx264`** — use `h264_videotoolbox` (the hardware H.264 encoder that is present); don't pass `-preset`/`-crf` (it ignores them).- Soft, toggleable track (no libass, no re-encode): `ffmpeg -i clip.mp4 -i subs.srt -c copy -c:s mov_text out.mp4`.## Cut filler words or silencediff --git a/apps/Donkey/Sources/DonkeyRuntime/ShortsOrchestrator.swift b/apps/Donkey/Sources/DonkeyRuntime/ShortsOrchestrator.swiftindex eee81520..e1d7b693 100644--- a/apps/Donkey/Sources/DonkeyRuntime/ShortsOrchestrator.swift+++ b/apps/Donkey/Sources/DonkeyRuntime/ShortsOrchestrator.swift@@ -125,7 +125,7 @@ public struct ShortsOrchestrator: Sendable {let cut = MediaPipeline.runStep("ffmpeg",["-y", "-i", sourcePath, "-ss", Self.seconds(moment.startSec), "-t", Self.seconds(max(0.5, moment.durationSec)),- "-c:v", "libx264", "-preset", "veryfast", "-crf", "20", "-c:a", "aac", clip],+ "-c:v", "h264_videotoolbox", "-c:a", "aac", clip],workingDirectory: workdir, expecting: clip, using: runTool)if case let .failed(reason) = cut { return .failed(reason: "clip \(n): could not cut the span — \(reason)") }