@oh-story/dsh 0.1.4 → 0.1.6
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/README.md +56 -12
- package/lib/client.js +2707 -268
- package/lib/client.js.map +4 -4
- package/lib/drama/manifest.json +136 -101
- package/lib/drama/skills/short-drama/SKILL.md +61 -1
- package/lib/drama/skills/short-drama/references/contract-and-ownership.md +7 -4
- package/lib/drama/skills/short-drama/references/creator-documents.md +133 -8
- package/lib/drama/skills/short-drama/references/creator-workflow.md +38 -2
- package/lib/drama/skills/short-drama/references/knowhow-index.md +3 -0
- package/lib/drama/skills/short-drama/references/reference-roles.md +10 -7
- package/lib/drama/skills/short-drama/references/runtime-preflight.md +3 -0
- package/lib/drama/skills/short-drama/scripts/creator_markdown_check.py +1002 -0
- package/lib/drama/skills/short-drama/scripts/project_tool.py +485 -5
- package/lib/drama/skills/short-drama-assets/SKILL.md +13 -3
- package/lib/drama/skills/short-drama-assets/references/continuity-lock.md +116 -0
- package/lib/drama/skills/short-drama-assets/references/identity-vs-variant.md +2 -1
- package/lib/drama/skills/short-drama-assets/references/prop-and-state.md +19 -0
- package/lib/drama/skills/short-drama-assets/references/stage-contract.md +2 -0
- package/lib/drama/skills/short-drama-assets/scripts/asset_check.py +1 -1
- package/lib/drama/skills/short-drama-image-prompts/SKILL.md +6 -2
- package/lib/drama/skills/short-drama-image-prompts/references/common-recipe.md +4 -3
- package/lib/drama/skills/short-drama-image-prompts/references/lookdev-frame.md +1 -1
- package/lib/drama/skills/short-drama-image-prompts/references/review-and-fixtures.md +1 -1
- package/lib/drama/skills/short-drama-image-prompts/references/stage-contract.md +3 -1
- package/lib/drama/skills/short-drama-image-prompts/scripts/image_prompt_check.py +8 -8
- package/lib/drama/skills/short-drama-image-prompts/scripts/selftest.py +4 -2
- package/lib/drama/skills/short-drama-produce/SKILL.md +46 -10
- package/lib/drama/skills/short-drama-produce/references/adapter-contract.md +65 -8
- package/lib/drama/skills/short-drama-produce/references/providers/minimax-h3-video.md +85 -0
- package/lib/drama/skills/short-drama-produce/references/providers/seedance.md +27 -10
- package/lib/drama/skills/short-drama-produce/scripts/production_tool.py +362 -3
- package/lib/drama/skills/short-drama-produce/scripts/provider_adapters.py +627 -40
- package/lib/drama/skills/short-drama-produce/scripts/selftest.py +5 -4
- package/lib/drama/skills/short-drama-review/references/rubric-visual-motion.md +12 -0
- package/lib/drama/skills/short-drama-review/scripts/review_check.py +1 -1
- package/lib/drama/skills/short-drama-storyboard/SKILL.md +76 -7
- package/lib/drama/skills/short-drama-storyboard/assets/shot-template.jsonl +1 -1
- package/lib/drama/skills/short-drama-storyboard/references/keyframe-craft.md +6 -2
- package/lib/drama/skills/short-drama-storyboard/references/production-shot-grammar.md +19 -4
- package/lib/drama/skills/short-drama-storyboard/references/review-and-fixtures.md +5 -2
- package/lib/drama/skills/short-drama-storyboard/references/screenplay-to-keyframe-example.md +16 -0
- package/lib/drama/skills/short-drama-storyboard/references/stage-contract.md +8 -3
- package/lib/drama/skills/short-drama-storyboard/scripts/storyboard_check.py +1 -1
- package/lib/drama/skills/short-drama-video-prompts/SKILL.md +81 -13
- package/lib/drama/skills/short-drama-video-prompts/assets/motion-spec.jsonl.md +6 -1
- package/lib/drama/skills/short-drama-video-prompts/assets/video-prompts.md +17 -1
- package/lib/drama/skills/short-drama-video-prompts/references/delivery-profile.md +21 -1
- package/lib/drama/skills/short-drama-video-prompts/references/minimax-h3.md +154 -0
- package/lib/drama/skills/short-drama-video-prompts/references/motion-recipe.md +24 -6
- package/lib/drama/skills/short-drama-video-prompts/references/production-prompt-grammar.md +11 -7
- package/lib/drama/skills/short-drama-video-prompts/references/seedance-2.0.md +41 -0
- package/lib/drama/skills/short-drama-video-prompts/references/seedance-2.5.md +66 -0
- package/lib/drama/skills/short-drama-video-prompts/references/stage-contract.md +5 -2
- package/lib/drama/skills/short-drama-video-prompts/references/target-model-profile.md +115 -0
- package/lib/drama/skills/short-drama-video-prompts/scripts/container_check.py +1 -1
- package/lib/drama/skills/short-drama-video-prompts/scripts/music_spec_check.py +1 -1
- package/lib/drama/skills/short-drama-write/SKILL.md +3 -2
- package/lib/drama/skills/short-drama-write/scripts/duration_estimate.py +1 -1
- package/lib/drama/skills/short-drama-write/scripts/screenplay_index.py +2 -2
- package/lib/drama/skills/short-drama-write/scripts/voice_sheet_check.py +1 -1
- package/lib/index.js +865 -33
- package/lib/index.js.map +4 -4
- package/lib/novel-to-game/LICENSE +21 -0
- package/lib/novel-to-game/README.md +180 -0
- package/lib/novel-to-game/README_ZH.md +178 -0
- package/lib/novel-to-game/VERSION +1 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/BUILD_BRIEF.md +217 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/.vercelignore +3 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/RUN.md +130 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/bg/compound_new_guofeng.webp +0 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/finale/fate_coda.webp +0 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/finale/meng.webp +0 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/finale/pan.webp +0 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/finale/pinger.webp +0 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/finale/xuee.webp +0 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/finale/yue.webp +0 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/group/inner_court_accord_five.webp +0 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/group/inner_court_afterglow_five.webp +0 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/group/inner_court_alliance.webp +0 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/group/public_day10.webp +0 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/group/public_day15.webp +0 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/group/public_day5.webp +0 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/group/title_new_guofeng.webp +0 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/joint/pan_pinger.webp +0 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/joint/pan_xuee.webp +0 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/joint/yue_meng.webp +0 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/joint/yue_pan.webp +0 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/joint/yue_pinger.webp +0 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/meng/explicit.webp +0 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/meng/prelude.webp +0 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/milestone/meng.webp +0 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/milestone/pan.webp +0 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/milestone/pinger.webp +0 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/milestone/xuee.webp +0 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/milestone/yue.webp +0 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/pan/explicit.webp +0 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/pan/prelude.webp +0 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/pinger/explicit.webp +0 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/pinger/prelude.webp +0 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/xuee/explicit.webp +0 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/xuee/prelude.webp +0 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/yue/explicit.webp +0 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/cg/yue/prelude.webp +0 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/heroine/meng/night.webp +0 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/heroine/pan/night.webp +0 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/heroine/pinger/night.webp +0 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/heroine/xuee/night.webp +0 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/heroine/yue/night.webp +0 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/household/li_jiaoer.webp +0 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/assets/scene/gate_collector.webp +0 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/css/new-guofeng.css +1105 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/css/style.css +2539 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/index.html +18 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/js/assets.js +147 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/js/audio.js +332 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/js/data.js +7472 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/js/engine.js +13077 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/js/main.js +3028 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/js/text.js +32 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/package.json +10 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/app/vercel.json +23 -0
- package/lib/novel-to-game/examples/jin-ping-mei/build/art/generated-art.json +161 -0
- package/lib/novel-to-game/examples/jin-ping-mei/example.json +12 -0
- package/lib/novel-to-game/examples/jin-ping-mei/qa/README.md +31 -0
- package/lib/novel-to-game/examples/jin-ping-mei/qa/playable-model.json +99 -0
- package/lib/novel-to-game/examples/jin-ping-mei/qa/verification.json +41 -0
- package/lib/novel-to-game/examples/jin-ping-mei/qa/verify_playable_model.mjs +129 -0
- package/lib/novel-to-game/manifest.json +508 -0
- package/lib/novel-to-game/skills/game-art-direction/SKILL.md +73 -0
- package/lib/novel-to-game/skills/game-art-direction/agents/openai.yaml +4 -0
- package/lib/novel-to-game/skills/game-art-direction/references/art-direction-method.md +119 -0
- package/lib/novel-to-game/skills/game-build/SKILL.md +84 -0
- package/lib/novel-to-game/skills/game-build/agents/openai.yaml +4 -0
- package/lib/novel-to-game/skills/game-build/references/build-brief-contract.md +109 -0
- package/lib/novel-to-game/skills/game-build/references/generative-media-pipeline.md +56 -0
- package/lib/novel-to-game/skills/game-build/references/playable-model-contract.md +81 -0
- package/lib/novel-to-game/skills/game-build/references/tts-production-contract.md +37 -0
- package/lib/novel-to-game/skills/game-concept/SKILL.md +72 -0
- package/lib/novel-to-game/skills/game-concept/agents/openai.yaml +4 -0
- package/lib/novel-to-game/skills/game-concept/references/concept-method.md +94 -0
- package/lib/novel-to-game/skills/game-qa/SKILL.md +50 -0
- package/lib/novel-to-game/skills/game-qa/agents/openai.yaml +4 -0
- package/lib/novel-to-game/skills/game-qa/references/qa-contract.md +66 -0
- package/lib/novel-to-game/skills/game-qa/references/test-design-method.md +45 -0
- package/lib/novel-to-game/skills/game-world-design/SKILL.md +63 -0
- package/lib/novel-to-game/skills/game-world-design/agents/openai.yaml +4 -0
- package/lib/novel-to-game/skills/game-world-design/references/dialogue-design-method.md +59 -0
- package/lib/novel-to-game/skills/game-world-design/references/game-writing-craft.md +53 -0
- package/lib/novel-to-game/skills/game-world-design/references/narrative-design-method.md +84 -0
- package/lib/novel-to-game/skills/game-world-design/references/numeric-design-method.md +56 -0
- package/lib/novel-to-game/skills/game-world-design/references/world-design-method.md +124 -0
- package/lib/novel-to-game/skills/novel-game-analyze/SKILL.md +77 -0
- package/lib/novel-to-game/skills/novel-game-analyze/agents/openai.yaml +4 -0
- package/lib/novel-to-game/skills/novel-game-analyze/references/gameability-protocol.md +65 -0
- package/lib/novel-to-game/skills/novel-to-game/SKILL.md +71 -0
- package/lib/novel-to-game/skills/novel-to-game/agents/openai.yaml +4 -0
- package/lib/novel-to-game/skills/novel-to-game/references/intake-benchmark-reference.md +42 -0
- package/lib/novel-to-game/skills/novel-to-game/references/intake-method.md +51 -0
- package/lib/novel-to-game/skills/novel-to-game/references/pipeline-contract.md +65 -0
- package/lib/oh-story/manifest.json +415 -305
- package/lib/oh-story/roles/consistency-checker.md +1 -1
- package/lib/oh-story/roles/narrative-writer.md +32 -33
- package/lib/oh-story/roles/story-architect.md +16 -26
- package/lib/oh-story/skills/browser-cdp/SKILL.md +1 -1
- package/lib/oh-story/skills/story/SKILL.md +16 -9
- package/lib/oh-story/skills/story/VERSION +1 -1
- package/lib/oh-story/skills/story/references/author-memory.md +163 -0
- package/lib/oh-story/skills/story/scripts/author_memory_commit.py +871 -0
- package/lib/oh-story/skills/story-cover/SKILL.md +1 -1
- package/lib/oh-story/skills/story-deslop/SKILL.md +10 -5
- package/lib/oh-story/skills/story-deslop/references/anti-ai-writing.md +2 -1
- package/lib/oh-story/skills/story-deslop/references/author-memory.md +163 -0
- package/lib/oh-story/skills/story-deslop/references/banned-words.md +6 -4
- package/lib/oh-story/skills/story-deslop/scripts/author_memory_commit.py +871 -0
- package/lib/oh-story/skills/story-deslop/scripts/check-ai-patterns.js +64 -1
- package/lib/oh-story/skills/story-import/SKILL.md +19 -10
- package/lib/oh-story/skills/story-import/references/format-and-structure.md +9 -10
- package/lib/oh-story/skills/story-import/references/structure-mapping-long.md +2 -2
- package/lib/oh-story/skills/story-import/references/structure-mapping-short.md +1 -1
- package/lib/oh-story/skills/story-import/references/tracking-transaction.md +14 -6
- package/lib/oh-story/skills/story-import/scripts/check-outline-contract.js +251 -0
- package/lib/oh-story/skills/story-import/scripts/tracking_commit.py +98 -9
- package/lib/oh-story/skills/story-import/scripts/wordcount_core.py +246 -0
- package/lib/oh-story/skills/story-long-analyze/SKILL.md +4 -4
- package/lib/oh-story/skills/story-long-scan/SKILL.md +1 -1
- package/lib/oh-story/skills/story-long-write/SKILL.md +35 -21
- package/lib/oh-story/skills/story-long-write/references/anti-ai-writing.md +2 -1
- package/lib/oh-story/skills/story-long-write/references/artifact-protocols.md +7 -3
- package/lib/oh-story/skills/story-long-write/references/author-memory.md +163 -0
- package/lib/oh-story/skills/story-long-write/references/banned-words.md +6 -4
- package/lib/oh-story/skills/story-long-write/references/cross-book-recall.md +6 -6
- package/lib/oh-story/skills/story-long-write/references/genre-prose-cards.md +1 -1
- package/lib/oh-story/skills/story-long-write/references/genre-readers.md +1 -1
- package/lib/oh-story/skills/{story-setup/references/agent-references/hooks-chapter.md → story-long-write/references/long-chapter-hooks.md} +5 -5
- package/lib/oh-story/skills/story-long-write/references/{quality-checklist.md → long-chapter-quality.md} +2 -1
- package/lib/oh-story/skills/story-long-write/references/long-format.md +42 -0
- package/lib/oh-story/skills/{story-setup/references/agent-references/genre-catalog.md → story-long-write/references/long-genre-catalog.md} +11 -97
- package/lib/oh-story/skills/{story-setup/references/agent-references/genre-core-mechanics.md → story-long-write/references/long-genre-mechanics.md} +1 -1
- package/lib/oh-story/skills/{story-short-write/references/reversal-toolkit.md → story-long-write/references/long-reversal.md} +18 -32
- package/lib/oh-story/skills/story-long-write/references/{hooks-suspense.md → long-suspense.md} +6 -6
- package/lib/oh-story/skills/story-long-write/references/opening-design.md +1 -1
- package/lib/oh-story/skills/story-long-write/references/outline-structure-theory.md +1 -1
- package/lib/oh-story/skills/story-long-write/references/style-genre-modules.md +1 -1
- package/lib/oh-story/skills/story-long-write/references/tracking-transaction.md +14 -6
- package/lib/oh-story/skills/story-long-write/references/workflow-chapter.md +32 -27
- package/lib/oh-story/skills/story-long-write/references/workflow-daily.md +4 -4
- package/lib/oh-story/skills/story-long-write/references/workflow-revision.md +2 -2
- package/lib/oh-story/skills/story-long-write/references/workflow-setup.md +14 -14
- package/lib/oh-story/skills/story-long-write/references/writing-craft.md +54 -54
- package/lib/oh-story/skills/story-long-write/scripts/author_memory_commit.py +871 -0
- package/lib/oh-story/skills/story-long-write/scripts/check-ai-patterns.js +64 -1
- package/lib/oh-story/skills/story-long-write/scripts/check-outline-contract.js +251 -0
- package/lib/oh-story/skills/story-long-write/scripts/storyctl.py +303 -0
- package/lib/oh-story/skills/story-long-write/scripts/tracking_commit.py +98 -9
- package/lib/oh-story/skills/story-long-write/scripts/wordcount_core.py +246 -0
- package/lib/oh-story/skills/story-review/SKILL.md +26 -17
- package/lib/oh-story/skills/story-review/references/anti-ai-writing.md +2 -1
- package/lib/oh-story/skills/story-review/references/author-memory.md +163 -0
- package/lib/oh-story/skills/story-review/references/banned-words.md +6 -4
- package/lib/oh-story/skills/story-review/references/{quality-checklist.md → review-quality.md} +22 -21
- package/lib/oh-story/skills/story-review/references/tracking-transaction.md +14 -6
- package/lib/oh-story/skills/story-review/scripts/author_memory_commit.py +871 -0
- package/lib/oh-story/skills/story-review/scripts/check-ai-patterns.js +64 -1
- package/lib/oh-story/skills/story-review/scripts/tracking_commit.py +98 -9
- package/lib/oh-story/skills/story-review/scripts/wordcount_core.py +246 -0
- package/lib/oh-story/skills/story-setup/SKILL.md +74 -33
- package/lib/oh-story/skills/story-setup/references/agent-references/agent-quality.md +72 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/agent-reference-profiles.md +55 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/anti-ai-writing.md +2 -1
- package/lib/oh-story/skills/story-setup/references/agent-references/banned-words.md +6 -4
- package/lib/oh-story/skills/story-setup/references/agent-references/format-and-structure.md +9 -10
- package/lib/oh-story/skills/story-setup/references/agent-references/genre-prose-cards.md +1 -1
- package/lib/oh-story/skills/story-setup/references/agent-references/genre-readers.md +1 -1
- package/lib/oh-story/skills/{story-short-analyze/references/hooks-chapter.md → story-setup/references/agent-references/long-chapter-hooks.md} +5 -5
- package/lib/oh-story/skills/story-setup/references/agent-references/long-emotional-methods.md +209 -0
- package/lib/oh-story/skills/{story-long-write/references/genre-catalog.md → story-setup/references/agent-references/long-genre-catalog.md} +11 -97
- package/lib/oh-story/skills/{story-long-write/references/genre-core-mechanics.md → story-setup/references/agent-references/long-genre-mechanics.md} +1 -1
- package/lib/oh-story/skills/story-setup/references/agent-references/long-quality.md +40 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/{reversal-toolkit.md → long-reversal.md} +18 -32
- package/lib/oh-story/skills/{story-short-write/references/hooks-suspense.md → story-setup/references/agent-references/long-suspense.md} +6 -6
- package/lib/oh-story/skills/story-setup/references/agent-references/opening-design.md +1 -1
- package/lib/oh-story/skills/story-setup/references/agent-references/{emotional-methods.md → short-emotional-methods.md} +4 -4
- package/lib/oh-story/skills/{story-long-write/references/genre-writing-formulas.md → story-setup/references/agent-references/short-genre-formulas.md} +32 -44
- package/lib/oh-story/skills/story-setup/references/agent-references/short-quality.md +39 -0
- package/lib/oh-story/skills/{story-long-write/references/reversal-toolkit.md → story-setup/references/agent-references/short-reversal.md} +29 -23
- package/lib/oh-story/skills/story-setup/references/agent-references/{hooks-suspense.md → short-suspense.md} +31 -31
- package/lib/oh-story/skills/story-setup/references/agent-references/style-genre-modules.md +1 -1
- package/lib/oh-story/skills/story-setup/references/agent-references/writing-craft.md +55 -55
- package/lib/oh-story/skills/story-short-analyze/SKILL.md +28 -28
- package/lib/oh-story/skills/story-short-analyze/references/{character-basics.md → analysis-character-basics.md} +1 -1
- package/lib/oh-story/skills/story-short-analyze/references/{character-design-methods.md → analysis-character-design.md} +1 -1
- package/lib/oh-story/skills/story-short-analyze/references/{character-relations.md → analysis-character-relations.md} +1 -1
- package/lib/oh-story/skills/story-short-analyze/references/{hooks-paragraph.md → analysis-paragraph-hooks.md} +1 -1
- package/lib/oh-story/skills/story-short-analyze/references/{genre-readers.md → analysis-reader-profile.md} +2 -2
- package/lib/oh-story/skills/story-short-analyze/references/analysis-report-style.md +45 -0
- package/lib/oh-story/skills/story-short-analyze/references/analysis-short-genres.md +65 -0
- package/lib/oh-story/skills/story-short-analyze/references/analysis-short-hooks.md +77 -0
- package/lib/oh-story/skills/story-short-analyze/references/analysis-short-mechanics.md +82 -0
- package/lib/oh-story/skills/story-short-analyze/references/analysis-short-patterns.md +50 -0
- package/lib/oh-story/skills/story-short-analyze/references/analysis-short-suspense.md +98 -0
- package/lib/oh-story/skills/story-short-analyze/references/{genre-writing-techniques.md → analysis-writing-techniques.md} +21 -19
- package/lib/oh-story/skills/story-short-analyze/references/deconstruction-examples.md +1 -1
- package/lib/oh-story/skills/story-short-analyze/references/material-decomposition.md +21 -28
- package/lib/oh-story/skills/story-short-analyze/references/output-contract.md +1 -1
- package/lib/oh-story/skills/story-short-analyze/references/output-templates.md +17 -17
- package/lib/oh-story/skills/story-short-analyze/references/{quality-checklist.md → source-story-quality.md} +28 -49
- package/lib/oh-story/skills/story-short-analyze/references/zhihu-style.md +2 -2
- package/lib/oh-story/skills/story-short-scan/SKILL.md +1 -1
- package/lib/oh-story/skills/story-short-write/SKILL.md +78 -55
- package/lib/oh-story/skills/story-short-write/references/author-memory.md +163 -0
- package/lib/oh-story/skills/story-short-write/references/banned-words.md +6 -4
- package/lib/oh-story/skills/story-short-write/references/cross-book-recall.md +3 -3
- package/lib/oh-story/skills/story-short-write/references/emotional-methods.md +4 -4
- package/lib/oh-story/skills/story-short-write/references/genre-styles//344/270/226/346/203/205/346/211/223/350/204/270.md +3 -3
- package/lib/oh-story/skills/story-short-write/references/genre-styles//345/217/214/347/224/267/344/270/273.md +2 -2
- package/lib/oh-story/skills/story-short-write/references/genre-styles//345/244/215/344/273/207/346/211/223/350/204/270.md +3 -3
- package/lib/oh-story/skills/story-short-write/references/genre-styles//345/256/205/346/226/227/345/256/253/346/226/227.md +6 -6
- package/lib/oh-story/skills/story-short-write/references/genre-styles//346/200/273/350/243/201/350/261/252/351/227/250.md +3 -3
- package/lib/oh-story/skills/story-short-write/references/genre-styles//346/202/254/347/226/221.md +4 -4
- package/lib/oh-story/skills/story-short-write/references/genre-styles//346/260/221/344/277/227/346/200/252/350/260/210.md +7 -7
- package/lib/oh-story/skills/story-short-write/references/genre-styles//346/262/231/351/233/225/350/204/221/346/264/236.md +5 -5
- package/lib/oh-story/skills/story-short-write/references/genre-styles//347/224/234/345/256/240.md +4 -4
- package/lib/oh-story/skills/story-short-write/references/genre-styles//350/277/275/345/246/273/347/201/253/350/221/254/345/234/272.md +3 -3
- package/lib/oh-story/skills/story-short-write/references/genre-writing-formulas.md +32 -44
- package/lib/oh-story/skills/story-short-write/references/genre-writing-techniques.md +20 -18
- package/lib/oh-story/skills/story-short-write/references/output-contract.md +1 -1
- package/lib/oh-story/skills/story-short-write/references/short-craft.md +18 -18
- package/lib/oh-story/skills/story-short-write/references/short-deslop.md +1 -1
- package/lib/oh-story/skills/story-short-write/references/short-format.md +38 -8
- package/lib/oh-story/skills/story-short-write/references/{quality-checklist.md → short-prose-quality.md} +22 -21
- package/lib/oh-story/skills/story-short-write/references/short-reversal.md +355 -0
- package/lib/oh-story/skills/{story-short-analyze/references/hooks-suspense.md → story-short-write/references/short-suspense.md} +31 -31
- package/lib/oh-story/skills/story-short-write/references/submission-craft.md +2 -2
- package/lib/oh-story/skills/story-short-write/references/writing-workflow.md +31 -22
- package/lib/oh-story/skills/story-short-write/scripts/author_memory_commit.py +871 -0
- package/lib/oh-story/skills/story-short-write/scripts/check-ai-patterns.js +64 -1
- package/lib/oh-story/skills/story-short-write/scripts/check-delivery-contract.js +212 -0
- package/lib/oh-story/skills/story-short-write/scripts/check-phase2-contract.js +363 -0
- package/lib/types/client/drama-production-view.d.ts +34 -0
- package/lib/types/client/drama-production-view.d.ts.map +1 -0
- package/lib/types/client/drama-production.d.ts +92 -0
- package/lib/types/client/drama-production.d.ts.map +1 -0
- package/lib/types/client/file-activity.d.ts +4 -2
- package/lib/types/client/file-activity.d.ts.map +1 -1
- package/lib/types/client/index.d.ts +1 -1
- package/lib/types/client/index.d.ts.map +1 -1
- package/lib/types/client/production-intents.d.ts +9 -0
- package/lib/types/client/production-intents.d.ts.map +1 -0
- package/lib/types/client/production-prompts.d.ts +9 -0
- package/lib/types/client/production-prompts.d.ts.map +1 -0
- package/lib/types/client/production-runtime.d.ts +58 -0
- package/lib/types/client/production-runtime.d.ts.map +1 -0
- package/lib/types/client/video-studio.d.ts +41 -0
- package/lib/types/client/video-studio.d.ts.map +1 -0
- package/lib/types/client/workbench-ui.d.ts +5 -0
- package/lib/types/client/workbench-ui.d.ts.map +1 -0
- package/lib/types/game-verification.d.ts +16 -0
- package/lib/types/game-verification.d.ts.map +1 -0
- package/lib/types/index.d.ts +3 -1
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/production-intent.d.ts +21 -0
- package/lib/types/production-intent.d.ts.map +1 -0
- package/lib/types/production-tool.d.ts +5 -0
- package/lib/types/production-tool.d.ts.map +1 -0
- package/lib/types/role-tool.d.ts.map +1 -1
- package/lib/types/skill-provider.d.ts +7 -0
- package/lib/types/skill-provider.d.ts.map +1 -1
- package/lib/types/video-project.d.ts +42 -0
- package/lib/types/video-project.d.ts.map +1 -0
- package/lib/types/workspace-request-trust.d.ts +6 -0
- package/lib/types/workspace-request-trust.d.ts.map +1 -1
- package/lib/types/workspace-route.d.ts +20 -0
- package/lib/types/workspace-route.d.ts.map +1 -1
- package/lib/video-recap/CHANGELOG.md +282 -0
- package/lib/video-recap/LICENSE +21 -0
- package/lib/video-recap/README.en.md +257 -0
- package/lib/video-recap/README.md +255 -0
- package/lib/video-recap/manifest.json +684 -0
- package/lib/video-recap/skills/video-assemble/SKILL.md +97 -0
- package/lib/video-recap/skills/video-assemble/references/jianying/LICENSE.duo-video +21 -0
- package/lib/video-recap/skills/video-assemble/references/jianying/SOURCE.md +15 -0
- package/lib/video-recap/skills/video-assemble/references/jianying/empty_draft_meta_info.json +69 -0
- package/lib/video-recap/skills/video-assemble/references/jianying/empty_jy_combination_segment.json +84 -0
- package/lib/video-recap/skills/video-assemble/references/jianying/empty_jy_combination_video_material.json +98 -0
- package/lib/video-recap/skills/video-assemble/references/jianying/empty_jy_draft.json +204 -0
- package/lib/video-recap/skills/video-assemble/references/jianying/empty_jy_material_video.json +83 -0
- package/lib/video-recap/skills/video-assemble/references/jianying/empty_jy_meta_material_value.json +23 -0
- package/lib/video-recap/skills/video-assemble/references/jianying/empty_jy_project_info.json +133 -0
- package/lib/video-recap/skills/video-assemble/references/jianying/empty_jy_segment.json +70 -0
- package/lib/video-recap/skills/video-assemble/references/jianying/empty_jy_text_styles.json +30 -0
- package/lib/video-recap/skills/video-assemble/references/jianying/empty_yj_material_audio.json +41 -0
- package/lib/video-recap/skills/video-assemble/references/jianying/empty_yj_material_text.json +109 -0
- package/lib/video-recap/skills/video-assemble/scripts/artifacts.py +88 -0
- package/lib/video-recap/skills/video-assemble/scripts/assemble.py +345 -0
- package/lib/video-recap/skills/video-assemble/scripts/assemble_constants.py +34 -0
- package/lib/video-recap/skills/video-assemble/scripts/assembly_contract.py +305 -0
- package/lib/video-recap/skills/video-assemble/scripts/assembly_settings.py +94 -0
- package/lib/video-recap/skills/video-assemble/scripts/audio_automation.py +205 -0
- package/lib/video-recap/skills/video-assemble/scripts/audio_mix.py +555 -0
- package/lib/video-recap/skills/video-assemble/scripts/export_jianying.py +261 -0
- package/lib/video-recap/skills/video-assemble/scripts/jianying_builders.py +767 -0
- package/lib/video-recap/skills/video-assemble/scripts/jianying_model.py +111 -0
- package/lib/video-recap/skills/video-assemble/scripts/jianying_optional.py +24 -0
- package/lib/video-recap/skills/video-assemble/scripts/jianying_schema.py +109 -0
- package/lib/video-recap/skills/video-assemble/scripts/jianying_templates.py +37 -0
- package/lib/video-recap/skills/video-assemble/scripts/jianying_timeline_contract.py +191 -0
- package/lib/video-recap/skills/video-assemble/scripts/jianying_tracks.py +75 -0
- package/lib/video-recap/skills/video-assemble/scripts/jianying_writer.py +394 -0
- package/lib/video-recap/skills/video-assemble/scripts/lib.py +239 -0
- package/lib/video-recap/skills/video-assemble/scripts/media.py +243 -0
- package/lib/video-recap/skills/video-assemble/scripts/narration_audio.py +477 -0
- package/lib/video-recap/skills/video-assemble/scripts/render_preflight.py +46 -0
- package/lib/video-recap/skills/video-assemble/scripts/source_subtitles.py +486 -0
- package/lib/video-recap/skills/video-assemble/scripts/subtitle_core.py +376 -0
- package/lib/video-recap/skills/video-assemble/scripts/subtitle_render.py +88 -0
- package/lib/video-recap/skills/video-assemble/scripts/timeline.py +248 -0
- package/lib/video-recap/skills/video-assemble/scripts/timeline_emit.py +89 -0
- package/lib/video-recap/skills/video-assemble/scripts/visual_render.py +512 -0
- package/lib/video-recap/skills/video-cut/SKILL.md +90 -0
- package/lib/video-recap/skills/video-cut/scripts/cut.py +67 -0
- package/lib/video-recap/skills/video-cut/scripts/cut_cli.py +320 -0
- package/lib/video-recap/skills/video-cut/scripts/cut_contract.py +545 -0
- package/lib/video-recap/skills/video-cut/scripts/cut_render.py +348 -0
- package/lib/video-recap/skills/video-cut/scripts/lib.py +77 -0
- package/lib/video-recap/skills/video-cut/scripts/media_geometry.py +341 -0
- package/lib/video-recap/skills/video-cut/scripts/narration_mapping.py +249 -0
- package/lib/video-recap/skills/video-cut/scripts/sentence_boundaries.py +745 -0
- package/lib/video-recap/skills/video-recap/SKILL.md +216 -0
- package/lib/video-recap/skills/video-recap/references/config-playbook.md +61 -0
- package/lib/video-recap/skills/video-recap/references/creative-editing-playbook.md +225 -0
- package/lib/video-recap/skills/video-recap/references/data-schema.md +534 -0
- package/lib/video-recap/skills/video-recap/references/research-guide.md +74 -0
- package/lib/video-recap/skills/video-recap/references/shift-left-qc-schema.md +23 -0
- package/lib/video-recap/skills/video-recap/references/timeline-and-jianying.md +251 -0
- package/lib/video-recap/skills/video-recap/scripts/doctor.py +483 -0
- package/lib/video-recap/skills/video-recap/scripts/final_qc.py +737 -0
- package/lib/video-recap/skills/video-recap/scripts/lib.py +242 -0
- package/lib/video-recap/skills/video-recap/scripts/materials.py +457 -0
- package/lib/video-recap/skills/video-recap/scripts/mimo_qc.py +95 -0
- package/lib/video-recap/skills/video-recap/scripts/mimo_qc_client.py +18 -0
- package/lib/video-recap/skills/video-recap/scripts/mimo_qc_contract.py +9 -0
- package/lib/video-recap/skills/video-recap/scripts/mimo_qc_evidence.py +371 -0
- package/lib/video-recap/skills/video-recap/scripts/mimo_qc_observations.py +201 -0
- package/lib/video-recap/skills/video-recap/scripts/mimo_qc_payload.py +227 -0
- package/lib/video-recap/skills/video-recap/scripts/mimo_qc_report.py +362 -0
- package/lib/video-recap/skills/video-recap/scripts/mimo_qc_runner.py +129 -0
- package/lib/video-recap/skills/video-recap/scripts/qc_contract.py +338 -0
- package/lib/video-recap/skills/video-recap/scripts/recap.py +9 -0
- package/lib/video-recap/skills/video-recap/scripts/recap_cli.py +140 -0
- package/lib/video-recap/skills/video-recap/scripts/recap_inspect.py +550 -0
- package/lib/video-recap/skills/video-recap/scripts/recap_review.py +77 -0
- package/lib/video-recap/skills/video-recap/scripts/recap_runner.py +654 -0
- package/lib/video-recap/skills/video-recap/scripts/recap_runtime.py +335 -0
- package/lib/video-recap/skills/video-recap/scripts/recap_stage_qc.py +217 -0
- package/lib/video-recap/skills/video-recap/scripts/recap_timeline.py +795 -0
- package/lib/video-recap/skills/video-script/SKILL.md +248 -0
- package/lib/video-recap/skills/video-script/references/creative-editing-playbook.md +225 -0
- package/lib/video-recap/skills/video-script/references/research-guide.md +75 -0
- package/lib/video-recap/skills/video-script/scripts/agent_brief.py +399 -0
- package/lib/video-recap/skills/video-script/scripts/agent_text.py +410 -0
- package/lib/video-recap/skills/video-script/scripts/brief_context.py +403 -0
- package/lib/video-recap/skills/video-script/scripts/brief_inputs.py +332 -0
- package/lib/video-recap/skills/video-script/scripts/brief_timeline.py +442 -0
- package/lib/video-recap/skills/video-script/scripts/deslop_qc.py +237 -0
- package/lib/video-recap/skills/video-script/scripts/evidence_bundle.py +492 -0
- package/lib/video-recap/skills/video-script/scripts/lib.py +327 -0
- package/lib/video-recap/skills/video-script/scripts/narration.py +12 -0
- package/lib/video-recap/skills/video-script/scripts/narration_lint.py +678 -0
- package/lib/video-recap/skills/video-script/scripts/review.py +42 -0
- package/lib/video-recap/skills/video-script/scripts/review_grounding.py +262 -0
- package/lib/video-recap/skills/video-script/scripts/review_response.py +761 -0
- package/lib/video-recap/skills/video-script/scripts/review_runner.py +200 -0
- package/lib/video-recap/skills/video-script/scripts/speech_ownership.py +204 -0
- package/lib/video-recap/skills/video-script/scripts/timeline_fusion.py +199 -0
- package/lib/video-recap/skills/video-script/scripts/validate.py +164 -0
- package/lib/video-recap/skills/video-understanding/SKILL.md +75 -0
- package/lib/video-recap/skills/video-understanding/references/data-schema.md +299 -0
- package/lib/video-recap/skills/video-understanding/references/prompt-templates.md +37 -0
- package/lib/video-recap/skills/video-understanding/references/research-guide.md +74 -0
- package/lib/video-recap/skills/video-understanding/scripts/agent_brief.py +399 -0
- package/lib/video-recap/skills/video-understanding/scripts/agent_text.py +410 -0
- package/lib/video-recap/skills/video-understanding/scripts/asr.py +260 -0
- package/lib/video-recap/skills/video-understanding/scripts/brief.py +12 -0
- package/lib/video-recap/skills/video-understanding/scripts/brief_context.py +403 -0
- package/lib/video-recap/skills/video-understanding/scripts/brief_inputs.py +332 -0
- package/lib/video-recap/skills/video-understanding/scripts/brief_timeline.py +442 -0
- package/lib/video-recap/skills/video-understanding/scripts/consolidate.py +647 -0
- package/lib/video-recap/skills/video-understanding/scripts/deslop_qc.py +237 -0
- package/lib/video-recap/skills/video-understanding/scripts/detect.py +513 -0
- package/lib/video-recap/skills/video-understanding/scripts/extract.py +62 -0
- package/lib/video-recap/skills/video-understanding/scripts/lib.py +470 -0
- package/lib/video-recap/skills/video-understanding/scripts/narration_lint.py +678 -0
- package/lib/video-recap/skills/video-understanding/scripts/speech_ownership.py +204 -0
- package/lib/video-recap/skills/video-understanding/scripts/storyboard.py +507 -0
- package/lib/video-recap/skills/video-understanding/scripts/timeline_fusion.py +199 -0
- package/lib/video-recap/skills/video-understanding/scripts/understand.py +9 -0
- package/lib/video-recap/skills/video-understanding/scripts/understanding_brief.py +216 -0
- package/lib/video-recap/skills/video-understanding/scripts/understanding_cache.py +327 -0
- package/lib/video-recap/skills/video-understanding/scripts/understanding_runner.py +367 -0
- package/lib/video-recap/skills/video-understanding/scripts/understanding_storyboard.py +162 -0
- package/lib/video-recap/skills/video-understanding/scripts/vlm.py +705 -0
- package/lib/video-recap/skills/video-voiceover/SKILL.md +81 -0
- package/lib/video-recap/skills/video-voiceover/scripts/dub.py +637 -0
- package/lib/video-recap/skills/video-voiceover/scripts/fish_audio.py +109 -0
- package/lib/video-recap/skills/video-voiceover/scripts/lib.py +421 -0
- package/lib/video-recap/skills/video-voiceover/scripts/tts_audio.py +113 -0
- package/lib/video-recap/skills/video-voiceover/scripts/voiceover.py +782 -0
- package/package.json +55 -40
- package/lib/oh-story/skills/story-deslop/scripts/check-outline-copy.js +0 -241
- package/lib/oh-story/skills/story-long-write/references/format-and-structure.md +0 -169
- package/lib/oh-story/skills/story-setup/references/agent-references/genre-writing-formulas.md +0 -444
- package/lib/oh-story/skills/story-setup/references/agent-references/quality-checklist.md +0 -247
- package/lib/oh-story/skills/story-short-analyze/references/anti-ai-writing.md +0 -582
- package/lib/oh-story/skills/story-short-analyze/references/banned-words.md +0 -147
- package/lib/oh-story/skills/story-short-analyze/references/genre-catalog.md +0 -490
- package/lib/oh-story/skills/story-short-analyze/references/genre-core-mechanics.md +0 -425
- package/lib/oh-story/skills/story-short-analyze/references/genre-writing-formulas.md +0 -453
- /package/lib/oh-story/skills/{story-long-write/references/hooks-chapter.md → story-setup/references/agent-references/short-chapter-hooks.md} +0 -0
- /package/lib/oh-story/skills/{story-long-write/references/hooks-paragraph.md → story-setup/references/agent-references/short-paragraph-hooks.md} +0 -0
|
@@ -0,0 +1,513 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
import re
|
|
4
|
+
import subprocess
|
|
5
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from lib import CONFIG
|
|
9
|
+
from lib import log, run_cmd, get_video_duration, file_fingerprint
|
|
10
|
+
|
|
11
|
+
# ── Step 2: 场景检测 ──────────────────────────────────────────────────
|
|
12
|
+
|
|
13
|
+
def detect_scenes(video_path, work_dir, threshold=None):
|
|
14
|
+
"""使用 ffmpeg scdet 滤镜检测场景切换"""
|
|
15
|
+
threshold = CONFIG["scene_threshold"] if threshold is None else threshold
|
|
16
|
+
scdet_threshold = int(threshold * 100)
|
|
17
|
+
|
|
18
|
+
cmd = ["ffmpeg", "-i", str(video_path),
|
|
19
|
+
"-vf", f"scdet=threshold={scdet_threshold}",
|
|
20
|
+
"-f", "null", "-"]
|
|
21
|
+
result = run_cmd(cmd)
|
|
22
|
+
if result.returncode != 0:
|
|
23
|
+
raise RuntimeError(f"场景检测失败: {result.stderr}")
|
|
24
|
+
|
|
25
|
+
# 解析 lavfi.scd.time 和 lavfi.scd.score
|
|
26
|
+
times = []
|
|
27
|
+
for line in result.stderr.split("\n"):
|
|
28
|
+
match = re.search(r"lavfi\.scd\.time[:=]\s*(\S+)", line)
|
|
29
|
+
if match:
|
|
30
|
+
times.append(float(match.group(1)))
|
|
31
|
+
|
|
32
|
+
if not times:
|
|
33
|
+
# 没有检测到场景切换,整个视频作为一个场景
|
|
34
|
+
duration = get_video_duration(video_path)
|
|
35
|
+
scenes = [{"start": 0.0, "end": duration}]
|
|
36
|
+
log(f"未检测到场景切换,整个视频作为一个场景 ({duration:.1f}s)")
|
|
37
|
+
else:
|
|
38
|
+
scenes = []
|
|
39
|
+
prev = 0.0
|
|
40
|
+
for t in times:
|
|
41
|
+
scenes.append({"start": round(prev, 2), "end": round(t, 2)})
|
|
42
|
+
prev = t
|
|
43
|
+
# 最后一个场景到视频结束
|
|
44
|
+
duration = get_video_duration(video_path)
|
|
45
|
+
scenes.append({"start": round(prev, 2), "end": round(duration, 2)})
|
|
46
|
+
|
|
47
|
+
log(f"检测到 {len(scenes)} 个场景")
|
|
48
|
+
|
|
49
|
+
# 先过滤黑/白帧过渡场景,再合并短场景
|
|
50
|
+
# (合并会保留短场景的 start,若黑场被并入长场景,单点采样会误删整段,故顺序在前)
|
|
51
|
+
if CONFIG.get("scene_junk_filter", True):
|
|
52
|
+
scenes = _filter_junk_scenes(scenes, video_path)
|
|
53
|
+
# 合并短场景(< 3s 合并到相邻场景)
|
|
54
|
+
scenes = _merge_short_scenes(scenes, min_duration=CONFIG.get("scene_merge_min", 4.0))
|
|
55
|
+
|
|
56
|
+
# 保存
|
|
57
|
+
scenes_file = work_dir / "scenes.json"
|
|
58
|
+
scenes_file.write_text(json.dumps(scenes, ensure_ascii=False, indent=2), encoding="utf-8")
|
|
59
|
+
for i, s in enumerate(scenes):
|
|
60
|
+
log(f" 场景 {i+1}: {s['start']:.1f}s - {s['end']:.1f}s ({s['end']-s['start']:.1f}s)")
|
|
61
|
+
|
|
62
|
+
return scenes
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _merge_short_scenes(scenes, min_duration=4.0):
|
|
66
|
+
"""合并过短的场景到相邻场景"""
|
|
67
|
+
if len(scenes) <= 1:
|
|
68
|
+
return scenes
|
|
69
|
+
merged = [scenes[0]]
|
|
70
|
+
for s in scenes[1:]:
|
|
71
|
+
prev = merged[-1]
|
|
72
|
+
# 任一侧过短就把两段并成一段 [prev.start, s.end]。(原来写成 if/elif 两个分支,
|
|
73
|
+
# 但两个分支体完全一样,读起来像是有两种不同处理,实际没有区别。)
|
|
74
|
+
too_short = (
|
|
75
|
+
prev["end"] - prev["start"] < min_duration
|
|
76
|
+
or s["end"] - s["start"] < min_duration
|
|
77
|
+
)
|
|
78
|
+
if too_short:
|
|
79
|
+
merged[-1] = {"start": prev["start"], "end": s["end"]}
|
|
80
|
+
else:
|
|
81
|
+
merged.append(s)
|
|
82
|
+
# 如果最后一个太短,已在前一步合并
|
|
83
|
+
log(f"合并短场景后: {len(scenes)} → {len(merged)} 个场景")
|
|
84
|
+
return merged
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _sample_frame_luma(video_path, timestamp, sample_size=64):
|
|
88
|
+
"""Extract one frame via ffmpeg and return luma values without extra deps."""
|
|
89
|
+
cmd = [
|
|
90
|
+
"ffmpeg",
|
|
91
|
+
"-hide_banner",
|
|
92
|
+
"-loglevel",
|
|
93
|
+
"error",
|
|
94
|
+
"-ss",
|
|
95
|
+
f"{max(0.0, float(timestamp)):.3f}",
|
|
96
|
+
"-i",
|
|
97
|
+
str(video_path),
|
|
98
|
+
"-frames:v",
|
|
99
|
+
"1",
|
|
100
|
+
"-vf",
|
|
101
|
+
f"scale={sample_size}:{sample_size},format=rgb24",
|
|
102
|
+
"-f",
|
|
103
|
+
"rawvideo",
|
|
104
|
+
"-",
|
|
105
|
+
]
|
|
106
|
+
result = subprocess.run(cmd, capture_output=True)
|
|
107
|
+
if result.returncode != 0 or not result.stdout:
|
|
108
|
+
raise RuntimeError(result.stderr.decode("utf-8", errors="replace")[:300])
|
|
109
|
+
data = result.stdout
|
|
110
|
+
return [
|
|
111
|
+
0.2126 * data[i] + 0.7152 * data[i + 1] + 0.0722 * data[i + 2]
|
|
112
|
+
for i in range(0, len(data) - 2, 3)
|
|
113
|
+
]
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def _is_junk_scene(video_path, timestamp, threshold_dark=None, threshold_bright=None):
|
|
117
|
+
"""Return True for near-black or near-white scene-start frames."""
|
|
118
|
+
threshold_dark = CONFIG.get("scene_junk_dark_luma", 8.0) if threshold_dark is None else threshold_dark
|
|
119
|
+
threshold_bright = CONFIG.get("scene_junk_bright_luma", 245.0) if threshold_bright is None else threshold_bright
|
|
120
|
+
pixel_ratio = min(1.0, max(0.0, float(CONFIG.get("scene_junk_pixel_ratio", 0.995))))
|
|
121
|
+
try:
|
|
122
|
+
lumas = _sample_frame_luma(video_path, timestamp)
|
|
123
|
+
except Exception as exc:
|
|
124
|
+
log(f"场景亮度采样失败,保留场景 {timestamp:.1f}s: {exc}")
|
|
125
|
+
return False
|
|
126
|
+
if not lumas:
|
|
127
|
+
return False
|
|
128
|
+
avg_luma = sum(lumas) / len(lumas)
|
|
129
|
+
dark_ratio = sum(1 for value in lumas if value <= threshold_dark) / len(lumas)
|
|
130
|
+
bright_ratio = sum(1 for value in lumas if value >= threshold_bright) / len(lumas)
|
|
131
|
+
return (
|
|
132
|
+
avg_luma <= threshold_dark and dark_ratio >= pixel_ratio
|
|
133
|
+
) or (
|
|
134
|
+
avg_luma >= threshold_bright and bright_ratio >= pixel_ratio
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def _scene_is_junk(scene, video_path):
|
|
139
|
+
"""Whether every probe point of one scene is a black/white transition frame."""
|
|
140
|
+
start = float(scene["start"])
|
|
141
|
+
end = float(scene["end"])
|
|
142
|
+
# 多点采样:起始、中点、结尾各探一帧;只有全部为垃圾帧才删除,
|
|
143
|
+
# 含任意非垃圾帧的场景必须保留(避免短黑场并入长真实场景后被整段误删)
|
|
144
|
+
probe_times = [
|
|
145
|
+
min(end, start + 0.1),
|
|
146
|
+
(start + end) / 2.0,
|
|
147
|
+
max(start, end - 0.1),
|
|
148
|
+
]
|
|
149
|
+
# `all` 的短路很重要:绝大多数场景第一探就否掉,只花一次 ffmpeg。
|
|
150
|
+
return all(_is_junk_scene(video_path, t) for t in probe_times)
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def _filter_junk_scenes(scenes, video_path):
|
|
154
|
+
"""Filter black/white transition scenes while never deleting the whole video."""
|
|
155
|
+
if len(scenes) <= 1:
|
|
156
|
+
return scenes
|
|
157
|
+
# 每个探点都是一次 ffmpeg 进程(seek + 解一帧),一部 30 分钟片有几百个场景,串行下来
|
|
158
|
+
# 光进程启动就要几十秒。按场景并行:每个 worker 内部仍然短路,所以既保留了「多数场景只
|
|
159
|
+
# 探一次」,又把进程启动开销摊平。判定逻辑与探点完全不变。
|
|
160
|
+
workers = max(1, int(CONFIG.get("scene_junk_workers", 8) or 8))
|
|
161
|
+
with ThreadPoolExecutor(max_workers=min(workers, len(scenes))) as executor:
|
|
162
|
+
verdicts = list(executor.map(lambda s: _scene_is_junk(s, video_path), scenes))
|
|
163
|
+
filtered = []
|
|
164
|
+
removed = []
|
|
165
|
+
for scene, is_junk in zip(scenes, verdicts):
|
|
166
|
+
if is_junk:
|
|
167
|
+
removed.append(scene)
|
|
168
|
+
else:
|
|
169
|
+
filtered.append(scene)
|
|
170
|
+
if not filtered:
|
|
171
|
+
log("场景黑/白帧过滤会删除全部场景,已放弃过滤")
|
|
172
|
+
return scenes
|
|
173
|
+
if removed:
|
|
174
|
+
log(f"过滤黑/白帧过渡场景: {len(scenes)} → {len(filtered)}")
|
|
175
|
+
return filtered
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
# ── Step 3.5: 静音检测 ─────────────────────────────────────────────
|
|
180
|
+
|
|
181
|
+
# The silence-detection audio is always extracted below as 16 kHz mono signed-16 PCM.
|
|
182
|
+
_SILENCE_AUDIO_BYTES_PER_SECOND = 16000 * 1 * 2
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def _wav_seconds_estimate(audio_path):
|
|
186
|
+
"""Approximate duration from file size — no ffprobe subprocess on this path."""
|
|
187
|
+
try:
|
|
188
|
+
return max(0.0, Path(audio_path).stat().st_size / _SILENCE_AUDIO_BYTES_PER_SECOND)
|
|
189
|
+
except OSError:
|
|
190
|
+
return 0.0
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def _compact_ffmpeg_error(stderr, limit=400):
|
|
194
|
+
"""Keep the actionable tail without dumping ffmpeg build/configuration banners."""
|
|
195
|
+
text = " ".join(str(stderr or "").split())
|
|
196
|
+
if len(text) <= limit:
|
|
197
|
+
return text
|
|
198
|
+
return "…" + text[-limit:]
|
|
199
|
+
|
|
200
|
+
def annotate_quiet_windows_with_asr(periods, asr_result=None, *, video_duration=None, configured_segment_seconds=None):
|
|
201
|
+
"""Pure helper: annotate quiet windows with ASR-overlap confidence and QC.
|
|
202
|
+
|
|
203
|
+
Coarse grid ASR (large synthetic windows from chunking) must not turn every quiet
|
|
204
|
+
window into speech. The return value is (annotated_periods, qc). Inputs are copied.
|
|
205
|
+
"""
|
|
206
|
+
out = [dict(p) for p in (periods or []) if isinstance(p, dict)]
|
|
207
|
+
qc = {"coarse_asr_windows": 0, "low_confidence_speech_flags": 0, "asr_granularity": "none"}
|
|
208
|
+
for qp in out:
|
|
209
|
+
qp.setdefault("speech_overlap_ratio", 0.0)
|
|
210
|
+
qp.setdefault("asr_overlap_seconds", 0.0)
|
|
211
|
+
qp.setdefault("asr_granularity", "none")
|
|
212
|
+
qp.setdefault("has_speech", False)
|
|
213
|
+
qp.setdefault("has_speech_reason", "no_asr_overlap")
|
|
214
|
+
if not asr_result:
|
|
215
|
+
return out, qc
|
|
216
|
+
|
|
217
|
+
valid_segments = []
|
|
218
|
+
for seg in asr_result:
|
|
219
|
+
if not isinstance(seg, dict):
|
|
220
|
+
continue
|
|
221
|
+
try:
|
|
222
|
+
ss, se = float(seg.get("start", 0)), float(seg.get("end", 0))
|
|
223
|
+
except (TypeError, ValueError):
|
|
224
|
+
continue
|
|
225
|
+
if se > ss:
|
|
226
|
+
valid_segments.append((ss, se))
|
|
227
|
+
asr_coverage = sum(se - ss for ss, se in valid_segments)
|
|
228
|
+
avg_seg_dur = asr_coverage / len(valid_segments) if valid_segments else 0
|
|
229
|
+
if video_duration is None:
|
|
230
|
+
ends = [float(p.get("end", 0) or 0) for p in out] + [se for _, se in valid_segments]
|
|
231
|
+
video_duration = max(ends or [0.0])
|
|
232
|
+
configured = float(configured_segment_seconds if configured_segment_seconds is not None else (CONFIG.get("asr_segment_seconds", 30) or 30))
|
|
233
|
+
coarse_asr = (
|
|
234
|
+
(len(valid_segments) <= 5 and asr_coverage > float(video_duration) * 0.8) or
|
|
235
|
+
asr_coverage > float(video_duration) * 1.5 or
|
|
236
|
+
avg_seg_dur > max(45.0, configured * 1.5) or
|
|
237
|
+
(avg_seg_dur >= configured * 0.9 and asr_coverage > float(video_duration) * 0.7)
|
|
238
|
+
)
|
|
239
|
+
granularity = "coarse_grid" if coarse_asr else "segment"
|
|
240
|
+
qc["asr_granularity"] = granularity
|
|
241
|
+
qc["avg_asr_segment_seconds"] = round(avg_seg_dur, 3)
|
|
242
|
+
for qp in out:
|
|
243
|
+
overlap_seconds = 0.0
|
|
244
|
+
for ss, se in valid_segments:
|
|
245
|
+
overlap_seconds += max(0.0, min(float(qp["end"]), se) - max(float(qp["start"]), ss))
|
|
246
|
+
ratio = overlap_seconds / max(0.001, float(qp.get("duration", 0.0) or 0.0))
|
|
247
|
+
qp["asr_overlap_seconds"] = round(overlap_seconds, 3)
|
|
248
|
+
qp["speech_overlap_ratio"] = round(ratio, 4)
|
|
249
|
+
qp["asr_granularity"] = granularity
|
|
250
|
+
if coarse_asr:
|
|
251
|
+
qp["has_speech"] = False
|
|
252
|
+
qp["has_speech_reason"] = "coarse_asr_overlap_ignored" if overlap_seconds > 0 else "coarse_asr_no_overlap"
|
|
253
|
+
if overlap_seconds > 0:
|
|
254
|
+
qc["coarse_asr_windows"] += 1
|
|
255
|
+
continue
|
|
256
|
+
if ratio >= 0.3:
|
|
257
|
+
qp["has_speech"] = True
|
|
258
|
+
qp["has_speech_reason"] = "asr_overlap_high_confidence"
|
|
259
|
+
elif overlap_seconds > 0:
|
|
260
|
+
qp["has_speech"] = False
|
|
261
|
+
qp["has_speech_reason"] = "asr_overlap_low_confidence_quiet"
|
|
262
|
+
qc["low_confidence_speech_flags"] += 1
|
|
263
|
+
else:
|
|
264
|
+
qp["has_speech"] = False
|
|
265
|
+
qp["has_speech_reason"] = "no_asr_overlap"
|
|
266
|
+
return out, qc
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
def detect_silence_periods(video_path, work_dir, asr_result=None):
|
|
270
|
+
"""用 ffmpeg silencedetect 检测安静时段,作为解说插入的候选窗口"""
|
|
271
|
+
audio_path = work_dir / "audio.wav"
|
|
272
|
+
if not _audio_cache_matches(audio_path, video_path):
|
|
273
|
+
if audio_path.exists():
|
|
274
|
+
audio_path.unlink()
|
|
275
|
+
# 提取到临时文件,成功后原子移动到位,避免被中断的 -y 运行留下半截 audio.wav
|
|
276
|
+
tmp_path = work_dir / "audio.wav.tmp"
|
|
277
|
+
extract = run_cmd([
|
|
278
|
+
"ffmpeg", "-y", "-i", str(video_path),
|
|
279
|
+
"-vn", "-ar", "16000", "-ac", "1",
|
|
280
|
+
"-f", "wav", str(tmp_path) # .tmp extension hides the format from ffmpeg; state it
|
|
281
|
+
])
|
|
282
|
+
if extract.returncode != 0 or not tmp_path.exists():
|
|
283
|
+
log(
|
|
284
|
+
"音频提取失败,无法检测静音窗口(视频可能无音轨): "
|
|
285
|
+
f"{_compact_ffmpeg_error(extract.stderr)}"
|
|
286
|
+
)
|
|
287
|
+
if tmp_path.exists():
|
|
288
|
+
tmp_path.unlink()
|
|
289
|
+
return []
|
|
290
|
+
os.replace(str(tmp_path), str(audio_path))
|
|
291
|
+
_write_audio_meta(work_dir, video_path)
|
|
292
|
+
|
|
293
|
+
# Sentence-entry anchors use short acoustic pauses aligned to terminal ASR punctuation.
|
|
294
|
+
# They are deliberately separate from silence_periods.json: a 200ms sentence pause is a
|
|
295
|
+
# safe place to ENTER narration, but not a multi-second quiet window that can own a block.
|
|
296
|
+
detect_speech_boundary_anchors(work_dir, asr_result or [])
|
|
297
|
+
|
|
298
|
+
noise = CONFIG["silence_noise_threshold"]
|
|
299
|
+
min_dur = CONFIG["silence_min_duration"]
|
|
300
|
+
cmd = ["ffmpeg", "-i", str(audio_path),
|
|
301
|
+
"-af", f"silencedetect=noise={noise}:d={min_dur}",
|
|
302
|
+
"-f", "null", "-"]
|
|
303
|
+
# Everything else in this function degrades to `return []` (narration then falls back to
|
|
304
|
+
# non-quiet placement). A timeout must degrade the same way instead of raising
|
|
305
|
+
# TimeoutExpired through the whole understanding stage. Scale the budget with the audio
|
|
306
|
+
# so a long feature is not cut off by a constant tuned for short clips — estimated from
|
|
307
|
+
# the file size (this is the 16 kHz mono s16 WAV we just wrote), not from another probe.
|
|
308
|
+
timeout = max(120.0, _wav_seconds_estimate(audio_path) * 0.5)
|
|
309
|
+
try:
|
|
310
|
+
result = run_cmd(cmd, timeout=timeout)
|
|
311
|
+
except subprocess.TimeoutExpired:
|
|
312
|
+
log(f"静音检测超时(>{timeout:.0f}s),跳过安静窗口检测")
|
|
313
|
+
return []
|
|
314
|
+
if result.returncode != 0:
|
|
315
|
+
log(f"静音检测失败: {_compact_ffmpeg_error(result.stderr)}")
|
|
316
|
+
return []
|
|
317
|
+
output = result.stderr
|
|
318
|
+
|
|
319
|
+
# 解析 silence_start / silence_end
|
|
320
|
+
starts = [float(m) for m in re.findall(r'silence_start:\s*([\d.]+)', output)]
|
|
321
|
+
ends = [float(m) for m in re.findall(r'silence_end:\s*([\d.]+)', output)]
|
|
322
|
+
|
|
323
|
+
# 配对所有静音段(不过滤时长,后面合并后再过滤)
|
|
324
|
+
raw_periods = []
|
|
325
|
+
for s, e in zip(starts, ends):
|
|
326
|
+
raw_periods.append({"start": round(s, 2), "end": round(e, 2),
|
|
327
|
+
"duration": round(e - s, 2)})
|
|
328
|
+
# 末尾静音
|
|
329
|
+
if len(starts) > len(ends):
|
|
330
|
+
dur_start = starts[len(ends)]
|
|
331
|
+
total_dur = get_video_duration(str(audio_path))
|
|
332
|
+
raw_periods.append({"start": round(dur_start, 2), "end": round(total_dur, 2),
|
|
333
|
+
"duration": round(total_dur - dur_start, 2)})
|
|
334
|
+
|
|
335
|
+
# 合并相邻静音段(间隔 < merge_gap 的合并为一个大窗口)
|
|
336
|
+
merge_gap = CONFIG.get("silence_merge_gap", 0.5)
|
|
337
|
+
merged = []
|
|
338
|
+
for rp in sorted(raw_periods, key=lambda x: x["start"]):
|
|
339
|
+
if merged and rp["start"] - merged[-1]["end"] < merge_gap:
|
|
340
|
+
merged[-1]["end"] = rp["end"]
|
|
341
|
+
merged[-1]["duration"] = round(merged[-1]["end"] - merged[-1]["start"], 2)
|
|
342
|
+
else:
|
|
343
|
+
merged.append({"start": rp["start"], "end": rp["end"],
|
|
344
|
+
"duration": rp["duration"], "has_speech": False})
|
|
345
|
+
|
|
346
|
+
# 过滤最短时长
|
|
347
|
+
quiet_min = CONFIG["quiet_window_min"]
|
|
348
|
+
periods = [p for p in merged if p["duration"] >= quiet_min]
|
|
349
|
+
|
|
350
|
+
# 与 ASR 交叉验证:标记有语音的窗口,并记录可观测 confidence/reason。
|
|
351
|
+
periods, qc = annotate_quiet_windows_with_asr(
|
|
352
|
+
periods,
|
|
353
|
+
asr_result,
|
|
354
|
+
video_duration=get_video_duration(str(audio_path)) if asr_result else None,
|
|
355
|
+
configured_segment_seconds=CONFIG.get("asr_segment_seconds", 30),
|
|
356
|
+
)
|
|
357
|
+
|
|
358
|
+
(work_dir / "silence_periods.qc.json").write_text(
|
|
359
|
+
json.dumps(qc, ensure_ascii=False, indent=2), encoding="utf-8")
|
|
360
|
+
|
|
361
|
+
# 保存
|
|
362
|
+
(work_dir / "silence_periods.json").write_text(
|
|
363
|
+
json.dumps(periods, ensure_ascii=False, indent=2), encoding="utf-8")
|
|
364
|
+
log(f"检测到 {len(periods)} 个安静窗口 (≥{quiet_min}s)")
|
|
365
|
+
for qp in periods:
|
|
366
|
+
flag = " [有语音]" if qp["has_speech"] else ""
|
|
367
|
+
log(f" {qp['start']:.1f}s-{qp['end']:.1f}s ({qp['duration']:.1f}s){flag}")
|
|
368
|
+
return periods
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
def _asr_segments(asr_result):
|
|
372
|
+
if isinstance(asr_result, dict):
|
|
373
|
+
asr_result = asr_result.get("segments", [])
|
|
374
|
+
return [item for item in (asr_result or []) if isinstance(item, dict)]
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
def detect_speech_boundary_anchors(work_dir, asr_result):
|
|
378
|
+
"""Write sentence-end entry anchors by aligning ASR punctuation to short pauses.
|
|
379
|
+
|
|
380
|
+
MiMo ASR timestamps are window-level, not word-level. We therefore estimate each terminal
|
|
381
|
+
punctuation time from its character position inside the ASR window, then snap it to the
|
|
382
|
+
closest short acoustic pause. The output is guidance + a deterministic pre-TTS gate; it
|
|
383
|
+
never rewrites narration timing on its own.
|
|
384
|
+
"""
|
|
385
|
+
work_dir = Path(work_dir)
|
|
386
|
+
audio_path = work_dir / "audio.wav"
|
|
387
|
+
out_path = work_dir / "speech_boundary_anchors.json"
|
|
388
|
+
segments = _asr_segments(asr_result)
|
|
389
|
+
report = {
|
|
390
|
+
"schema_version": 1,
|
|
391
|
+
"artifact": "speech_boundary_anchors.json",
|
|
392
|
+
"status": "completed",
|
|
393
|
+
"detector": {
|
|
394
|
+
"noise_threshold": CONFIG.get("source_boundary_noise_threshold", "-18dB"),
|
|
395
|
+
"min_pause_seconds": float(CONFIG.get("source_boundary_min_pause", 0.12)),
|
|
396
|
+
"alignment": "terminal_punctuation_to_nearest_acoustic_pause",
|
|
397
|
+
},
|
|
398
|
+
"sentence_anchors": [],
|
|
399
|
+
"acoustic_pauses": [],
|
|
400
|
+
}
|
|
401
|
+
if not audio_path.exists() or not segments:
|
|
402
|
+
report["status"] = "unavailable"
|
|
403
|
+
report["reason"] = "missing_audio_or_asr"
|
|
404
|
+
out_path.write_text(json.dumps(report, ensure_ascii=False, indent=2), encoding="utf-8")
|
|
405
|
+
return report
|
|
406
|
+
|
|
407
|
+
result = run_cmd([
|
|
408
|
+
"ffmpeg", "-hide_banner", "-nostats", "-i", str(audio_path),
|
|
409
|
+
"-af", (
|
|
410
|
+
"silencedetect="
|
|
411
|
+
f"noise={CONFIG.get('source_boundary_noise_threshold', '-18dB')}:"
|
|
412
|
+
f"d={float(CONFIG.get('source_boundary_min_pause', 0.12))}"
|
|
413
|
+
),
|
|
414
|
+
"-f", "null", "-",
|
|
415
|
+
], timeout=120)
|
|
416
|
+
if result.returncode != 0:
|
|
417
|
+
report["status"] = "failed"
|
|
418
|
+
report["reason"] = "silencedetect_failed"
|
|
419
|
+
out_path.write_text(json.dumps(report, ensure_ascii=False, indent=2), encoding="utf-8")
|
|
420
|
+
return report
|
|
421
|
+
|
|
422
|
+
starts = [float(value) for value in re.findall(r"silence_start:\s*([\d.]+)", result.stderr or "")]
|
|
423
|
+
ends = [float(value) for value in re.findall(r"silence_end:\s*([\d.]+)", result.stderr or "")]
|
|
424
|
+
pauses = []
|
|
425
|
+
for index, (start, end) in enumerate(zip(starts, ends)):
|
|
426
|
+
if end <= start:
|
|
427
|
+
continue
|
|
428
|
+
pauses.append({
|
|
429
|
+
"index": index,
|
|
430
|
+
"start": round(start, 3),
|
|
431
|
+
"end": round(end, 3),
|
|
432
|
+
"midpoint": round((start + end) / 2.0, 3),
|
|
433
|
+
"duration": round(end - start, 3),
|
|
434
|
+
})
|
|
435
|
+
report["acoustic_pauses"] = pauses
|
|
436
|
+
|
|
437
|
+
max_error = float(CONFIG.get("source_boundary_max_alignment_error", 2.1))
|
|
438
|
+
used = set()
|
|
439
|
+
anchors = []
|
|
440
|
+
for asr_index, segment in enumerate(segments):
|
|
441
|
+
try:
|
|
442
|
+
seg_start = float(segment.get("start"))
|
|
443
|
+
seg_end = float(segment.get("end"))
|
|
444
|
+
except (TypeError, ValueError):
|
|
445
|
+
continue
|
|
446
|
+
text = str(segment.get("text") or "").strip()
|
|
447
|
+
if seg_end <= seg_start or not text:
|
|
448
|
+
continue
|
|
449
|
+
last_midpoint = seg_start - 1e-6
|
|
450
|
+
for match in re.finditer(r"[。!?!?;;]", text):
|
|
451
|
+
expected = seg_start + (seg_end - seg_start) * (match.end() / max(1, len(text)))
|
|
452
|
+
candidates = [
|
|
453
|
+
pause for pause in pauses
|
|
454
|
+
if pause["index"] not in used
|
|
455
|
+
and seg_start - 0.3 <= pause["midpoint"] <= seg_end + 0.3
|
|
456
|
+
and pause["midpoint"] > last_midpoint
|
|
457
|
+
and abs(pause["midpoint"] - expected) <= max_error
|
|
458
|
+
]
|
|
459
|
+
if not candidates:
|
|
460
|
+
continue
|
|
461
|
+
pause = min(candidates, key=lambda item: abs(item["midpoint"] - expected))
|
|
462
|
+
used.add(pause["index"])
|
|
463
|
+
last_midpoint = pause["midpoint"]
|
|
464
|
+
error = abs(pause["midpoint"] - expected)
|
|
465
|
+
confidence = "high" if error <= 0.6 else ("medium" if error <= 1.2 else "low")
|
|
466
|
+
anchors.append({
|
|
467
|
+
"time": pause["end"],
|
|
468
|
+
"pause_start": pause["start"],
|
|
469
|
+
"pause_end": pause["end"],
|
|
470
|
+
"expected_time": round(expected, 3),
|
|
471
|
+
"alignment_error": round(error, 3),
|
|
472
|
+
"confidence": confidence,
|
|
473
|
+
"punctuation": match.group(0),
|
|
474
|
+
"text_tail": text[max(0, match.end() - 32):match.end()],
|
|
475
|
+
"asr_segment_index": asr_index,
|
|
476
|
+
})
|
|
477
|
+
report["sentence_anchors"] = sorted(anchors, key=lambda item: item["time"])
|
|
478
|
+
out_path.write_text(json.dumps(report, ensure_ascii=False, indent=2), encoding="utf-8")
|
|
479
|
+
log(f"检测到 {len(anchors)} 个原声句末安全切入点")
|
|
480
|
+
return report
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
def _audio_meta_path(work_dir):
|
|
484
|
+
return Path(work_dir) / "audio.wav.meta.json"
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
def _audio_cache_matches(audio_path, video_path):
|
|
488
|
+
audio_path = Path(audio_path)
|
|
489
|
+
if not audio_path.exists():
|
|
490
|
+
return False
|
|
491
|
+
meta_path = _audio_meta_path(audio_path.parent)
|
|
492
|
+
if not meta_path.exists():
|
|
493
|
+
return False
|
|
494
|
+
try:
|
|
495
|
+
meta = json.loads(meta_path.read_text(encoding="utf-8"))
|
|
496
|
+
except (OSError, ValueError, TypeError):
|
|
497
|
+
return False
|
|
498
|
+
try:
|
|
499
|
+
expected = file_fingerprint(video_path)
|
|
500
|
+
except OSError:
|
|
501
|
+
return False
|
|
502
|
+
return meta.get("source_video_fingerprint") == expected
|
|
503
|
+
|
|
504
|
+
|
|
505
|
+
def _write_audio_meta(work_dir, video_path):
|
|
506
|
+
_audio_meta_path(work_dir).write_text(
|
|
507
|
+
json.dumps({
|
|
508
|
+
"schema_version": 1,
|
|
509
|
+
"source_video_fingerprint": file_fingerprint(video_path),
|
|
510
|
+
"audio": "audio.wav",
|
|
511
|
+
}, ensure_ascii=False, indent=2),
|
|
512
|
+
encoding="utf-8",
|
|
513
|
+
)
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
from lib import CONFIG
|
|
2
|
+
from lib import log, run_cmd
|
|
3
|
+
|
|
4
|
+
# ── Step 1: 帧提取 ───────────────────────────────────────────────────
|
|
5
|
+
|
|
6
|
+
# ffmpeg 的 `fps` 滤镜从源时间 0 开始输出第一帧,而 image2 muxer 的 `-start_number`
|
|
7
|
+
# 默认是 1。所以 frame_00001.jpg 对应 t=0,第 n 号帧对应 (n-1)/fps —— 不是 n/fps。
|
|
8
|
+
# 这个 off-by-one 会把所有画面锚点(frame_facts、场景归属、storyboard 标签)整体推后
|
|
9
|
+
# 1/fps 秒(长视频默认 fps=1,即整整 1 秒)。这里是该约定的唯一定义处。
|
|
10
|
+
FRAME_START_NUMBER = 1
|
|
11
|
+
|
|
12
|
+
# 帧编号↔时间的换算规则变更时递增;进入各阶段缓存 key,强制重算旧产物。
|
|
13
|
+
FRAME_TIME_CONVENTION_VERSION = 2
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def frame_time(frame_number, fps):
|
|
17
|
+
"""帧文件序号 → 源视频时间(秒)。frame_00001 → 0.0。"""
|
|
18
|
+
fps = float(fps)
|
|
19
|
+
if fps <= 0:
|
|
20
|
+
raise ValueError("fps 必须大于 0")
|
|
21
|
+
return (int(frame_number) - FRAME_START_NUMBER) / fps
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def frame_number_for_time(timestamp, fps):
|
|
25
|
+
"""源视频时间(秒)→ 对应的帧文件序号(可能是小数,供最近邻查找用)。"""
|
|
26
|
+
fps = float(fps)
|
|
27
|
+
if fps <= 0:
|
|
28
|
+
raise ValueError("fps 必须大于 0")
|
|
29
|
+
return float(timestamp) * fps + FRAME_START_NUMBER
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def parse_frame_number(frame_path):
|
|
33
|
+
"""从 frame_NNNNN.jpg 解析序号;命名不符合约定时返回 None。"""
|
|
34
|
+
parts = frame_path.stem.split("_")
|
|
35
|
+
if len(parts) != 2 or not parts[1].isdigit():
|
|
36
|
+
return None
|
|
37
|
+
return int(parts[1])
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def extract_frames(video_path, work_dir, fps=None):
|
|
41
|
+
"""提取视频帧"""
|
|
42
|
+
fps = CONFIG["fps"] if fps is None else fps
|
|
43
|
+
if fps <= 0:
|
|
44
|
+
raise ValueError("fps 必须大于 0;完整 pipeline 会自动计算 fps")
|
|
45
|
+
frames_dir = work_dir / "frames"
|
|
46
|
+
frames_dir.mkdir(exist_ok=True)
|
|
47
|
+
|
|
48
|
+
# 清理上一次(可能更高 fps)残留的帧,避免陈旧帧泄漏进本次结果
|
|
49
|
+
for stale in frames_dir.glob("frame_*.jpg"):
|
|
50
|
+
stale.unlink()
|
|
51
|
+
|
|
52
|
+
output_pattern = str(frames_dir / "frame_%05d.jpg")
|
|
53
|
+
cmd = ["ffmpeg", "-y", "-i", str(video_path),
|
|
54
|
+
"-vf", f"fps={fps}", "-q:v", "2",
|
|
55
|
+
"-start_number", str(FRAME_START_NUMBER), output_pattern]
|
|
56
|
+
result = run_cmd(cmd)
|
|
57
|
+
if result.returncode != 0:
|
|
58
|
+
raise RuntimeError(f"帧提取失败: {result.stderr}")
|
|
59
|
+
|
|
60
|
+
frames = sorted(frames_dir.glob("frame_*.jpg"))
|
|
61
|
+
log(f"提取了 {len(frames)} 帧 ({fps}fps)")
|
|
62
|
+
return frames
|