mergestory 0.0.0-stage → 1.0.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/LICENSE +202 -0
- package/NOTICE +2 -0
- package/README.md +48 -2
- package/assets/kokoro-plugin/package-lock.json +1139 -0
- package/dist/analyzer/analyze.d.ts +8 -0
- package/dist/analyzer/analyze.js +328 -0
- package/dist/analyzer/components.d.ts +18 -0
- package/dist/analyzer/components.js +266 -0
- package/dist/analyzer/dependencies.d.ts +13 -0
- package/dist/analyzer/dependencies.js +349 -0
- package/dist/analyzer/evidence.d.ts +15 -0
- package/dist/analyzer/evidence.js +73 -0
- package/dist/analyzer/hunks.d.ts +21 -0
- package/dist/analyzer/hunks.js +88 -0
- package/dist/analyzer/imports.d.ts +46 -0
- package/dist/analyzer/imports.js +87 -0
- package/dist/analyzer/index.d.ts +14 -0
- package/dist/analyzer/index.js +16 -0
- package/dist/analyzer/languages/go.d.ts +2 -0
- package/dist/analyzer/languages/go.js +76 -0
- package/dist/analyzer/languages/index.d.ts +18 -0
- package/dist/analyzer/languages/index.js +72 -0
- package/dist/analyzer/languages/javascript.d.ts +2 -0
- package/dist/analyzer/languages/javascript.js +336 -0
- package/dist/analyzer/languages/jvm.d.ts +2 -0
- package/dist/analyzer/languages/jvm.js +157 -0
- package/dist/analyzer/languages/others.d.ts +2 -0
- package/dist/analyzer/languages/others.js +40 -0
- package/dist/analyzer/languages/php.d.ts +2 -0
- package/dist/analyzer/languages/php.js +81 -0
- package/dist/analyzer/languages/python.d.ts +2 -0
- package/dist/analyzer/languages/python.js +180 -0
- package/dist/analyzer/languages/ruby.d.ts +2 -0
- package/dist/analyzer/languages/ruby.js +99 -0
- package/dist/analyzer/languages/rust.d.ts +2 -0
- package/dist/analyzer/languages/rust.js +164 -0
- package/dist/analyzer/languages/shared.d.ts +35 -0
- package/dist/analyzer/languages/shared.js +43 -0
- package/dist/analyzer/languages/types.d.ts +78 -0
- package/dist/analyzer/languages/types.js +2 -0
- package/dist/analyzer/pack-format.d.ts +27 -0
- package/dist/analyzer/pack-format.js +139 -0
- package/dist/analyzer/pack.d.ts +26 -0
- package/dist/analyzer/pack.js +498 -0
- package/dist/analyzer/relationships.d.ts +17 -0
- package/dist/analyzer/relationships.js +34 -0
- package/dist/analyzer/risk-rules.d.ts +287 -0
- package/dist/analyzer/risk-rules.js +373 -0
- package/dist/analyzer/risks.d.ts +36 -0
- package/dist/analyzer/risks.js +480 -0
- package/dist/analyzer/roles.d.ts +11 -0
- package/dist/analyzer/roles.js +280 -0
- package/dist/analyzer/scan.d.ts +26 -0
- package/dist/analyzer/scan.js +157 -0
- package/dist/analyzer/signals.d.ts +20 -0
- package/dist/analyzer/signals.js +51 -0
- package/dist/analyzer/symbol-changes.d.ts +11 -0
- package/dist/analyzer/symbol-changes.js +101 -0
- package/dist/analyzer/symbol-types.d.ts +17 -0
- package/dist/analyzer/symbol-types.js +9 -0
- package/dist/analyzer/symbols.d.ts +4 -0
- package/dist/analyzer/symbols.js +16 -0
- package/dist/analyzer/trivial.d.ts +13 -0
- package/dist/analyzer/trivial.js +137 -0
- package/dist/analyzer/util.d.ts +6 -0
- package/dist/analyzer/util.js +24 -0
- package/dist/cli/commands/authoring.d.ts +9 -0
- package/dist/cli/commands/authoring.js +98 -0
- package/dist/cli/commands/cache.d.ts +4 -0
- package/dist/cli/commands/cache.js +37 -0
- package/dist/cli/commands/doctor.d.ts +5 -0
- package/dist/cli/commands/doctor.js +37 -0
- package/dist/cli/commands/generate.d.ts +8 -0
- package/dist/cli/commands/generate.js +69 -0
- package/dist/cli/commands/jobs.d.ts +8 -0
- package/dist/cli/commands/jobs.js +70 -0
- package/dist/cli/commands/publish.d.ts +8 -0
- package/dist/cli/commands/publish.js +120 -0
- package/dist/cli/commands/serve.d.ts +4 -0
- package/dist/cli/commands/serve.js +69 -0
- package/dist/cli/commands/setup.d.ts +14 -0
- package/dist/cli/commands/setup.js +108 -0
- package/dist/cli/commands/shared.d.ts +18 -0
- package/dist/cli/commands/shared.js +24 -0
- package/dist/cli/files.d.ts +26 -0
- package/dist/cli/files.js +98 -0
- package/dist/cli/format.d.ts +55 -0
- package/dist/cli/format.js +295 -0
- package/dist/cli/inputs.d.ts +23 -0
- package/dist/cli/inputs.js +96 -0
- package/dist/cli/io.d.ts +19 -0
- package/dist/cli/io.js +31 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +15 -0
- package/dist/cli/options.d.ts +105 -0
- package/dist/cli/options.js +324 -0
- package/dist/cli/program.d.ts +12 -0
- package/dist/cli/program.js +146 -0
- package/dist/cli/runtime.d.ts +59 -0
- package/dist/cli/runtime.js +83 -0
- package/dist/cli/style.d.ts +13 -0
- package/dist/cli/style.js +27 -0
- package/dist/core/binaries.d.ts +7 -0
- package/dist/core/binaries.js +33 -0
- package/dist/core/binary-paths.d.ts +5 -0
- package/dist/core/binary-paths.js +92 -0
- package/dist/core/cache.d.ts +14 -0
- package/dist/core/cache.js +43 -0
- package/dist/core/child-env.d.ts +9 -0
- package/dist/core/child-env.js +61 -0
- package/dist/core/concurrency.d.ts +13 -0
- package/dist/core/concurrency.js +58 -0
- package/dist/core/config.d.ts +223 -0
- package/dist/core/config.js +454 -0
- package/dist/core/context.d.ts +39 -0
- package/dist/core/context.js +44 -0
- package/dist/core/cost.d.ts +46 -0
- package/dist/core/cost.js +108 -0
- package/dist/core/diagram-metrics.d.ts +57 -0
- package/dist/core/diagram-metrics.js +63 -0
- package/dist/core/diff-view.d.ts +44 -0
- package/dist/core/diff-view.js +136 -0
- package/dist/core/errors.d.ts +47 -0
- package/dist/core/errors.js +94 -0
- package/dist/core/ids.d.ts +11 -0
- package/dist/core/ids.js +36 -0
- package/dist/core/json.d.ts +8 -0
- package/dist/core/json.js +17 -0
- package/dist/core/languages.d.ts +19 -0
- package/dist/core/languages.js +292 -0
- package/dist/core/logger.d.ts +29 -0
- package/dist/core/logger.js +68 -0
- package/dist/core/net.d.ts +16 -0
- package/dist/core/net.js +80 -0
- package/dist/core/path-policy.d.ts +20 -0
- package/dist/core/path-policy.js +202 -0
- package/dist/core/paths.d.ts +18 -0
- package/dist/core/paths.js +53 -0
- package/dist/core/posix.d.ts +12 -0
- package/dist/core/posix.js +50 -0
- package/dist/core/process.d.ts +22 -0
- package/dist/core/process.js +117 -0
- package/dist/core/providers.d.ts +204 -0
- package/dist/core/providers.js +2 -0
- package/dist/core/redact.d.ts +11 -0
- package/dist/core/redact.js +70 -0
- package/dist/core/render-plan.d.ts +307 -0
- package/dist/core/render-plan.js +7 -0
- package/dist/core/retry.d.ts +54 -0
- package/dist/core/retry.js +116 -0
- package/dist/core/run-folder.d.ts +74 -0
- package/dist/core/run-folder.js +129 -0
- package/dist/core/secrets.d.ts +56 -0
- package/dist/core/secrets.js +301 -0
- package/dist/core/storyboard-facts.d.ts +22 -0
- package/dist/core/storyboard-facts.js +61 -0
- package/dist/core/storyboard-schema.d.ts +1279 -0
- package/dist/core/storyboard-schema.js +342 -0
- package/dist/core/text.d.ts +43 -0
- package/dist/core/text.js +94 -0
- package/dist/core/types.d.ts +459 -0
- package/dist/core/types.js +17 -0
- package/dist/doctor/check.d.ts +6 -0
- package/dist/doctor/check.js +18 -0
- package/dist/doctor/deps.d.ts +2 -0
- package/dist/doctor/deps.js +90 -0
- package/dist/doctor/format.d.ts +9 -0
- package/dist/doctor/format.js +19 -0
- package/dist/doctor/github.d.ts +2 -0
- package/dist/doctor/github.js +13 -0
- package/dist/doctor/home.d.ts +2 -0
- package/dist/doctor/home.js +26 -0
- package/dist/doctor/index.d.ts +18 -0
- package/dist/doctor/index.js +81 -0
- package/dist/doctor/llm.d.ts +2 -0
- package/dist/doctor/llm.js +32 -0
- package/dist/doctor/publish.d.ts +2 -0
- package/dist/doctor/publish.js +16 -0
- package/dist/doctor/s3.d.ts +2 -0
- package/dist/doctor/s3.js +125 -0
- package/dist/doctor/speech.d.ts +2 -0
- package/dist/doctor/speech.js +112 -0
- package/dist/doctor/tools.d.ts +5 -0
- package/dist/doctor/tools.js +58 -0
- package/dist/doctor/types.d.ts +92 -0
- package/dist/doctor/types.js +2 -0
- package/dist/doctor/youtube.d.ts +2 -0
- package/dist/doctor/youtube.js +73 -0
- package/dist/github/client.d.ts +108 -0
- package/dist/github/client.js +499 -0
- package/dist/github/errors.d.ts +37 -0
- package/dist/github/errors.js +155 -0
- package/dist/github/index.d.ts +13 -0
- package/dist/github/index.js +9 -0
- package/dist/github/linked-issues.d.ts +37 -0
- package/dist/github/linked-issues.js +131 -0
- package/dist/github/model.d.ts +81 -0
- package/dist/github/model.js +114 -0
- package/dist/github/notify.d.ts +27 -0
- package/dist/github/notify.js +118 -0
- package/dist/github/pr-url.d.ts +27 -0
- package/dist/github/pr-url.js +122 -0
- package/dist/github/token.d.ts +16 -0
- package/dist/github/token.js +69 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +19 -0
- package/dist/jobs/input-rules.d.ts +20 -0
- package/dist/jobs/input-rules.js +100 -0
- package/dist/jobs/model.d.ts +47 -0
- package/dist/jobs/model.js +18 -0
- package/dist/jobs/runner.d.ts +43 -0
- package/dist/jobs/runner.js +165 -0
- package/dist/jobs/store.d.ts +67 -0
- package/dist/jobs/store.js +314 -0
- package/dist/jobs/view.d.ts +48 -0
- package/dist/jobs/view.js +111 -0
- package/dist/jobs/worker.d.ts +24 -0
- package/dist/jobs/worker.js +47 -0
- package/dist/llm/anthropic.d.ts +11 -0
- package/dist/llm/anthropic.js +225 -0
- package/dist/llm/index.d.ts +10 -0
- package/dist/llm/index.js +27 -0
- package/dist/llm/openai-compatible.d.ts +33 -0
- package/dist/llm/openai-compatible.js +378 -0
- package/dist/llm/prices.d.ts +26 -0
- package/dist/llm/prices.js +41 -0
- package/dist/llm/shared.d.ts +30 -0
- package/dist/llm/shared.js +115 -0
- package/dist/narration/assemble.d.ts +36 -0
- package/dist/narration/assemble.js +282 -0
- package/dist/narration/audio.d.ts +61 -0
- package/dist/narration/audio.js +301 -0
- package/dist/narration/captions.d.ts +37 -0
- package/dist/narration/captions.js +195 -0
- package/dist/narration/chunking.d.ts +6 -0
- package/dist/narration/chunking.js +46 -0
- package/dist/narration/convert.d.ts +9 -0
- package/dist/narration/convert.js +90 -0
- package/dist/narration/elevenlabs.d.ts +5 -0
- package/dist/narration/elevenlabs.js +53 -0
- package/dist/narration/http-errors.d.ts +14 -0
- package/dist/narration/http-errors.js +74 -0
- package/dist/narration/index.d.ts +21 -0
- package/dist/narration/index.js +22 -0
- package/dist/narration/kokoro-install.d.ts +30 -0
- package/dist/narration/kokoro-install.js +284 -0
- package/dist/narration/kokoro-model.d.ts +54 -0
- package/dist/narration/kokoro-model.js +168 -0
- package/dist/narration/kokoro-plugin.d.ts +78 -0
- package/dist/narration/kokoro-plugin.js +245 -0
- package/dist/narration/kokoro.d.ts +22 -0
- package/dist/narration/kokoro.js +231 -0
- package/dist/narration/openai.d.ts +4 -0
- package/dist/narration/openai.js +54 -0
- package/dist/narration/pricing.d.ts +8 -0
- package/dist/narration/pricing.js +17 -0
- package/dist/narration/remote-speech.d.ts +53 -0
- package/dist/narration/remote-speech.js +100 -0
- package/dist/narration/say.d.ts +28 -0
- package/dist/narration/say.js +178 -0
- package/dist/narration/select.d.ts +27 -0
- package/dist/narration/select.js +80 -0
- package/dist/narration/silent.d.ts +2 -0
- package/dist/narration/silent.js +18 -0
- package/dist/narration/speakable.d.ts +20 -0
- package/dist/narration/speakable.js +398 -0
- package/dist/narration/synthesize.d.ts +25 -0
- package/dist/narration/synthesize.js +220 -0
- package/dist/narration/wav.d.ts +37 -0
- package/dist/narration/wav.js +170 -0
- package/dist/pipeline/authoring.d.ts +8 -0
- package/dist/pipeline/authoring.js +117 -0
- package/dist/pipeline/commands.d.ts +9 -0
- package/dist/pipeline/commands.js +21 -0
- package/dist/pipeline/fit-duration.d.ts +41 -0
- package/dist/pipeline/fit-duration.js +150 -0
- package/dist/pipeline/index.d.ts +9 -0
- package/dist/pipeline/index.js +9 -0
- package/dist/pipeline/inputs.d.ts +42 -0
- package/dist/pipeline/inputs.js +171 -0
- package/dist/pipeline/plan.d.ts +8 -0
- package/dist/pipeline/plan.js +85 -0
- package/dist/pipeline/planned-egress.d.ts +21 -0
- package/dist/pipeline/planned-egress.js +43 -0
- package/dist/pipeline/prepare.d.ts +26 -0
- package/dist/pipeline/prepare.js +84 -0
- package/dist/pipeline/presentation.d.ts +26 -0
- package/dist/pipeline/presentation.js +110 -0
- package/dist/pipeline/publish-run.d.ts +71 -0
- package/dist/pipeline/publish-run.js +295 -0
- package/dist/pipeline/run.d.ts +7 -0
- package/dist/pipeline/run.js +196 -0
- package/dist/pipeline/storyboard-choice.d.ts +34 -0
- package/dist/pipeline/storyboard-choice.js +129 -0
- package/dist/pipeline/types.d.ts +76 -0
- package/dist/pipeline/types.js +2 -0
- package/dist/publish/access-probe.d.ts +55 -0
- package/dist/publish/access-probe.js +249 -0
- package/dist/publish/bundle.d.ts +20 -0
- package/dist/publish/bundle.js +57 -0
- package/dist/publish/comment.d.ts +10 -0
- package/dist/publish/comment.js +184 -0
- package/dist/publish/content-types.d.ts +15 -0
- package/dist/publish/content-types.js +41 -0
- package/dist/publish/index.d.ts +18 -0
- package/dist/publish/index.js +30 -0
- package/dist/publish/keys.d.ts +10 -0
- package/dist/publish/keys.js +30 -0
- package/dist/publish/local.d.ts +33 -0
- package/dist/publish/local.js +143 -0
- package/dist/publish/privacy.d.ts +20 -0
- package/dist/publish/privacy.js +21 -0
- package/dist/publish/s3/bucket.d.ts +22 -0
- package/dist/publish/s3/bucket.js +82 -0
- package/dist/publish/s3/client.d.ts +33 -0
- package/dist/publish/s3/client.js +134 -0
- package/dist/publish/s3/failures.d.ts +22 -0
- package/dist/publish/s3/failures.js +110 -0
- package/dist/publish/s3/index.d.ts +5 -0
- package/dist/publish/s3/index.js +6 -0
- package/dist/publish/s3/links.d.ts +38 -0
- package/dist/publish/s3/links.js +60 -0
- package/dist/publish/s3/protected-links.d.ts +29 -0
- package/dist/publish/s3/protected-links.js +67 -0
- package/dist/publish/s3/publisher.d.ts +32 -0
- package/dist/publish/s3/publisher.js +123 -0
- package/dist/publish/s3/settings.d.ts +29 -0
- package/dist/publish/s3/settings.js +64 -0
- package/dist/publish/s3/upload.d.ts +29 -0
- package/dist/publish/s3/upload.js +145 -0
- package/dist/publish/severity.d.ts +9 -0
- package/dist/publish/severity.js +18 -0
- package/dist/publish/text.d.ts +23 -0
- package/dist/publish/text.js +94 -0
- package/dist/publish/types.d.ts +67 -0
- package/dist/publish/types.js +12 -0
- package/dist/publish/vtt.d.ts +9 -0
- package/dist/publish/vtt.js +43 -0
- package/dist/publish/watch-page.d.ts +4 -0
- package/dist/publish/watch-page.js +463 -0
- package/dist/publish/youtube/credentials.d.ts +33 -0
- package/dist/publish/youtube/credentials.js +162 -0
- package/dist/publish/youtube/description.d.ts +56 -0
- package/dist/publish/youtube/description.js +197 -0
- package/dist/publish/youtube/google-api.d.ts +95 -0
- package/dist/publish/youtube/google-api.js +339 -0
- package/dist/publish/youtube/index.d.ts +7 -0
- package/dist/publish/youtube/index.js +8 -0
- package/dist/publish/youtube/loopback.d.ts +13 -0
- package/dist/publish/youtube/loopback.js +144 -0
- package/dist/publish/youtube/oauth.d.ts +68 -0
- package/dist/publish/youtube/oauth.js +159 -0
- package/dist/publish/youtube/prompt.d.ts +27 -0
- package/dist/publish/youtube/prompt.js +94 -0
- package/dist/publish/youtube/publisher.d.ts +38 -0
- package/dist/publish/youtube/publisher.js +346 -0
- package/dist/publish/youtube/scopes.d.ts +32 -0
- package/dist/publish/youtube/scopes.js +55 -0
- package/dist/publish/youtube/sign-in.d.ts +37 -0
- package/dist/publish/youtube/sign-in.js +137 -0
- package/dist/publish/youtube/upload.d.ts +43 -0
- package/dist/publish/youtube/upload.js +210 -0
- package/dist/render/browser.d.ts +23 -0
- package/dist/render/browser.js +219 -0
- package/dist/render/chromium-renderer.d.ts +56 -0
- package/dist/render/chromium-renderer.js +519 -0
- package/dist/render/ffmpeg.d.ts +55 -0
- package/dist/render/ffmpeg.js +212 -0
- package/dist/render/fonts.d.ts +10 -0
- package/dist/render/fonts.js +42 -0
- package/dist/render/index.d.ts +9 -0
- package/dist/render/index.js +11 -0
- package/dist/render/page.d.ts +46 -0
- package/dist/render/page.js +123 -0
- package/dist/render/playwright.d.ts +3 -0
- package/dist/render/playwright.js +6 -0
- package/dist/render/runtime-bundle.d.ts +2 -0
- package/dist/render/runtime-bundle.js +72 -0
- package/dist/runtime/runtime.js +1626 -0
- package/dist/server/auth.d.ts +17 -0
- package/dist/server/auth.js +58 -0
- package/dist/server/http.d.ts +43 -0
- package/dist/server/http.js +119 -0
- package/dist/server/index.d.ts +46 -0
- package/dist/server/index.js +310 -0
- package/dist/server/queue.d.ts +30 -0
- package/dist/server/queue.js +76 -0
- package/dist/server/schema.d.ts +103 -0
- package/dist/server/schema.js +121 -0
- package/dist/server/source.d.ts +17 -0
- package/dist/server/source.js +100 -0
- package/dist/sources/assemble.d.ts +86 -0
- package/dist/sources/assemble.js +117 -0
- package/dist/sources/diff-parser.d.ts +14 -0
- package/dist/sources/diff-parser.js +84 -0
- package/dist/sources/git.d.ts +28 -0
- package/dist/sources/git.js +108 -0
- package/dist/sources/github.d.ts +20 -0
- package/dist/sources/github.js +192 -0
- package/dist/sources/hunk-selection.d.ts +25 -0
- package/dist/sources/hunk-selection.js +46 -0
- package/dist/sources/index.d.ts +23 -0
- package/dist/sources/index.js +62 -0
- package/dist/sources/limits.d.ts +27 -0
- package/dist/sources/limits.js +22 -0
- package/dist/sources/local.d.ts +34 -0
- package/dist/sources/local.js +555 -0
- package/dist/sources/reader.d.ts +13 -0
- package/dist/sources/reader.js +45 -0
- package/dist/sources/remote.d.ts +13 -0
- package/dist/sources/remote.js +41 -0
- package/dist/sources/repo-context.d.ts +34 -0
- package/dist/sources/repo-context.js +144 -0
- package/dist/sources/text.d.ts +25 -0
- package/dist/sources/text.js +71 -0
- package/dist/storyboard/authoring.d.ts +108 -0
- package/dist/storyboard/authoring.js +196 -0
- package/dist/storyboard/claims.d.ts +35 -0
- package/dist/storyboard/claims.js +318 -0
- package/dist/storyboard/coderef.d.ts +28 -0
- package/dist/storyboard/coderef.js +118 -0
- package/dist/storyboard/generate.d.ts +25 -0
- package/dist/storyboard/generate.js +194 -0
- package/dist/storyboard/heuristic-code.d.ts +91 -0
- package/dist/storyboard/heuristic-code.js +524 -0
- package/dist/storyboard/heuristic-context.d.ts +42 -0
- package/dist/storyboard/heuristic-context.js +102 -0
- package/dist/storyboard/heuristic-facts.d.ts +106 -0
- package/dist/storyboard/heuristic-facts.js +415 -0
- package/dist/storyboard/heuristic-overview.d.ts +4 -0
- package/dist/storyboard/heuristic-overview.js +151 -0
- package/dist/storyboard/heuristic-review.d.ts +10 -0
- package/dist/storyboard/heuristic-review.js +158 -0
- package/dist/storyboard/heuristic-scenes.d.ts +8 -0
- package/dist/storyboard/heuristic-scenes.js +357 -0
- package/dist/storyboard/heuristic-shared.d.ts +43 -0
- package/dist/storyboard/heuristic-shared.js +136 -0
- package/dist/storyboard/heuristic.d.ts +15 -0
- package/dist/storyboard/heuristic.js +324 -0
- package/dist/storyboard/identifiers.d.ts +51 -0
- package/dist/storyboard/identifiers.js +195 -0
- package/dist/storyboard/index.d.ts +10 -0
- package/dist/storyboard/index.js +10 -0
- package/dist/storyboard/prompts.d.ts +16 -0
- package/dist/storyboard/prompts.js +61 -0
- package/dist/storyboard/run.d.ts +82 -0
- package/dist/storyboard/run.js +332 -0
- package/dist/storyboard/text.d.ts +16 -0
- package/dist/storyboard/text.js +103 -0
- package/dist/storyboard/types.d.ts +47 -0
- package/dist/storyboard/types.js +2 -0
- package/dist/storyboard/urls.d.ts +15 -0
- package/dist/storyboard/urls.js +83 -0
- package/dist/storyboard/validate.d.ts +8 -0
- package/dist/storyboard/validate.js +525 -0
- package/dist/storyboard/visuals.d.ts +23 -0
- package/dist/storyboard/visuals.js +324 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +3 -0
- package/dist/visuals/code.d.ts +68 -0
- package/dist/visuals/code.js +385 -0
- package/dist/visuals/highlight.d.ts +17 -0
- package/dist/visuals/highlight.js +85 -0
- package/dist/visuals/image.d.ts +12 -0
- package/dist/visuals/image.js +96 -0
- package/dist/visuals/index.d.ts +10 -0
- package/dist/visuals/index.js +10 -0
- package/dist/visuals/layout.d.ts +89 -0
- package/dist/visuals/layout.js +506 -0
- package/dist/visuals/plan.d.ts +33 -0
- package/dist/visuals/plan.js +511 -0
- package/dist/visuals/timeline.d.ts +31 -0
- package/dist/visuals/timeline.js +96 -0
- package/package.json +74 -4
|
@@ -0,0 +1,519 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ChromiumRenderer: RenderPlan -> MP4.
|
|
3
|
+
*
|
|
4
|
+
* The runtime in a headless browser draws any time of the plan on request. The frames are cut into
|
|
5
|
+
* fixed-length segments; several browsers capture segments in parallel, each segment streams its
|
|
6
|
+
* JPEG frames into its own FFmpeg process, and the segments are joined without re-encoding while the
|
|
7
|
+
* narration is added. Frames that did not change are not captured again.
|
|
8
|
+
*
|
|
9
|
+
* Output depends only on the plan: segment boundaries do not move with the number of workers, and
|
|
10
|
+
* every segment is drawn in ascending order by a page that has not drawn anything before. Chromium
|
|
11
|
+
* can draw a frame slightly differently depending on the frames drawn before it (layer raster
|
|
12
|
+
* scale), so reusing a page across segments would make the bytes depend on which worker got which
|
|
13
|
+
* segment. Partial raster is off for the same reason.
|
|
14
|
+
*/
|
|
15
|
+
import { mkdir, rename, rm, stat, writeFile } from 'node:fs/promises';
|
|
16
|
+
import { cpus, totalmem } from 'node:os';
|
|
17
|
+
import { join, resolve } from 'node:path';
|
|
18
|
+
import { resolveFfmpeg } from '../core/binaries.js';
|
|
19
|
+
import { QUALITY_PRESETS } from '../core/config.js';
|
|
20
|
+
import { abortedError, assertNotAborted, MergeStoryError } from '../core/errors.js';
|
|
21
|
+
import { randomToken } from '../core/ids.js';
|
|
22
|
+
import { RUN_FILE } from '../core/run-folder.js';
|
|
23
|
+
import { detectImage } from '../visuals/image.js';
|
|
24
|
+
import { locateBrowser } from './browser.js';
|
|
25
|
+
import { concatAndMux, concatListText, probeDuration, SegmentEncoder, segmentEncodeArgs } from './ffmpeg.js';
|
|
26
|
+
import { fontFacesCss } from './fonts.js';
|
|
27
|
+
import { buildPageHtml, PlanPage } from './page.js';
|
|
28
|
+
import { loadPlaywright } from './playwright.js';
|
|
29
|
+
import { loadRuntimeBundle } from './runtime-bundle.js';
|
|
30
|
+
/**
|
|
31
|
+
* Browser flags. Partial raster is off so pixels no longer depend on the order of seeks; text hinting
|
|
32
|
+
* and subpixel text are off so glyphs look the same on every platform; name lookups are refused so
|
|
33
|
+
* a browser that is not a headless shell cannot reach out in the background.
|
|
34
|
+
*/
|
|
35
|
+
export const BROWSER_ARGS = [
|
|
36
|
+
'--disable-partial-raster',
|
|
37
|
+
'--font-render-hinting=none',
|
|
38
|
+
'--disable-lcd-text',
|
|
39
|
+
'--disable-breakpad',
|
|
40
|
+
'--host-resolver-rules=MAP * ~NOTFOUND',
|
|
41
|
+
];
|
|
42
|
+
/** Fixed encoder thread count, so the same plan always encodes to the same bytes. */
|
|
43
|
+
const ENCODER_THREADS = 2;
|
|
44
|
+
/** Most browsers started automatically; more did not help in measurements. */
|
|
45
|
+
const MAX_AUTO_WORKERS = 6;
|
|
46
|
+
/** Rough memory one worker needs (browser plus encoder). */
|
|
47
|
+
const BYTES_PER_WORKER = 1.5 * 1024 ** 3;
|
|
48
|
+
const SEGMENT_ATTEMPTS = 2;
|
|
49
|
+
const POSTER_OFFSET_SEC = 1.5;
|
|
50
|
+
const POSTER_QUALITY = 92;
|
|
51
|
+
const PROGRESS_STEP = 0.02;
|
|
52
|
+
/** Number of frames for a plan: its duration at the frame rate, at least one. */
|
|
53
|
+
export function frameCountFor(durationSec, fps) {
|
|
54
|
+
return Math.max(1, Math.round(durationSec * fps));
|
|
55
|
+
}
|
|
56
|
+
/** Fixed segments of four seconds (two keyframe intervals), whatever the machine. */
|
|
57
|
+
export function planSegments(frames, fps) {
|
|
58
|
+
const length = fps * 4;
|
|
59
|
+
const segments = [];
|
|
60
|
+
for (let start = 0, index = 0; start < frames; start += length, index++) {
|
|
61
|
+
segments.push({ index, start, end: Math.min(frames, start + length) });
|
|
62
|
+
}
|
|
63
|
+
return segments;
|
|
64
|
+
}
|
|
65
|
+
/** Parallel browsers: the configured number, else half the CPUs, limited by memory and by 6. */
|
|
66
|
+
export function chooseWorkers(configured, segmentCount, cpuCount = cpus().length, memoryBytes = totalmem()) {
|
|
67
|
+
const byCpu = Math.max(1, Math.floor(cpuCount / 2));
|
|
68
|
+
const byMemory = Math.max(1, Math.floor(memoryBytes / BYTES_PER_WORKER));
|
|
69
|
+
const automatic = Math.min(MAX_AUTO_WORKERS, byCpu, byMemory);
|
|
70
|
+
return Math.max(1, Math.min(Math.max(1, segmentCount), configured ?? automatic));
|
|
71
|
+
}
|
|
72
|
+
/** When the poster is taken: shortly after the title scene's heading appears. */
|
|
73
|
+
export function posterTimeFor(plan, frames) {
|
|
74
|
+
const scene = plan.scenes.find((s) => s.visual.type === 'title') ?? plan.scenes[0];
|
|
75
|
+
const last = (frames - 1) / plan.fps;
|
|
76
|
+
if (!scene)
|
|
77
|
+
return Math.min(POSTER_OFFSET_SEC, last);
|
|
78
|
+
const latest = scene.startSec + Math.max(0, scene.durationSec - 0.2);
|
|
79
|
+
return Math.max(0, Math.min(scene.startSec + POSTER_OFFSET_SEC, latest, last));
|
|
80
|
+
}
|
|
81
|
+
function assertPlan(plan) {
|
|
82
|
+
const even = (n) => Number.isInteger(n) && n > 0 && n % 2 === 0;
|
|
83
|
+
if (!even(plan.width) || !even(plan.height)) {
|
|
84
|
+
throw new MergeStoryError('RENDER_FAILED', `The video size ${plan.width}x${plan.height} must be even numbers.`, {
|
|
85
|
+
hint: 'H.264 with 4:2:0 colour needs an even width and height.',
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
if (!Number.isInteger(plan.fps) || plan.fps < 1 || plan.fps > 120) {
|
|
89
|
+
throw new MergeStoryError('RENDER_FAILED', `The frame rate ${plan.fps} is not supported (1 to 120).`);
|
|
90
|
+
}
|
|
91
|
+
if (!Number.isFinite(plan.durationSec) || plan.durationSec <= 0) {
|
|
92
|
+
throw new MergeStoryError('RENDER_FAILED', 'The render plan has no duration.');
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function isAbort(err) {
|
|
96
|
+
return err instanceof MergeStoryError && err.code === 'ABORTED';
|
|
97
|
+
}
|
|
98
|
+
/** One render: workers capture segments from a shared queue. */
|
|
99
|
+
class RenderRun {
|
|
100
|
+
frames;
|
|
101
|
+
reusedFrames = 0;
|
|
102
|
+
posterJpeg = null;
|
|
103
|
+
setup;
|
|
104
|
+
nextSegment = 0;
|
|
105
|
+
done = 0;
|
|
106
|
+
reported = 0;
|
|
107
|
+
failure = null;
|
|
108
|
+
posterClaimed = false;
|
|
109
|
+
encoders = new Set();
|
|
110
|
+
browsers = new Set();
|
|
111
|
+
constructor(setup, frames) {
|
|
112
|
+
this.setup = setup;
|
|
113
|
+
this.frames = frames;
|
|
114
|
+
}
|
|
115
|
+
async execute() {
|
|
116
|
+
const { ctx, workers } = this.setup;
|
|
117
|
+
const onAbort = () => this.fail(abortedError());
|
|
118
|
+
ctx.signal.addEventListener('abort', onAbort, { once: true });
|
|
119
|
+
if (ctx.signal.aborted)
|
|
120
|
+
onAbort();
|
|
121
|
+
try {
|
|
122
|
+
await Promise.all(Array.from({ length: workers }, (_, id) => this.worker(id).catch((err) => this.fail(err instanceof Error ? err : new Error(String(err))))));
|
|
123
|
+
if (this.failure)
|
|
124
|
+
throw this.failure;
|
|
125
|
+
}
|
|
126
|
+
finally {
|
|
127
|
+
ctx.signal.removeEventListener('abort', onAbort);
|
|
128
|
+
for (const encoder of this.encoders)
|
|
129
|
+
encoder.kill();
|
|
130
|
+
await Promise.allSettled([...this.browsers].map((browser) => browser.close()));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/** Record the first failure and stop everything else. */
|
|
134
|
+
fail(err) {
|
|
135
|
+
if (this.failure)
|
|
136
|
+
return;
|
|
137
|
+
this.failure = err;
|
|
138
|
+
for (const encoder of this.encoders)
|
|
139
|
+
encoder.kill();
|
|
140
|
+
}
|
|
141
|
+
throwIfFailed() {
|
|
142
|
+
if (this.failure)
|
|
143
|
+
throw this.failure;
|
|
144
|
+
}
|
|
145
|
+
advance(frames) {
|
|
146
|
+
this.done += frames;
|
|
147
|
+
const progress = Math.min(1, this.done / this.frames);
|
|
148
|
+
if (progress - this.reported >= PROGRESS_STEP || (progress >= 1 && this.reported < 1)) {
|
|
149
|
+
this.reported = progress;
|
|
150
|
+
this.setup.ctx.progress({
|
|
151
|
+
stage: 'render',
|
|
152
|
+
status: 'progress',
|
|
153
|
+
progress,
|
|
154
|
+
message: `Rendering frames (${Math.min(this.done, this.frames)} of ${this.frames})`,
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
async launchBrowser() {
|
|
159
|
+
const { executablePath, launch } = this.setup;
|
|
160
|
+
let browser;
|
|
161
|
+
try {
|
|
162
|
+
browser = await launch(executablePath, this.setup.ctx.logger);
|
|
163
|
+
}
|
|
164
|
+
catch (err) {
|
|
165
|
+
throw browserStartError(err);
|
|
166
|
+
}
|
|
167
|
+
this.browsers.add(browser);
|
|
168
|
+
return browser;
|
|
169
|
+
}
|
|
170
|
+
async closeBrowser(browser) {
|
|
171
|
+
if (!browser)
|
|
172
|
+
return;
|
|
173
|
+
this.browsers.delete(browser);
|
|
174
|
+
await browser.close().catch(() => undefined);
|
|
175
|
+
}
|
|
176
|
+
/** A new page in a new browser context, so no earlier frame can influence what it draws. */
|
|
177
|
+
async openPage(browser, workerId) {
|
|
178
|
+
const { plan, html, ctx } = this.setup;
|
|
179
|
+
return PlanPage.open(browser, plan, html, ctx.logger.child({ worker: workerId }));
|
|
180
|
+
}
|
|
181
|
+
async closePage(page) {
|
|
182
|
+
const logger = this.setup.ctx.logger;
|
|
183
|
+
if (page.pageErrors.length > 0) {
|
|
184
|
+
logger.warn('The render page reported errors.', {
|
|
185
|
+
count: page.pageErrors.length,
|
|
186
|
+
first: page.pageErrors[0]?.slice(0, 200),
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
if (page.blockedRequests > 0) {
|
|
190
|
+
logger.warn('The render page tried to make network requests; all were blocked.', {
|
|
191
|
+
count: page.blockedRequests,
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
await page.close();
|
|
195
|
+
}
|
|
196
|
+
takeSegment() {
|
|
197
|
+
return this.setup.segments[this.nextSegment++] ?? null;
|
|
198
|
+
}
|
|
199
|
+
async worker(id) {
|
|
200
|
+
let browser = null;
|
|
201
|
+
const finishing = [];
|
|
202
|
+
try {
|
|
203
|
+
for (;;) {
|
|
204
|
+
this.throwIfFailed();
|
|
205
|
+
const segment = this.takeSegment();
|
|
206
|
+
if (!segment)
|
|
207
|
+
break;
|
|
208
|
+
for (let attempt = 1;; attempt++) {
|
|
209
|
+
try {
|
|
210
|
+
browser ??= await this.launchBrowser();
|
|
211
|
+
const page = await this.openPage(browser, id);
|
|
212
|
+
try {
|
|
213
|
+
finishing.push((await this.captureSegment(page, segment)).finished);
|
|
214
|
+
}
|
|
215
|
+
finally {
|
|
216
|
+
await this.closePage(page);
|
|
217
|
+
}
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
catch (err) {
|
|
221
|
+
if (this.failure || isAbort(err) || attempt >= SEGMENT_ATTEMPTS)
|
|
222
|
+
throw err;
|
|
223
|
+
this.setup.ctx.logger.warn('A render worker failed; restarting its browser and retrying the segment.', {
|
|
224
|
+
worker: id,
|
|
225
|
+
segment: segment.index,
|
|
226
|
+
error: err instanceof Error ? err.message : String(err),
|
|
227
|
+
});
|
|
228
|
+
await this.closeBrowser(browser);
|
|
229
|
+
browser = null;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
// The poster comes from the first worker that has a browser and nothing left to do.
|
|
234
|
+
if (browser && !this.posterClaimed) {
|
|
235
|
+
this.posterClaimed = true;
|
|
236
|
+
try {
|
|
237
|
+
const page = await this.openPage(browser, id);
|
|
238
|
+
try {
|
|
239
|
+
await page.seek(posterTimeFor(this.setup.plan, this.frames));
|
|
240
|
+
this.posterJpeg = await page.capture({
|
|
241
|
+
format: 'jpeg',
|
|
242
|
+
quality: POSTER_QUALITY,
|
|
243
|
+
optimizeForSpeed: false,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
finally {
|
|
247
|
+
await this.closePage(page);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
catch (err) {
|
|
251
|
+
// The poster is optional: a failure here must not cost the finished segments.
|
|
252
|
+
if (this.failure || isAbort(err))
|
|
253
|
+
throw err;
|
|
254
|
+
this.setup.ctx.logger.warn('The poster could not be captured; the video has no poster.', {
|
|
255
|
+
error: err instanceof Error ? err.message : String(err),
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
await Promise.all(finishing);
|
|
260
|
+
}
|
|
261
|
+
finally {
|
|
262
|
+
await this.closeBrowser(browser);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Capture one segment into a new encoder. Resolves when all frames are written; `finished`
|
|
267
|
+
* settles when the encoder is done, so the next segment can start meanwhile.
|
|
268
|
+
*/
|
|
269
|
+
async captureSegment(page, segment) {
|
|
270
|
+
const { plan, ffmpeg, segmentPath, crf, x264Preset, jpeg, reuseStaticFrames } = this.setup;
|
|
271
|
+
const encoder = SegmentEncoder.start(ffmpeg, segmentEncodeArgs({
|
|
272
|
+
fps: plan.fps,
|
|
273
|
+
crf,
|
|
274
|
+
x264Preset,
|
|
275
|
+
gop: plan.fps * 2,
|
|
276
|
+
threads: ENCODER_THREADS,
|
|
277
|
+
outPath: segmentPath(segment),
|
|
278
|
+
}));
|
|
279
|
+
this.encoders.add(encoder);
|
|
280
|
+
let counted = 0;
|
|
281
|
+
let reused = 0;
|
|
282
|
+
try {
|
|
283
|
+
let previous = null;
|
|
284
|
+
for (let frame = segment.start; frame < segment.end; frame++) {
|
|
285
|
+
this.throwIfFailed();
|
|
286
|
+
const dirty = await page.seek(frame / plan.fps);
|
|
287
|
+
let bytes;
|
|
288
|
+
if (!dirty && previous && reuseStaticFrames) {
|
|
289
|
+
bytes = previous;
|
|
290
|
+
reused++;
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
bytes = await page.capture(jpeg);
|
|
294
|
+
if (previous === null && segment.index === 0)
|
|
295
|
+
this.checkFrameSize(bytes);
|
|
296
|
+
previous = bytes;
|
|
297
|
+
}
|
|
298
|
+
await encoder.write(bytes);
|
|
299
|
+
counted++;
|
|
300
|
+
this.advance(1);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
catch (err) {
|
|
304
|
+
encoder.kill();
|
|
305
|
+
this.encoders.delete(encoder);
|
|
306
|
+
this.done -= counted; // a retry counts these frames again
|
|
307
|
+
throw err;
|
|
308
|
+
}
|
|
309
|
+
this.reusedFrames += reused;
|
|
310
|
+
const finished = encoder.finish().then(() => {
|
|
311
|
+
this.encoders.delete(encoder);
|
|
312
|
+
}, (err) => {
|
|
313
|
+
this.encoders.delete(encoder);
|
|
314
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
315
|
+
this.fail(error);
|
|
316
|
+
throw error;
|
|
317
|
+
});
|
|
318
|
+
// The worker awaits `finished` later; this keeps an early failure from being reported as unhandled.
|
|
319
|
+
finished.catch(() => undefined);
|
|
320
|
+
return { finished };
|
|
321
|
+
}
|
|
322
|
+
checkFrameSize(jpegBytes) {
|
|
323
|
+
const { plan } = this.setup;
|
|
324
|
+
const info = detectImage(jpegBytes);
|
|
325
|
+
if (!info || info.width !== plan.width || info.height !== plan.height) {
|
|
326
|
+
throw new MergeStoryError('RENDER_FAILED', `The browser captured a ${info ? `${info.width}x${info.height}` : 'unreadable'} frame instead of ${plan.width}x${plan.height}.`, { hint: 'Try another browser with MERGESTORY_BROWSER_PATH.' });
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* The browser keeps its sandbox on, because it draws images from the change. It cannot start with the
|
|
332
|
+
* sandbox as root (as in many containers), so it is turned off there.
|
|
333
|
+
*/
|
|
334
|
+
export function browserSandbox(uid = process.getuid?.()) {
|
|
335
|
+
return uid !== 0;
|
|
336
|
+
}
|
|
337
|
+
/** What Chromium prints when the machine refuses it a sandbox. */
|
|
338
|
+
const NO_SANDBOX = /no usable sandbox|sandbox helper/i;
|
|
339
|
+
/**
|
|
340
|
+
* Starts the browser with its sandbox where the machine allows one. Some do not allow it for a normal
|
|
341
|
+
* user either: Ubuntu 23.10 and later block the user namespaces that a downloaded Chromium needs. There
|
|
342
|
+
* the browser starts without the sandbox, as it does for root, and the user gets a warning.
|
|
343
|
+
*/
|
|
344
|
+
export async function launchWithSandbox(launch, logger, uid = process.getuid?.()) {
|
|
345
|
+
if (!browserSandbox(uid)) {
|
|
346
|
+
logger.debug('Running as root, so the browser starts without its sandbox.');
|
|
347
|
+
return launch(false);
|
|
348
|
+
}
|
|
349
|
+
try {
|
|
350
|
+
return await launch(true);
|
|
351
|
+
}
|
|
352
|
+
catch (err) {
|
|
353
|
+
if (!(err instanceof Error && NO_SANDBOX.test(err.message)))
|
|
354
|
+
throw err;
|
|
355
|
+
logger.warn('This machine does not allow the browser sandbox, so the browser runs without it. ' +
|
|
356
|
+
'Google Chrome installed from its package can usually use the sandbox: set MERGESTORY_BROWSER_PATH to it.');
|
|
357
|
+
return launch(false);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
const launchChromium = async (executablePath, logger) => {
|
|
361
|
+
const { chromium } = await loadPlaywright();
|
|
362
|
+
return launchWithSandbox((chromiumSandbox) => chromium.launch({
|
|
363
|
+
executablePath,
|
|
364
|
+
headless: true,
|
|
365
|
+
chromiumSandbox,
|
|
366
|
+
args: BROWSER_ARGS,
|
|
367
|
+
timeout: 90_000,
|
|
368
|
+
// The CLI handles Ctrl-C itself and cancels the run through its abort signal.
|
|
369
|
+
handleSIGINT: false,
|
|
370
|
+
handleSIGTERM: false,
|
|
371
|
+
handleSIGHUP: false,
|
|
372
|
+
}), logger);
|
|
373
|
+
};
|
|
374
|
+
/** The error for a browser that did not start. A launcher passed in by a caller has no sandbox fallback. */
|
|
375
|
+
function browserStartError(err) {
|
|
376
|
+
const sandbox = err instanceof Error && NO_SANDBOX.test(err.message);
|
|
377
|
+
return new MergeStoryError('RENDER_FAILED', 'The browser could not be started.', {
|
|
378
|
+
hint: `${sandbox ? 'This machine does not allow the browser sandbox. Google Chrome installed from its package can usually use it. ' : ''}Set MERGESTORY_BROWSER_PATH to a working Chrome or Chromium, or run "mergestory doctor".`,
|
|
379
|
+
cause: err,
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
export class ChromiumRenderer {
|
|
383
|
+
id = 'chromium';
|
|
384
|
+
config;
|
|
385
|
+
options;
|
|
386
|
+
constructor(config, options = {}) {
|
|
387
|
+
this.config = config;
|
|
388
|
+
this.options = options;
|
|
389
|
+
}
|
|
390
|
+
async render(input, ctx) {
|
|
391
|
+
const { plan } = input;
|
|
392
|
+
assertNotAborted(ctx.signal);
|
|
393
|
+
assertPlan(plan);
|
|
394
|
+
const preset = QUALITY_PRESETS[input.quality] ?? QUALITY_PRESETS.standard;
|
|
395
|
+
const { ffmpeg, ffprobe } = await resolveFfmpeg(this.config);
|
|
396
|
+
const browser = await locateBrowser(this.config);
|
|
397
|
+
const [runtimeJs, fontsCss] = await Promise.all([
|
|
398
|
+
this.options.runtimeJs ?? loadRuntimeBundle(),
|
|
399
|
+
fontFacesCss(),
|
|
400
|
+
]);
|
|
401
|
+
const html = buildPageHtml({ runtimeJs, fontsCss });
|
|
402
|
+
const outDir = resolve(input.outDir);
|
|
403
|
+
await mkdir(outDir, { recursive: true, mode: 0o700 });
|
|
404
|
+
const audioPath = input.audioPath ? resolve(input.audioPath) : null;
|
|
405
|
+
if (audioPath) {
|
|
406
|
+
const found = await stat(audioPath).then((s) => s.isFile(), () => false);
|
|
407
|
+
if (!found)
|
|
408
|
+
throw new MergeStoryError('RENDER_FAILED', 'The audio track was not found.', {
|
|
409
|
+
hint: 'Re-run the narration step.',
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
const frames = frameCountFor(plan.durationSec, plan.fps);
|
|
413
|
+
const segments = planSegments(frames, plan.fps);
|
|
414
|
+
const workers = this.options.workers ?? chooseWorkers(this.config.render.concurrency, segments.length);
|
|
415
|
+
const tmpDir = join(outDir, `.render-${randomToken(4)}`);
|
|
416
|
+
await mkdir(tmpDir, { mode: 0o700 });
|
|
417
|
+
const segmentFile = (segment) => join(tmpDir, `segment-${String(segment.index).padStart(4, '0')}.mp4`);
|
|
418
|
+
const started = performance.now();
|
|
419
|
+
const videoPath = join(outDir, RUN_FILE.video);
|
|
420
|
+
const posterFile = join(outDir, RUN_FILE.poster);
|
|
421
|
+
try {
|
|
422
|
+
const run = new RenderRun({
|
|
423
|
+
plan,
|
|
424
|
+
ffmpeg,
|
|
425
|
+
executablePath: browser.path,
|
|
426
|
+
html,
|
|
427
|
+
segments,
|
|
428
|
+
segmentPath: segmentFile,
|
|
429
|
+
workers,
|
|
430
|
+
crf: preset.crf,
|
|
431
|
+
x264Preset: preset.x264Preset,
|
|
432
|
+
jpeg: { format: 'jpeg', quality: preset.jpegQuality, optimizeForSpeed: true },
|
|
433
|
+
reuseStaticFrames: this.config.render.reuseStaticFrames,
|
|
434
|
+
launch: this.options.launch ?? launchChromium,
|
|
435
|
+
ctx,
|
|
436
|
+
}, frames);
|
|
437
|
+
await run.execute();
|
|
438
|
+
assertNotAborted(ctx.signal);
|
|
439
|
+
const listPath = join(tmpDir, 'segments.txt');
|
|
440
|
+
await writeFile(listPath, concatListText(segments.map(segmentFile)), { mode: 0o600 });
|
|
441
|
+
const assembled = join(tmpDir, RUN_FILE.video);
|
|
442
|
+
await concatAndMux(ffmpeg, { listPath, audioPath, outPath: assembled, durationSec: frames / plan.fps }, ctx.signal);
|
|
443
|
+
await rename(assembled, videoPath);
|
|
444
|
+
if (run.posterJpeg)
|
|
445
|
+
await writeFile(posterFile, run.posterJpeg, { mode: 0o600 });
|
|
446
|
+
const [durationSec, size] = await Promise.all([
|
|
447
|
+
probeDuration(ffprobe, videoPath, ctx.signal),
|
|
448
|
+
stat(videoPath),
|
|
449
|
+
]);
|
|
450
|
+
const seconds = (performance.now() - started) / 1000;
|
|
451
|
+
ctx.logger.debug('Render finished', {
|
|
452
|
+
frames,
|
|
453
|
+
reusedFrames: run.reusedFrames,
|
|
454
|
+
workers,
|
|
455
|
+
segments: segments.length,
|
|
456
|
+
seconds: Number(seconds.toFixed(1)),
|
|
457
|
+
fps: Number((frames / seconds).toFixed(1)),
|
|
458
|
+
});
|
|
459
|
+
return {
|
|
460
|
+
videoPath,
|
|
461
|
+
posterPath: run.posterJpeg ? posterFile : null,
|
|
462
|
+
width: plan.width,
|
|
463
|
+
height: plan.height,
|
|
464
|
+
fps: plan.fps,
|
|
465
|
+
durationSec,
|
|
466
|
+
frames,
|
|
467
|
+
reusedFrames: run.reusedFrames,
|
|
468
|
+
sizeBytes: size.size,
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
finally {
|
|
472
|
+
await rm(tmpDir, { recursive: true, force: true });
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
function stillName(timeSec) {
|
|
477
|
+
return `frame-${timeSec.toFixed(2).padStart(7, '0')}.png`;
|
|
478
|
+
}
|
|
479
|
+
/** Render single frames to PNG files. Returns the written paths in the order of `timesSec`. */
|
|
480
|
+
export async function renderStillFrames(plan, timesSec, outDir, ctx, options = {}) {
|
|
481
|
+
assertPlan(plan);
|
|
482
|
+
for (const time of timesSec) {
|
|
483
|
+
if (!Number.isFinite(time) || time < 0) {
|
|
484
|
+
throw new MergeStoryError('USAGE', `A preview time is not valid: ${time}`, {
|
|
485
|
+
hint: 'Times are seconds from the start.',
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
const executable = await locateBrowser(ctx.config);
|
|
490
|
+
const [runtimeJs, fontsCss] = await Promise.all([options.runtimeJs ?? loadRuntimeBundle(), fontFacesCss()]);
|
|
491
|
+
const html = buildPageHtml({ runtimeJs, fontsCss });
|
|
492
|
+
const target = resolve(outDir);
|
|
493
|
+
await mkdir(target, { recursive: true, mode: 0o700 });
|
|
494
|
+
let browser;
|
|
495
|
+
try {
|
|
496
|
+
browser = await (options.launch ?? launchChromium)(executable.path, ctx.logger);
|
|
497
|
+
}
|
|
498
|
+
catch (err) {
|
|
499
|
+
throw browserStartError(err);
|
|
500
|
+
}
|
|
501
|
+
try {
|
|
502
|
+
const page = await PlanPage.open(browser, plan, html, ctx.logger);
|
|
503
|
+
const written = [];
|
|
504
|
+
for (const time of timesSec) {
|
|
505
|
+
assertNotAborted(ctx.signal);
|
|
506
|
+
const clamped = Math.min(time, plan.durationSec);
|
|
507
|
+
await page.seek(clamped);
|
|
508
|
+
const png = await page.capture({ format: 'png', optimizeForSpeed: false });
|
|
509
|
+
const file = join(target, stillName(clamped));
|
|
510
|
+
await writeFile(file, png, { mode: 0o600 });
|
|
511
|
+
written.push(file);
|
|
512
|
+
}
|
|
513
|
+
return written;
|
|
514
|
+
}
|
|
515
|
+
finally {
|
|
516
|
+
await browser.close().catch(() => undefined);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
//# sourceMappingURL=chromium-renderer.js.map
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chrome writes JPEG frames as full-range BT.601 YCbCr. The video is limited-range BT.709, so the
|
|
3
|
+
* frames go through RGB (exact in every FFmpeg version) and are then tagged. Without this the
|
|
4
|
+
* output keeps the JPEG's full range, and players that ignore the range flag show washed colours.
|
|
5
|
+
*/
|
|
6
|
+
export declare const COLOR_FILTER: string;
|
|
7
|
+
export interface SegmentEncodeOptions {
|
|
8
|
+
fps: number;
|
|
9
|
+
crf: number;
|
|
10
|
+
x264Preset: string;
|
|
11
|
+
/** Keyframe interval in frames. Every segment starts with a keyframe. */
|
|
12
|
+
gop: number;
|
|
13
|
+
/** Fixed, so the same plan encodes to the same bytes on any machine. */
|
|
14
|
+
threads: number;
|
|
15
|
+
outPath: string;
|
|
16
|
+
}
|
|
17
|
+
/** Arguments that turn a stream of JPEG frames on stdin into one H.264 segment. */
|
|
18
|
+
export declare function segmentEncodeArgs(o: SegmentEncodeOptions): string[];
|
|
19
|
+
export interface MuxOptions {
|
|
20
|
+
/** Concat list written by writeConcatList. */
|
|
21
|
+
listPath: string;
|
|
22
|
+
/** Mixed narration track (WAV), or null for a silent video. */
|
|
23
|
+
audioPath: string | null;
|
|
24
|
+
outPath: string;
|
|
25
|
+
/** Length of the video. The audio is padded or cut to exactly this length. */
|
|
26
|
+
durationSec: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Arguments that join the segments without re-encoding and add the audio as AAC. Metadata is
|
|
30
|
+
* stripped, including the encoder's own settings string, and the index is moved to the front so
|
|
31
|
+
* the video starts playing before it has fully downloaded.
|
|
32
|
+
*/
|
|
33
|
+
export declare function muxArgs(o: MuxOptions): string[];
|
|
34
|
+
/** Text of a concat demuxer list. Single quotes in paths are escaped. */
|
|
35
|
+
export declare function concatListText(paths: readonly string[], platform?: NodeJS.Platform): string;
|
|
36
|
+
export declare function concatAndMux(ffmpegPath: string, options: MuxOptions, signal?: AbortSignal): Promise<void>;
|
|
37
|
+
/** Duration of a media file in seconds. */
|
|
38
|
+
export declare function probeDuration(ffprobePath: string, file: string, signal?: AbortSignal): Promise<number>;
|
|
39
|
+
/** An FFmpeg process that encodes JPEG frames written to it. */
|
|
40
|
+
export declare class SegmentEncoder {
|
|
41
|
+
private readonly child;
|
|
42
|
+
private stderr;
|
|
43
|
+
private failure;
|
|
44
|
+
private closed;
|
|
45
|
+
private readonly done;
|
|
46
|
+
private constructor();
|
|
47
|
+
/** Start ffmpeg with the given arguments. Frames go to its stdin. */
|
|
48
|
+
static start(ffmpegPath: string, args: string[]): SegmentEncoder;
|
|
49
|
+
/** Write one JPEG frame, waiting when the pipe is full. */
|
|
50
|
+
write(frame: Buffer): Promise<void>;
|
|
51
|
+
/** Close the input and wait for ffmpeg to finish. Rejects when ffmpeg fails. */
|
|
52
|
+
finish(): Promise<void>;
|
|
53
|
+
/** Stop ffmpeg now. */
|
|
54
|
+
kill(): void;
|
|
55
|
+
}
|