dsh-chat-comprehension 0.2.0 → 0.3.1
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/NOTICE.md +20 -0
- package/README.md +20 -9
- package/client.js +41 -9
- package/lib/engines.mjs +136 -0
- package/lib/index.js +54 -4
- package/lib/qqbot-0.5.3-patches.json +75 -70
- package/lib/qqbot-patch.mjs +12 -7
- package/lib/video.mjs +11 -2
- package/package.json +7 -23
- package/vendor/dsh-agent-md/LICENSE +21 -0
- package/vendor/dsh-agent-md/cordis.patch.yml +8 -0
- package/vendor/dsh-agent-md/lib/index.js +775 -0
- package/vendor/dsh-agent-md/lib/persona.js +634 -0
- package/vendor/dsh-agent-md/lib/qq.js +527 -0
- package/vendor/dsh-agent-md/package.json +50 -0
- package/vendor/dsh-bili-scroll/LICENSE +21 -0
- package/vendor/dsh-bili-scroll/NOTICE.md +18 -0
- package/vendor/dsh-bili-scroll/cordis.patch.yml +20 -0
- package/vendor/dsh-bili-scroll/index.js +3293 -0
- package/vendor/dsh-bili-scroll/lib/asr.py +141 -0
- package/vendor/dsh-bili-scroll/lib/diagnose.mjs +95 -0
- package/vendor/dsh-bili-scroll/lib/dm.mjs +110 -0
- package/vendor/dsh-bili-scroll/lib/favops.py +90 -0
- package/vendor/dsh-bili-scroll/lib/hostdeps.mjs +148 -0
- package/vendor/dsh-bili-scroll/lib/login.mjs +141 -0
- package/vendor/dsh-bili-scroll/lib/mcp.mjs +144 -0
- package/vendor/dsh-bili-scroll/lib/state.mjs +236 -0
- package/vendor/dsh-bili-scroll/lib/uid.mjs +61 -0
- package/vendor/dsh-bili-scroll/lib/uvfetch.mjs +217 -0
- package/vendor/dsh-bili-scroll/lib/verify.mjs +184 -0
- package/vendor/dsh-bili-scroll/package.json +84 -0
- package/vendor/dsh-bili-scroll/profile-template/bili-duty/cordis.patch.yml +116 -0
- package/vendor/dsh-bili-scroll/profile-template/bili-duty/cordis.yml +4 -0
- package/vendor/dsh-bili-scroll/profile-template/bili-duty/package.json +13 -0
- package/vendor/dsh-bili-scroll/prompts/duty.md +296 -0
- package/vendor/dsh-bili-scroll/vendor/bilibili-mcp/LICENSE +21 -0
- package/vendor/dsh-bili-scroll/vendor/bilibili-mcp/README.md +176 -0
- package/vendor/dsh-bili-scroll/vendor/bilibili-mcp/mcp_server.py +2015 -0
- package/vendor/dsh-bili-scroll/vendor/bilibili-mcp/requirements.txt +10 -0
- package/vendor/dsh-meme/.dsh/skills/dsh-meme-maintenance/SKILL.md +50 -0
- package/vendor/dsh-meme/LICENSE +21 -0
- package/vendor/dsh-meme/anim.js +588 -0
- package/vendor/dsh-meme/cordis.patch.yml +13 -0
- package/vendor/dsh-meme/icon.jpg +0 -0
- package/vendor/dsh-meme/index.js +2616 -0
- package/vendor/dsh-meme/locale/en.json +6 -0
- package/vendor/dsh-meme/locale/zh.json +6 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/index.db +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/manifest.json +13 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/angry/shengqi.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/baka/xianqi.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/color/huachi.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/confused/jiazai.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/confused/wenhao.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/cpu/jiaban.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/daily/ganfan.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/fool/buyao.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/givemoney/yaoqian.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/happy/deyi.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/happy/ok.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/happy/piaole.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/like/bixin.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/meow/maozhua.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/morning/zaoshanghao.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/sad/qiurao.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/sad/yun.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/see/zhenjing.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/shy/haixiu.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/shy/toukan.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/sigh/wuyu.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/sleep/shuijiao.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/surprised/xia.jpg +0 -0
- package/vendor/dsh-meme/memes/dafeiyu-001/memes/work/tangping.jpg +0 -0
- package/vendor/dsh-meme/memes.js +998 -0
- package/vendor/dsh-meme/package.json +67 -0
- package/vendor/dsh-meme/panel.html +210 -0
- package/vendor/dsh-video-storyboard/LICENSE +21 -0
- package/vendor/dsh-video-storyboard/NOTICE +12 -0
- package/vendor/dsh-video-storyboard/bin/_args.mjs +16 -0
- package/vendor/dsh-video-storyboard/bin/asr-check.mjs +85 -0
- package/vendor/dsh-video-storyboard/bin/scan-stats.mjs +43 -0
- package/vendor/dsh-video-storyboard/bin/scan-video.mjs +38 -0
- package/vendor/dsh-video-storyboard/bin/storyboard.mjs +195 -0
- package/vendor/dsh-video-storyboard/cordis.patch.yml +3 -0
- package/vendor/dsh-video-storyboard/dsh.plugin.json +12 -0
- package/vendor/dsh-video-storyboard/package.json +88 -0
- package/vendor/dsh-video-storyboard/scripts/check-syntax.mjs +56 -0
- package/vendor/dsh-video-storyboard/scripts/install-dev.mjs +104 -0
- package/vendor/dsh-video-storyboard/src/flicker.js +104 -0
- package/vendor/dsh-video-storyboard/src/index.js +82 -0
- package/vendor/dsh-video-storyboard/src/ocr_bridge.py +103 -0
- package/vendor/dsh-video-storyboard/src/storyboard/asr-lifecycle.js +262 -0
- package/vendor/dsh-video-storyboard/src/storyboard/asr.js +488 -0
- package/vendor/dsh-video-storyboard/src/storyboard/audio.js +168 -0
- package/vendor/dsh-video-storyboard/src/storyboard/binaries.js +69 -0
- package/vendor/dsh-video-storyboard/src/storyboard/board.js +121 -0
- package/vendor/dsh-video-storyboard/src/storyboard/browser-time.js +504 -0
- package/vendor/dsh-video-storyboard/src/storyboard/cache.js +143 -0
- package/vendor/dsh-video-storyboard/src/storyboard/cells.js +70 -0
- package/vendor/dsh-video-storyboard/src/storyboard/density.js +545 -0
- package/vendor/dsh-video-storyboard/src/storyboard/direct-url.js +130 -0
- package/vendor/dsh-video-storyboard/src/storyboard/fetch.js +373 -0
- package/vendor/dsh-video-storyboard/src/storyboard/flash.js +180 -0
- package/vendor/dsh-video-storyboard/src/storyboard/format.js +573 -0
- package/vendor/dsh-video-storyboard/src/storyboard/frames.js +212 -0
- package/vendor/dsh-video-storyboard/src/storyboard/index.js +32 -0
- package/vendor/dsh-video-storyboard/src/storyboard/injection.js +76 -0
- package/vendor/dsh-video-storyboard/src/storyboard/layout-order.js +176 -0
- package/vendor/dsh-video-storyboard/src/storyboard/locate.js +113 -0
- package/vendor/dsh-video-storyboard/src/storyboard/media-store.js +106 -0
- package/vendor/dsh-video-storyboard/src/storyboard/memory.js +94 -0
- package/vendor/dsh-video-storyboard/src/storyboard/ocr-subs.js +107 -0
- package/vendor/dsh-video-storyboard/src/storyboard/ocr.js +167 -0
- package/vendor/dsh-video-storyboard/src/storyboard/pipeline.js +853 -0
- package/vendor/dsh-video-storyboard/src/storyboard/plan.js +400 -0
- package/vendor/dsh-video-storyboard/src/storyboard/probe.js +132 -0
- package/vendor/dsh-video-storyboard/src/storyboard/provenance.js +44 -0
- package/vendor/dsh-video-storyboard/src/storyboard/python.js +84 -0
- package/vendor/dsh-video-storyboard/src/storyboard/register.js +32 -0
- package/vendor/dsh-video-storyboard/src/storyboard/scan.js +486 -0
- package/vendor/dsh-video-storyboard/src/storyboard/segments.js +117 -0
- package/vendor/dsh-video-storyboard/src/storyboard/sheet.js +507 -0
- package/vendor/dsh-video-storyboard/src/storyboard/storage.js +93 -0
- package/vendor/dsh-video-storyboard/src/storyboard/subtitles.js +181 -0
- package/vendor/dsh-video-storyboard/src/storyboard/tool-spec.js +544 -0
- package/vendor/dsh-video-storyboard/src/storyboard/transcript-file.js +146 -0
- package/vendor/dsh-video-storyboard/src/storyboard/url.js +69 -0
- package/vendor/dsh-video-storyboard/src/storyboard/ytdlp.js +289 -0
- package/vendor/dsh-video-storyboard/src/tool-spec.js +17 -0
- package/vendor/dsh-video-storyboard/src/tools/locate.js +39 -0
- package/vendor/dsh-video-storyboard/src/tools/probe.js +23 -0
- package/vendor/dsh-video-storyboard/src/tools/shared.js +39 -0
- package/vendor/dsh-video-storyboard/src/tools/storyboard.js +20 -0
- package/vendor/dsh-video-storyboard/src/tools/zoom.js +56 -0
- package/vendor/dsh-world/LICENSE +21 -0
- package/vendor/dsh-world/assets/qq-card.png +0 -0
- package/vendor/dsh-world/cordis.patch.yml +6 -0
- package/vendor/dsh-world/lib/archive.d.ts +6 -0
- package/vendor/dsh-world/lib/archive.js +49 -0
- package/vendor/dsh-world/lib/archiveSelection.d.ts +8 -0
- package/vendor/dsh-world/lib/archiveSelection.js +20 -0
- package/vendor/dsh-world/lib/compaction.d.ts +124 -0
- package/vendor/dsh-world/lib/compaction.js +273 -0
- package/vendor/dsh-world/lib/compactionRegion.d.ts +42 -0
- package/vendor/dsh-world/lib/compactionRegion.js +210 -0
- package/vendor/dsh-world/lib/console/routes.d.ts +57 -0
- package/vendor/dsh-world/lib/console/routes.js +129 -0
- package/vendor/dsh-world/lib/console/snapshot.d.ts +39 -0
- package/vendor/dsh-world/lib/console/snapshot.js +51 -0
- package/vendor/dsh-world/lib/ecosystem/bridge/bridge.d.ts +36 -0
- package/vendor/dsh-world/lib/ecosystem/bridge/bridge.js +140 -0
- package/vendor/dsh-world/lib/ecosystem/bridge/route.d.ts +9 -0
- package/vendor/dsh-world/lib/ecosystem/bridge/route.js +46 -0
- package/vendor/dsh-world/lib/ecosystem/qq/bridge.d.ts +123 -0
- package/vendor/dsh-world/lib/ecosystem/qq/bridge.js +380 -0
- package/vendor/dsh-world/lib/ecosystem/qq/panel.d.ts +75 -0
- package/vendor/dsh-world/lib/ecosystem/qq/panel.js +187 -0
- package/vendor/dsh-world/lib/ecosystem/qq/route.d.ts +32 -0
- package/vendor/dsh-world/lib/ecosystem/qq/route.js +134 -0
- package/vendor/dsh-world/lib/ecosystem/qq/supervisor.d.ts +57 -0
- package/vendor/dsh-world/lib/ecosystem/qq/supervisor.js +188 -0
- package/vendor/dsh-world/lib/ecosystem/shared/context.d.ts +14 -0
- package/vendor/dsh-world/lib/ecosystem/shared/context.js +42 -0
- package/vendor/dsh-world/lib/ecosystem/shared/identity.d.ts +15 -0
- package/vendor/dsh-world/lib/ecosystem/shared/identity.js +36 -0
- package/vendor/dsh-world/lib/ecosystem/shared/outlets.d.ts +43 -0
- package/vendor/dsh-world/lib/ecosystem/shared/outlets.js +70 -0
- package/vendor/dsh-world/lib/ecosystem/shared/sessions.d.ts +16 -0
- package/vendor/dsh-world/lib/ecosystem/shared/sessions.js +52 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/archive.d.ts +24 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/archive.js +62 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/home.d.ts +21 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/home.js +111 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/images.d.ts +5 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/images.js +43 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/index.d.ts +41 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/index.js +166 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/messages.d.ts +24 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/messages.js +35 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/sending.d.ts +30 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/sending.js +216 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/supervisor.d.ts +39 -0
- package/vendor/dsh-world/lib/ecosystem/wechat/supervisor.js +138 -0
- package/vendor/dsh-world/lib/faults.d.ts +10 -0
- package/vendor/dsh-world/lib/faults.js +13 -0
- package/vendor/dsh-world/lib/history.d.ts +16 -0
- package/vendor/dsh-world/lib/history.js +80 -0
- package/vendor/dsh-world/lib/hostContract.d.ts +19 -0
- package/vendor/dsh-world/lib/hostContract.js +1 -0
- package/vendor/dsh-world/lib/http.d.ts +18 -0
- package/vendor/dsh-world/lib/http.js +39 -0
- package/vendor/dsh-world/lib/index.d.ts +108 -0
- package/vendor/dsh-world/lib/index.js +356 -0
- package/vendor/dsh-world/lib/life/activity.d.ts +14 -0
- package/vendor/dsh-world/lib/life/activity.js +58 -0
- package/vendor/dsh-world/lib/life/alarm.d.ts +39 -0
- package/vendor/dsh-world/lib/life/alarm.js +132 -0
- package/vendor/dsh-world/lib/life/alarmTimer.d.ts +22 -0
- package/vendor/dsh-world/lib/life/alarmTimer.js +49 -0
- package/vendor/dsh-world/lib/life/diary.d.ts +4 -0
- package/vendor/dsh-world/lib/life/diary.js +9 -0
- package/vendor/dsh-world/lib/life/earlyStop.d.ts +19 -0
- package/vendor/dsh-world/lib/life/earlyStop.js +25 -0
- package/vendor/dsh-world/lib/life/home.d.ts +34 -0
- package/vendor/dsh-world/lib/life/home.js +91 -0
- package/vendor/dsh-world/lib/life/host.d.ts +22 -0
- package/vendor/dsh-world/lib/life/host.js +24 -0
- package/vendor/dsh-world/lib/life/journal.d.ts +20 -0
- package/vendor/dsh-world/lib/life/journal.js +59 -0
- package/vendor/dsh-world/lib/life/lifeStore.d.ts +16 -0
- package/vendor/dsh-world/lib/life/lifeStore.js +105 -0
- package/vendor/dsh-world/lib/life/messages.d.ts +17 -0
- package/vendor/dsh-world/lib/life/messages.js +53 -0
- package/vendor/dsh-world/lib/life/notify.d.ts +15 -0
- package/vendor/dsh-world/lib/life/notify.js +40 -0
- package/vendor/dsh-world/lib/life/pricing.d.ts +4 -0
- package/vendor/dsh-world/lib/life/pricing.js +30 -0
- package/vendor/dsh-world/lib/life/runtime.d.ts +52 -0
- package/vendor/dsh-world/lib/life/runtime.js +376 -0
- package/vendor/dsh-world/lib/life/toolRegistry.d.ts +22 -0
- package/vendor/dsh-world/lib/life/toolRegistry.js +64 -0
- package/vendor/dsh-world/lib/life/tools.d.ts +24 -0
- package/vendor/dsh-world/lib/life/tools.js +47 -0
- package/vendor/dsh-world/lib/life/types.d.ts +67 -0
- package/vendor/dsh-world/lib/life/types.js +1 -0
- package/vendor/dsh-world/lib/persona.d.ts +10 -0
- package/vendor/dsh-world/lib/persona.js +29 -0
- package/vendor/dsh-world/lib/promptSection.d.ts +30 -0
- package/vendor/dsh-world/lib/promptSection.js +81 -0
- package/vendor/dsh-world/lib/qqScope.d.ts +11 -0
- package/vendor/dsh-world/lib/qqScope.js +39 -0
- package/vendor/dsh-world/lib/runtime.d.ts +23 -0
- package/vendor/dsh-world/lib/runtime.js +206 -0
- package/vendor/dsh-world/lib/self.d.ts +10 -0
- package/vendor/dsh-world/lib/self.js +36 -0
- package/vendor/dsh-world/lib/sourceArchive.d.ts +28 -0
- package/vendor/dsh-world/lib/sourceArchive.js +156 -0
- package/vendor/dsh-world/lib/store.d.ts +30 -0
- package/vendor/dsh-world/lib/store.js +191 -0
- package/vendor/dsh-world/lib/timeContext.d.ts +3 -0
- package/vendor/dsh-world/lib/timeContext.js +13 -0
- package/vendor/dsh-world/lib/types.d.ts +118 -0
- package/vendor/dsh-world/lib/types.js +1 -0
- package/vendor/dsh-world/lib/worldPrompt.d.ts +47 -0
- package/vendor/dsh-world/lib/worldPrompt.js +49 -0
- package/vendor/dsh-world/lib/worldSwitch.d.ts +44 -0
- package/vendor/dsh-world/lib/worldSwitch.js +78 -0
- package/vendor/dsh-world/package-lock.json +1088 -0
- package/vendor/dsh-world/package.json +88 -0
- package/vendor/dsh-world/scripts/enable-tool-free-compaction.ps1 +33 -0
- package/vendor/dsh-world/src/archive.ts +45 -0
- package/vendor/dsh-world/src/archiveSelection.ts +27 -0
- package/vendor/dsh-world/src/compaction.ts +260 -0
- package/vendor/dsh-world/src/compactionRegion.ts +172 -0
- package/vendor/dsh-world/src/console/routes.ts +125 -0
- package/vendor/dsh-world/src/console/snapshot.ts +84 -0
- package/vendor/dsh-world/src/ecosystem/README.md +14 -0
- package/vendor/dsh-world/src/ecosystem/bridge/bridge.ts +121 -0
- package/vendor/dsh-world/src/ecosystem/bridge/route.ts +35 -0
- package/vendor/dsh-world/src/ecosystem/qq/bridge.ts +456 -0
- package/vendor/dsh-world/src/ecosystem/qq/panel.ts +178 -0
- package/vendor/dsh-world/src/ecosystem/qq/route.ts +130 -0
- package/vendor/dsh-world/src/ecosystem/qq/supervisor.ts +262 -0
- package/vendor/dsh-world/src/ecosystem/shared/context.ts +38 -0
- package/vendor/dsh-world/src/ecosystem/shared/identity.ts +42 -0
- package/vendor/dsh-world/src/ecosystem/shared/outlets.ts +75 -0
- package/vendor/dsh-world/src/ecosystem/shared/sessions.ts +47 -0
- package/vendor/dsh-world/src/ecosystem/wechat/archive.ts +66 -0
- package/vendor/dsh-world/src/ecosystem/wechat/home.ts +94 -0
- package/vendor/dsh-world/src/ecosystem/wechat/images.ts +38 -0
- package/vendor/dsh-world/src/ecosystem/wechat/index.ts +101 -0
- package/vendor/dsh-world/src/ecosystem/wechat/messages.ts +43 -0
- package/vendor/dsh-world/src/ecosystem/wechat/sending.ts +177 -0
- package/vendor/dsh-world/src/ecosystem/wechat/supervisor.ts +116 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/README.md +117 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/adapter.py +572 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/binding.py +52 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/engine/LICENSE +43 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/engine/NOTICE.md +10 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/engine/bridge.cpp +229 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/engine/build.ps1 +19 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/engine/profile.json +28 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/groups.py +42 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/incoming.py +157 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/native.py +168 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/outgoing.py +95 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/requirements.txt +1 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/sender.py +157 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/snapshot.py +32 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/stickers.py +60 -0
- package/vendor/dsh-world/src/ecosystem/wechat/windows/wechat.ps1 +75 -0
- package/vendor/dsh-world/src/faults.ts +12 -0
- package/vendor/dsh-world/src/history.ts +77 -0
- package/vendor/dsh-world/src/hostContract.ts +9 -0
- package/vendor/dsh-world/src/http.ts +34 -0
- package/vendor/dsh-world/src/index.ts +286 -0
- package/vendor/dsh-world/src/life/activity.ts +48 -0
- package/vendor/dsh-world/src/life/alarm.ts +119 -0
- package/vendor/dsh-world/src/life/alarmTimer.ts +45 -0
- package/vendor/dsh-world/src/life/diary.ts +10 -0
- package/vendor/dsh-world/src/life/earlyStop.ts +27 -0
- package/vendor/dsh-world/src/life/home.ts +85 -0
- package/vendor/dsh-world/src/life/host.ts +50 -0
- package/vendor/dsh-world/src/life/journal.ts +44 -0
- package/vendor/dsh-world/src/life/lifeStore.ts +70 -0
- package/vendor/dsh-world/src/life/messages.ts +44 -0
- package/vendor/dsh-world/src/life/notify.ts +47 -0
- package/vendor/dsh-world/src/life/pricing.ts +37 -0
- package/vendor/dsh-world/src/life/runtime.ts +318 -0
- package/vendor/dsh-world/src/life/toolRegistry.ts +48 -0
- package/vendor/dsh-world/src/life/tools.ts +61 -0
- package/vendor/dsh-world/src/life/types.ts +19 -0
- package/vendor/dsh-world/src/persona.ts +26 -0
- package/vendor/dsh-world/src/promptSection.ts +71 -0
- package/vendor/dsh-world/src/qqScope.ts +51 -0
- package/vendor/dsh-world/src/runtime.ts +172 -0
- package/vendor/dsh-world/src/self.ts +32 -0
- package/vendor/dsh-world/src/sourceArchive.ts +132 -0
- package/vendor/dsh-world/src/store.ts +170 -0
- package/vendor/dsh-world/src/timeContext.ts +13 -0
- package/vendor/dsh-world/src/types.ts +112 -0
- package/vendor/dsh-world/src/worldPrompt.ts +64 -0
- package/vendor/dsh-world/src/worldSwitch.ts +82 -0
- package/vendor/dsh-world/templates/alarm.md +49 -0
- package/vendor/dsh-world/templates/world-prompt.md +7 -0
- package/vendor/dsh-world/tests/archive.test.ts +57 -0
- package/vendor/dsh-world/tests/archiveScope.test.ts +86 -0
- package/vendor/dsh-world/tests/bridge.test.ts +211 -0
- package/vendor/dsh-world/tests/channelSessions.test.ts +79 -0
- package/vendor/dsh-world/tests/clientHooks.test.ts +103 -0
- package/vendor/dsh-world/tests/compaction.test.ts +141 -0
- package/vendor/dsh-world/tests/console.test.ts +202 -0
- package/vendor/dsh-world/tests/consoleClient.test.ts +101 -0
- package/vendor/dsh-world/tests/enableCompaction.test.ts +19 -0
- package/vendor/dsh-world/tests/fixtures.ts +6 -0
- package/vendor/dsh-world/tests/history.test.ts +100 -0
- package/vendor/dsh-world/tests/hostFixture.ts +46 -0
- package/vendor/dsh-world/tests/lifeActivity.test.ts +70 -0
- package/vendor/dsh-world/tests/lifeAlarm.test.ts +87 -0
- package/vendor/dsh-world/tests/lifeDiary.test.ts +33 -0
- package/vendor/dsh-world/tests/lifeMessages.test.ts +61 -0
- package/vendor/dsh-world/tests/lifeNotify.test.ts +46 -0
- package/vendor/dsh-world/tests/lifeParts.test.ts +45 -0
- package/vendor/dsh-world/tests/lifeRuntime.test.ts +660 -0
- package/vendor/dsh-world/tests/lifeStore.test.ts +90 -0
- package/vendor/dsh-world/tests/lifeTools.test.ts +53 -0
- package/vendor/dsh-world/tests/outlets.test.ts +85 -0
- package/vendor/dsh-world/tests/panel.test.ts +85 -0
- package/vendor/dsh-world/tests/plugin.test.ts +614 -0
- package/vendor/dsh-world/tests/pricing.test.ts +21 -0
- package/vendor/dsh-world/tests/qq.test.ts +121 -0
- package/vendor/dsh-world/tests/qqSessionMode.test.ts +97 -0
- package/vendor/dsh-world/tests/qqSupervisor.test.ts +149 -0
- package/vendor/dsh-world/tests/sourceArchive.test.ts +58 -0
- package/vendor/dsh-world/tests/store.test.ts +82 -0
- package/vendor/dsh-world/tests/storeWriter.ts +5 -0
- package/vendor/dsh-world/tests/timeContext.test.ts +15 -0
- package/vendor/dsh-world/tests/wechat.test.ts +254 -0
- package/vendor/dsh-world/tests/wechatImages.test.ts +130 -0
- package/vendor/dsh-world/tests/wechatSending.test.ts +142 -0
- package/vendor/dsh-world/tests/wechatSupervisor.test.ts +91 -0
- package/vendor/dsh-world/tests/worldPrompt.test.ts +201 -0
- package/vendor/dsh-world/tsconfig.build.json +5 -0
- package/vendor/dsh-world/tsconfig.json +8 -0
|
@@ -0,0 +1,853 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pipeline.js — 端到端**编排**:探测 → 切分 → 分段 → 取帧 → 拼图 → 清单。
|
|
3
|
+
*
|
|
4
|
+
* CLI(bin/storyboard.mjs)和 DSH 工具(index.js)都走这里,避免两份实现漂移。
|
|
5
|
+
* 本模块只返回内存里的 PNG buffer 与结构化清单,落盘由调用方决定。
|
|
6
|
+
*
|
|
7
|
+
* 本文件只留"一次运行是按什么顺序做什么"。三件事已经各自独立成模块:
|
|
8
|
+
* frames.js 取像素(本地/直链、单帧/摊格、并发)
|
|
9
|
+
* ocr-subs.js 用画面硬字幕校正转写
|
|
10
|
+
* format.js 把结果渲染成清单 / 时间线 / 证据文件
|
|
11
|
+
* scan.js 镜头切分(含爆点细扫 refineCutsByWindow)
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { cpus } from 'node:os';
|
|
15
|
+
|
|
16
|
+
import { probeVideo, DEFAULT_FFMPEG, DEFAULT_FFPROBE } from './probe.js';
|
|
17
|
+
import { resolveInput } from './fetch.js';
|
|
18
|
+
import { loadTranscriptFile } from './transcript-file.js';
|
|
19
|
+
import { detectDarkRuns, refineCutsByWindow, scanShots, spikeCuts, suppressClose } from './scan.js';
|
|
20
|
+
import { tagCuts } from './flash.js';
|
|
21
|
+
import { rememberSegments } from './locate.js';
|
|
22
|
+
import { ensureAsr, isOwned, keepAlive, scheduleStop } from './asr-lifecycle.js';
|
|
23
|
+
import { fitSegments, segmentsFromCuts } from './segments.js';
|
|
24
|
+
import { bestLayout, fillLayout, isMusicDriven, suggest, PLAN_THRESHOLDS } from './plan.js';
|
|
25
|
+
import {
|
|
26
|
+
densityFromScore, findBursts, integralMarks, planByRodt, planByShotCount, planCellRanges, planSheetsByFrames,
|
|
27
|
+
} from './density.js';
|
|
28
|
+
import { remember } from './memory.js';
|
|
29
|
+
import { analyzeAudio, describeAudio, detectOnsets } from './audio.js';
|
|
30
|
+
import {
|
|
31
|
+
ASR_DEFAULTS, alignCells, applyTermMap, canTranscribe, describeAsrTarget, explainFetchError,
|
|
32
|
+
extractSubtitleTrack, filterSuspectSegments, resolveAsrConfig, speechCurve, transcribeLong,
|
|
33
|
+
} from './asr.js';
|
|
34
|
+
import { fetchRemoteSubtitles } from './subtitles.js';
|
|
35
|
+
import { cacheKey, withCache } from './cache.js';
|
|
36
|
+
import { pruneStorage } from './storage.js';
|
|
37
|
+
import { saveCells } from './cells.js';
|
|
38
|
+
import { ffmpegVersion, sha256File } from './provenance.js';
|
|
39
|
+
import { findInjection } from './injection.js';
|
|
40
|
+
import { addAudioStrip, composeSheet, encodePngBuffer, layoutCanvas } from './sheet.js';
|
|
41
|
+
import { chooseSubGrid, extractFrameWithFallback, extractSubTile, mapPool } from './frames.js';
|
|
42
|
+
import { correctByOnScreenSubs } from './ocr-subs.js';
|
|
43
|
+
import { countTextInSilence } from './format.js';
|
|
44
|
+
|
|
45
|
+
export const PICK_MODES = ['sharp', 'mid', 'thumb'];// 只有两种:时间码不烧进画面 —— 它占像素、压缩后先糊,而清单里已经有 0.01 秒精度的时间。
|
|
46
|
+
// (历史上 `index+time` 在参数表里但从没实现过,等于一个会静默失效的选项。)
|
|
47
|
+
export const BURN_MODES = ['index', 'none'];
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @param {object} opts
|
|
51
|
+
* @param {string} opts.input 视频路径
|
|
52
|
+
* @param {number} [opts.from] 窗口起点(秒)
|
|
53
|
+
* @param {number} [opts.to] 窗口终点(秒)
|
|
54
|
+
* @param {number} [opts.cells] 每张格数(0=自动)
|
|
55
|
+
* @param {number} [opts.sheets] 张数(0=自动)
|
|
56
|
+
* @param {number|'auto'} [opts.threshold]
|
|
57
|
+
* @param {number} [opts.minGap] 采样最小间隔
|
|
58
|
+
* @param {'sharp'|'mid'|'thumb'} [opts.pick]
|
|
59
|
+
* @param {'index'|'none'} [opts.burn]
|
|
60
|
+
* @param {boolean} [opts.sourceHash] 在清单里写源文件 SHA-256(默认关;大文件要整读一遍)
|
|
61
|
+
* @param {number} [opts.badgeRatio]
|
|
62
|
+
* @param {number} [opts.budget] 单图像素预算
|
|
63
|
+
* @param {string} [opts.ffmpegPath]
|
|
64
|
+
* @param {string} [opts.ffprobePath]
|
|
65
|
+
* @param {(p:object)=>void} [opts.onProgress]
|
|
66
|
+
*/
|
|
67
|
+
export async function runStoryboard(opts) {
|
|
68
|
+
const {
|
|
69
|
+
input: inputRaw,
|
|
70
|
+
from = 0,
|
|
71
|
+
to,
|
|
72
|
+
threshold = 'auto',
|
|
73
|
+
minGap = 1.2,
|
|
74
|
+
// 扫描时的"两刀最短间隔"。和上面的 minGap(格子合并)不是一回事:
|
|
75
|
+
// 快闪素材要把这个调小才数得出镜头数,否则 3 秒 18 镜会被压成 4 刀。
|
|
76
|
+
scanGap = 0.35,
|
|
77
|
+
refineBursts = true,
|
|
78
|
+
// 取帧并发数:每路 ffmpeg 只解一帧,互不依赖。实测 9 格 90 秒片:
|
|
79
|
+
// 1 路 13.3s / 3 路 8.0s / 5 路 6.5s / 8 路 4.0s(这台 16 核)。
|
|
80
|
+
// 默认取核数一半、上限 8 —— 弱机或机械盘上不会把 IO 打死。
|
|
81
|
+
frameConcurrency = Math.min(8, Math.max(2, Math.floor(cpus().length / 2))),
|
|
82
|
+
adaptive = true,
|
|
83
|
+
pick = 'sharp',
|
|
84
|
+
burn = 'index',
|
|
85
|
+
transcript = 'auto',
|
|
86
|
+
transcriptFile,
|
|
87
|
+
sourceHash = false,
|
|
88
|
+
frameSource = null,
|
|
89
|
+
fetchOptions = null,
|
|
90
|
+
audioStrip = true,
|
|
91
|
+
asrMaxChunk = 45,
|
|
92
|
+
// 热词按**这一次**覆盖全局:材料视频该传「位错 滑移 柏氏矢量」,口播摄影片传「像差 焦段」。
|
|
93
|
+
// 全局 asr.json 里的那份是默认值,不是铁律 —— 学科不对时它对识别是负偏置。
|
|
94
|
+
hotwords,
|
|
95
|
+
// 用画面硬字幕校正 ASR(detail=high 时才开):OCR 全程本地,不花 token
|
|
96
|
+
ocr = false,
|
|
97
|
+
// undefined = 按 env / $DSH_HOME/asr.json 解析;显式 null = 明确不用 env/file 里的 key
|
|
98
|
+
// (云端因此变成 no-key;本机服务按设计不需要 key,仍会尝试。要彻底关掉转写用 transcript:'off')
|
|
99
|
+
asrKey,
|
|
100
|
+
// 内容分类阈值(musicLufs / musicSpeechRate / speechRateCut)可覆盖:
|
|
101
|
+
// 不同母带响度能差 9 LU,写死的常数换一批片源就误判。实际生效的那组会写进清单。
|
|
102
|
+
planThresholds = null,
|
|
103
|
+
// 本次运行结束后,本地 ASR 至少再活这么久(毫秒)。陪看用它跨段保活。
|
|
104
|
+
asrIdleMs = null,
|
|
105
|
+
cache = true,
|
|
106
|
+
textOnly = false,
|
|
107
|
+
precomputed = null,
|
|
108
|
+
badgeRatio = 0.15,
|
|
109
|
+
budget = 640_000,
|
|
110
|
+
encode = true,
|
|
111
|
+
ffmpegPath = DEFAULT_FFMPEG,
|
|
112
|
+
ffprobePath = DEFAULT_FFPROBE,
|
|
113
|
+
onProgress,
|
|
114
|
+
} = opts;
|
|
115
|
+
if (!inputRaw) throw new Error('input is required');
|
|
116
|
+
if (!PICK_MODES.includes(pick)) throw new RangeError(`pick must be one of ${PICK_MODES.join('/')}`);
|
|
117
|
+
if (!BURN_MODES.includes(burn)) throw new RangeError(`burn must be one of ${BURN_MODES.join('/')}`);
|
|
118
|
+
|
|
119
|
+
// 链接在这里变成一份本地文件;本地路径原样返回(source 为 null)。
|
|
120
|
+
// 后面的所有阶段都只面对 input,不知道它原来是不是个 URL。
|
|
121
|
+
// ffmpegPath 也要带过去:链接下载时 yt-dlp 需要它来合流 DASH 的 video+audio(issue #18)
|
|
122
|
+
const resolved = await resolveInput(inputRaw, { ...(fetchOptions ?? {}), ffmpegPath });
|
|
123
|
+
const input = resolved.path;
|
|
124
|
+
const sourceInfo = resolved.source;
|
|
125
|
+
// zoom 用高清直链取帧;失败要能回落到本地低清,所以这里只记"首选源",不替换 input
|
|
126
|
+
const remoteFrame = frameSource?.uri
|
|
127
|
+
? { uri: frameSource.uri, http: { userAgent: frameSource.userAgent, referer: frameSource.referer } }
|
|
128
|
+
: null;
|
|
129
|
+
|
|
130
|
+
const info = { ...(await probeVideo(input, { ffprobePath })), path: input };
|
|
131
|
+
// Provenance 是锦上添花:ffmpeg 版本缓存/失败不阻塞;hash 只在显式要求时算。
|
|
132
|
+
const [ffmpeg, sha256] = await Promise.all([
|
|
133
|
+
ffmpegVersion(ffmpegPath),
|
|
134
|
+
sourceHash ? sha256File(input).catch(() => 'unavailable') : Promise.resolve(null),
|
|
135
|
+
]);
|
|
136
|
+
const provenance = {
|
|
137
|
+
...(ffmpeg ? { ffmpeg } : {}),
|
|
138
|
+
...(sourceHash ? { sha256 } : {}),
|
|
139
|
+
};
|
|
140
|
+
const winStart = Math.max(0, Math.min(Number(from) || 0, Math.max(0, info.duration - 0.2)));
|
|
141
|
+
const winEnd = Math.min(info.duration, Number(to) > 0 ? Number(to) : info.duration);
|
|
142
|
+
const winDur = Math.max(0.2, winEnd - winStart);
|
|
143
|
+
|
|
144
|
+
// 分阶段计时:只有真跑的时候才知道慢在哪。结果里带 timing,不额外开销(Date.now 级别)
|
|
145
|
+
// 本地 ASR 的生命周期句柄:只有"我们拉起来的"那个才会在结束时被停。
|
|
146
|
+
// 必须声明在转写块之前 —— 转写现在跑在扫描之前(并行),拿不到后面声明的变量。
|
|
147
|
+
let asrLife = null;
|
|
148
|
+
|
|
149
|
+
const timing = {};
|
|
150
|
+
let _t = Date.now();
|
|
151
|
+
const mark = (name) => { timing[name] = ((Date.now() - _t) / 1000); _t = Date.now(); };
|
|
152
|
+
|
|
153
|
+
// ---- 音频测量(零模型:响度 + 静音)。先做,因为静音位置要用来切 ASR 请求。
|
|
154
|
+
const needAudio = info.hasAudio && !textOnly && (audioStrip !== false || transcript !== 'off');
|
|
155
|
+
const audio = needAudio
|
|
156
|
+
? await analyzeAudio({ input, ffmpegPath, start: winStart, end: winStart + winDur })
|
|
157
|
+
: null;
|
|
158
|
+
const stripAudio = audioStrip !== false ? audio : null;
|
|
159
|
+
const silences = audio?.silences ?? [];
|
|
160
|
+
// 声音事件:突然变响/突然安静。画面没动但事情发生的时刻,只能靠它抓到。
|
|
161
|
+
// 口播片里"每句话的停顿"都会触发,所以**只用最突出的若干个**参与格位加权
|
|
162
|
+
// (全部 90 多个事件铺上去等于把密度曲线压平),清单里也按强度排序展示。
|
|
163
|
+
const allEvents = audio ? detectOnsets(audio) : [];
|
|
164
|
+
mark('audio');
|
|
165
|
+
|
|
166
|
+
// 转写在**扫描的同时**跑:它只依赖音频静音位置,不依赖切点。
|
|
167
|
+
// 21 分钟教程实测:扫描 133s、转写 58s,串起来 202s;并行后只等较慢的那个。
|
|
168
|
+
const transcriptP = (async () => {
|
|
169
|
+
// 这次调用到底会不会真的转写:云端没配 key 只是"跳过"的其中一种,本机服务不需要 key。
|
|
170
|
+
// 判据必须和 `transcribe()` 的门同源(见 asr.js 的 canTranscribe),否则清单会和实际行为相反。
|
|
171
|
+
const willTranscribe = () => canTranscribe(resolveAsrConfig(), asrKey);
|
|
172
|
+
let transcriptInfo = null;
|
|
173
|
+
// 站点有字幕轨但要登录 —— 清单要说明"现在用的是 ASR,不是这视频没字幕"
|
|
174
|
+
let subtitleNeedsLogin = false;
|
|
175
|
+
if (transcriptFile) {
|
|
176
|
+
// 显式给了转写就只用它:不查字幕轨、不跑 ASR。
|
|
177
|
+
// 接 B 站时这一步最省 —— 字幕本来就有,没必要再识别一遍(10 分钟口播省 60–120 秒)。
|
|
178
|
+
// 也**不跑幻觉过滤**:那是给 ASR 兜底的,用户递进来的文件按可信处理。
|
|
179
|
+
try {
|
|
180
|
+
const loaded = await loadTranscriptFile(transcriptFile);
|
|
181
|
+
const { segments: fixed, replaced } = applyTermMap(loaded.segments, resolveAsrConfig().terms);
|
|
182
|
+
transcriptInfo = {
|
|
183
|
+
...(replaced > 0 ? { termsFixed: replaced } : {}),
|
|
184
|
+
source: fixed.length > 0 ? 'file' : 'file-empty',
|
|
185
|
+
model: `file:${loaded.format}`,
|
|
186
|
+
segments: fixed,
|
|
187
|
+
suspect: 0,
|
|
188
|
+
suspectDetail: [],
|
|
189
|
+
};
|
|
190
|
+
} catch (error) {
|
|
191
|
+
transcriptInfo = {
|
|
192
|
+
segments: [],
|
|
193
|
+
source: 'file-failed',
|
|
194
|
+
error: String(error?.message ?? error).slice(0, 300),
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
} else if (transcript !== 'off' && info.hasAudio) {
|
|
198
|
+
// **先试站点字幕轨**(B 站 CC):作者写的文本比 ASR 准,还不烧 CPU。
|
|
199
|
+
// 以前只看"下载下来的 mp4 里有没有内嵌字幕流",而 B 站的字幕是单独轨道,
|
|
200
|
+
// 于是永远判成"没有字幕",白白退回 ASR。
|
|
201
|
+
// 站点字幕默认开(准、且省掉一次 ASR);想省钱/想只走 ASR 时可以显式关:
|
|
202
|
+
// fetchOptions: { siteSubtitles: false }
|
|
203
|
+
const remote = (sourceInfo?.url && fetchOptions?.siteSubtitles !== false)
|
|
204
|
+
? await fetchRemoteSubtitles({ url: sourceInfo.url, cookies: fetchOptions?.cookies ?? null })
|
|
205
|
+
: null;
|
|
206
|
+
const subtitle = remote?.ok
|
|
207
|
+
? remote.segments
|
|
208
|
+
: (info.hasSubtitle ? await extractSubtitleTrack({ input, ffmpegPath }) : null);
|
|
209
|
+
if (remote && !remote.ok && remote.reason === 'needs-login') {
|
|
210
|
+
// 有字幕但要登录:这个事实必须让用户看到,否则会以为"这视频没字幕"
|
|
211
|
+
subtitleNeedsLogin = true;
|
|
212
|
+
}
|
|
213
|
+
if (subtitle) {
|
|
214
|
+
transcriptInfo = {
|
|
215
|
+
segments: subtitle,
|
|
216
|
+
source: 'subtitle',
|
|
217
|
+
model: remote?.ok ? `site-cc${remote.lang ? `:${remote.lang}` : ''}` : 'embedded',
|
|
218
|
+
};
|
|
219
|
+
} else if (!willTranscribe()) {
|
|
220
|
+
// 压根不会转写(云端没配 key)—— 跟"跑了但没听懂"是两码事。
|
|
221
|
+
// 旧代码走的是 withCache → null 空壳 → asr.empty → 'asr-empty',清单于是写
|
|
222
|
+
// "ASR ran and found no speech here",一个字都没听过却说"这片子没人说话"。
|
|
223
|
+
transcriptInfo = { segments: [], source: 'no-key' };
|
|
224
|
+
} else {
|
|
225
|
+
try {
|
|
226
|
+
// 切片调用:单次请求过长会让时间码整体压早(实测 299s 压早 13s)。
|
|
227
|
+
// 结果按 (文件, 窗口, 后端, 切片长度) 缓存 —— 否则 textOnly 分页每翻一页都要重跑 ASR。
|
|
228
|
+
const asrCacheKey = await cacheKey({
|
|
229
|
+
input, start: winStart, end: winStart + winDur,
|
|
230
|
+
threshold: `asr|${ASR_DEFAULTS.baseUrl}|${ASR_DEFAULTS.model}|${asrMaxChunk}|${transcript}|${hotwords ?? ''}`,
|
|
231
|
+
});
|
|
232
|
+
// 本地 ASR 可能要临时拉起(用完就停)—— 只在 asr.json 配了 manage.start 时才托管
|
|
233
|
+
const asrCfg = resolveAsrConfig();
|
|
234
|
+
// `spawnImpl` 不要在这里传:这个文件从来没导入过 spawn,
|
|
235
|
+
// 传 `spawnImpl: spawn` 等于每跑一次就 ReferenceError 一次,被下面的 catch 吞成
|
|
236
|
+
// "asr-failed · spawn is not defined" —— 转写于是永远是空的。默认值在 asr-lifecycle 里。
|
|
237
|
+
asrLife = await ensureAsr({ baseUrl: asrCfg.baseUrl, config: asrCfg })
|
|
238
|
+
.catch((e) => { if (process.env.DSH_ASR_DEBUG) console.error('[asr-lifecycle]', e.message); return null; });
|
|
239
|
+
const asr = await withCache(asrCacheKey, () => transcribeLong({
|
|
240
|
+
input, ffmpegPath, start: winStart, end: winStart + winDur,
|
|
241
|
+
// apiKey 必须传:否则关掉 ASR 只能靠"没 key",而本机服务不需要 key
|
|
242
|
+
silences, maxChunk: asrMaxChunk, apiKey: asrKey,
|
|
243
|
+
...(hotwords !== undefined ? { hotwords } : {}),
|
|
244
|
+
}), { enabled: cache });
|
|
245
|
+
if (asr) {
|
|
246
|
+
// 音乐段的幻觉句会命中多个格子、被复制好几遍,先过滤(结果里报出来,不静默丢)
|
|
247
|
+
const { kept, dropped } = filterSuspectSegments(asr.segments);
|
|
248
|
+
// 用户词典校正(确定性替换,替换次数会报出来)
|
|
249
|
+
const { segments: fixed, replaced } = applyTermMap(kept, resolveAsrConfig().terms);
|
|
250
|
+
transcriptInfo = {
|
|
251
|
+
...(replaced > 0 ? { termsFixed: replaced } : {}),
|
|
252
|
+
...asr,
|
|
253
|
+
// 空结果(整片纯音乐 / 服务在跑但没听到话)不该自称 asr —— 见 PR #3。
|
|
254
|
+
// "没配 key 所以没跑" 已经在上面被 willTranscribe() 分流成 no-key,走不到这里。
|
|
255
|
+
source: asr.empty || fixed.length === 0 ? 'asr-empty' : 'asr',
|
|
256
|
+
segments: fixed,
|
|
257
|
+
suspect: dropped.length,
|
|
258
|
+
suspectDetail: dropped.slice(0, 3).map((d) => ({
|
|
259
|
+
from: +d.from.toFixed(2), to: +d.to.toFixed(2),
|
|
260
|
+
charsPerSec: d.charsPerSec, reason: d.reason,
|
|
261
|
+
})),
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
} catch (error) {
|
|
265
|
+
transcriptInfo = {
|
|
266
|
+
segments: [],
|
|
267
|
+
source: 'asr-failed',
|
|
268
|
+
// 把真实原因带出来 —— 只写 "ASR call failed" 会让每次故障都得重新猜
|
|
269
|
+
error: `${explainFetchError(error).slice(0, 300)} [${describeAsrTarget()}]`,
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
} else if (transcript !== 'off' && !info.hasAudio) {
|
|
274
|
+
transcriptInfo = { segments: [], source: 'no-audio' };
|
|
275
|
+
}
|
|
276
|
+
// 一致性检查:台词落在"被判静音"的区间里 = 两种可能,轻声被吞了,或者 ASR 编的。
|
|
277
|
+
const textInSilence = transcriptInfo?.source === 'asr'
|
|
278
|
+
? countTextInSilence(transcriptInfo.segments, silences)
|
|
279
|
+
: 0;
|
|
280
|
+
|
|
281
|
+
return {
|
|
282
|
+
transcriptInfo: (transcriptInfo && subtitleNeedsLogin)
|
|
283
|
+
? { ...transcriptInfo, subtitleNeedsLogin: true }
|
|
284
|
+
: transcriptInfo,
|
|
285
|
+
textInSilence,
|
|
286
|
+
};
|
|
287
|
+
})();
|
|
288
|
+
|
|
289
|
+
// 扫描结果按 (文件, 窗口, 阈值策略) 缓存:storyboard 之后的 zoom 能直接复用
|
|
290
|
+
const key = cache ? await cacheKey({ input, start: winStart, end: winStart + winDur, threshold }) : null;
|
|
291
|
+
// precomputed:批量模式下全片已经扫过一次,窗口直接复用那份切点与摘要,
|
|
292
|
+
// 不再为每个窗口重新解码一遍(2 小时的片子能省掉 24 次重复扫描)。
|
|
293
|
+
// 逐帧指纹只在"真的扫了"的那一次里拿得到(缓存存不下 Uint8Array),
|
|
294
|
+
// 所以缓存命中 / precomputed 时它们是 null,tagCuts 会退化成不打标签。
|
|
295
|
+
let scanMeans = null;
|
|
296
|
+
let scanPrints = null;
|
|
297
|
+
const scan = precomputed
|
|
298
|
+
? {
|
|
299
|
+
cuts: (precomputed.cuts ?? []).filter((c) => c.t >= winStart && c.t < winStart + winDur),
|
|
300
|
+
summary: precomputed.summary ?? { frames: 0, p90: 0, p99: 0 },
|
|
301
|
+
threshold: precomputed.threshold ?? threshold,
|
|
302
|
+
cached: false,
|
|
303
|
+
reused: true,
|
|
304
|
+
}
|
|
305
|
+
: await withCache(key, async () => {
|
|
306
|
+
const s = await scanShots({
|
|
307
|
+
input, fps: info.fps, threshold, start: winStart, end: winStart + winDur,
|
|
308
|
+
// 默认 0.35s:两刀之间短于它的合并成一刀。快闪素材(<0.35s 一个镜头)要显式调小,
|
|
309
|
+
// 否则 3 秒 18 个镜头会被压成 4 刀 —— 实测过,这是"数不出快闪"的主因。
|
|
310
|
+
minGap: scanGap, ffmpegPath, onProgress,
|
|
311
|
+
});
|
|
312
|
+
// **逐帧的 means / prints 不进缓存**:级联缓存走的是 JSON.stringify,
|
|
313
|
+
// 而 prints 是 7500 个 Uint8Array —— 序列化后会变成 {"0":12,"1":34,…},
|
|
314
|
+
// 60 分钟片子直接几十 MB,而且读回来类型也丢了(判据会拿到坏数据)。
|
|
315
|
+
// 它们只在本次调用里给 tagCuts 用,缓存命中时没有就算了(退化成不打标签)。
|
|
316
|
+
// 但**黑场段要单独存下来**:means 只在扫描那一次存在,不存的话"黑场独占一格"
|
|
317
|
+
// 只在第一次跑生效,第二次(命中缓存)黑场又并回内容格里 —— 同一支片子两次出图不一样。
|
|
318
|
+
scanMeans = s.means;
|
|
319
|
+
scanPrints = s.prints;
|
|
320
|
+
return {
|
|
321
|
+
cuts: s.cuts, stats: s.stats, frames: s.frames,
|
|
322
|
+
threshold: s.threshold, degraded: s.degraded, summary: s.summary,
|
|
323
|
+
darkRuns: detectDarkRuns(s.means, { fps: info.fps }),
|
|
324
|
+
};
|
|
325
|
+
}, { enabled: cache });
|
|
326
|
+
if (cache && !scan.cached && !precomputed) await pruneStorage();
|
|
327
|
+
mark('scan');
|
|
328
|
+
|
|
329
|
+
// ---- 爆点细扫(见 refineBurstCuts 注释:粗扫看不见 0.35s 以下的刀)
|
|
330
|
+
// **运行一开始就续命**。上一次运行结束时设的 idleMs 计时器,会在这一次运行的扫描阶段到点,
|
|
331
|
+
// 把服务关掉 —— 等这次终于到转录那一步又得重新拉起(白等 30 秒)。续命一次就避免这种浪费。
|
|
332
|
+
if (isOwned()) keepAlive();
|
|
333
|
+
let cuts = scan.cuts;
|
|
334
|
+
|
|
335
|
+
// ---- 极静素材(PPT / 代码录屏 / 固定机位):绝对阈值会漏掉"只改了几个像素"的翻页。
|
|
336
|
+
// 这类素材的分数中位数接近 0,一页 PPT 换页可能只有 3–8 分,压在任何合理绝对阈值下面。
|
|
337
|
+
// 改用**相对基线**再找一次(和本地中位数比),只在确实更静的时候替换。
|
|
338
|
+
// 用户反馈(野生的猛龙):纯 PPT 视频上"阈值压到 0.08 也一条都检不出来,只能退回等间隔"。
|
|
339
|
+
if (!precomputed && scan.stats.length > 20) {
|
|
340
|
+
// 判据是**刀密度**,不是"画面静不静":实测概念 PV / 沧野 / MAD 的中位分都是 0.9–1.1,
|
|
341
|
+
// 和录屏素材(0.0–1.4)完全混在一起,用中位分根本分不开。
|
|
342
|
+
// 能分开的是刀/秒:录屏 0.11–0.22,视频内容 0.40–0.49。
|
|
343
|
+
const perSec = cuts.length / Math.max(1, winDur);
|
|
344
|
+
if (perSec < 0.25) {
|
|
345
|
+
// minAbs 4:实测 320×180 上"改一块约 3.5% 的画面"峰值只有 5.7 分、7.8% 才 11.8 分 ——
|
|
346
|
+
// 绝对阈值 12~15 全都漏;而静止画面的噪声底只有 0.0–1.5,4 分足够把噪声挡在外面。
|
|
347
|
+
const spikes = suppressClose(spikeCuts(scan.stats, { k: 4, minAbs: 4, halfWindow: 12 }), scanGap);
|
|
348
|
+
if (spikes.length > cuts.length) cuts = spikes;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
let refinedBursts = [];
|
|
353
|
+
if (refineBursts && !precomputed && !textOnly) {
|
|
354
|
+
const r = refineCutsByWindow({ stats: scan.stats, coarseCuts: cuts, fps: info.fps, winStart, winDur });
|
|
355
|
+
cuts = r.cuts;
|
|
356
|
+
refinedBursts = r.refined;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// ---- 给每个切点打类型标签(flash / white / black / hardcut / dissolve / motion)。
|
|
360
|
+
// **一个都不删**:删掉误检会让这段在插件眼里变成"完全静止",反而丢了"这里一直在动"。
|
|
361
|
+
// 标签只用于清单表述和下游降权,格位分配靠的是变化率积分(见 densityFromScore)。
|
|
362
|
+
if (!precomputed && !textOnly && Array.isArray(scanPrints) && scanPrints.length) {
|
|
363
|
+
cuts = tagCuts(cuts, {
|
|
364
|
+
prints: scanPrints,
|
|
365
|
+
means: scanMeans,
|
|
366
|
+
fps: info.fps,
|
|
367
|
+
scores: scan.stats?.map((s) => s.score),
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
// ---- 台词:显式文件 > 字幕轨 > ASR;三者都没有就静默跳过(绝不让分镜失败)
|
|
373
|
+
|
|
374
|
+
const transcriptResult = await transcriptP;
|
|
375
|
+
let { transcriptInfo } = transcriptResult;
|
|
376
|
+
const { textInSilence } = transcriptResult;
|
|
377
|
+
// ---- 硬字幕校正:只在明确要求、且转写来自 ASR 时才做
|
|
378
|
+
let ocrReport = null;
|
|
379
|
+
if (ocr && transcriptInfo?.source === 'asr' && (transcriptInfo.segments?.length ?? 0) > 0) {
|
|
380
|
+
ocrReport = await correctByOnScreenSubs({
|
|
381
|
+
input, winStart, winDur, ffmpegPath, segments: transcriptInfo.segments, remoteFrame,
|
|
382
|
+
// URL 模式下 input 是下载的扫描副本(默认 360p)。scale=1280 放大不回细节,
|
|
383
|
+
// 所以这份校正是"基于低清副本做的",必须让清单说清楚,而不是假装和原流一样准。
|
|
384
|
+
sourceCopyHeight: sourceInfo ? (sourceInfo.scanActual ?? sourceInfo.scanHeight ?? null) : null,
|
|
385
|
+
}).catch((e) => {
|
|
386
|
+
if (process.env.DSH_OCR_DEBUG) console.error('[ocr]', e?.message ?? e);
|
|
387
|
+
return { status: 'failed', reason: String(e?.message ?? e).slice(0, 160) };
|
|
388
|
+
});
|
|
389
|
+
if (ocrReport?.status === 'applied' && ocrReport.fixed > 0) {
|
|
390
|
+
transcriptInfo = { ...transcriptInfo, segments: ocrReport.segments, ocrFixed: ocrReport.fixed };
|
|
391
|
+
}
|
|
392
|
+
delete ocrReport.segments;
|
|
393
|
+
}
|
|
394
|
+
const relSegments = (transcriptInfo?.segments ?? [])
|
|
395
|
+
.map((seg) => ({ ...seg, from: seg.from - winStart, to: seg.to - winStart }))
|
|
396
|
+
.filter((seg) => seg.to > 0 && seg.from < winDur);
|
|
397
|
+
// 窗口口径:transcriptFile 可能给的是整片,不能拿整片 chars 去除以 winDur。
|
|
398
|
+
const transcriptChars = relSegments.reduce((n, seg) => n + String(seg.text ?? '').length, 0);
|
|
399
|
+
// 外部文本只做标记,不改变执行:注入扫描是证据,不是策略。
|
|
400
|
+
// 标题也算外部文本(yt-dlp 的 title 会进清单),一并扫;它没有时间码,from/to 留 null。
|
|
401
|
+
const externalSource = sourceInfo?.url ?? info.path ?? null;
|
|
402
|
+
const suspectInjection = findInjection(
|
|
403
|
+
[
|
|
404
|
+
...(sourceInfo?.title ? [{ text: sourceInfo.title }] : []),
|
|
405
|
+
...relSegments,
|
|
406
|
+
],
|
|
407
|
+
{ source: externalSource },
|
|
408
|
+
);
|
|
409
|
+
const speech = relSegments.length > 0
|
|
410
|
+
? speechCurve(relSegments, { duration: winDur })
|
|
411
|
+
: null;
|
|
412
|
+
|
|
413
|
+
// 声音事件只有在"话不密"的片子里才有信息量:
|
|
414
|
+
// 口播片每句话的停顿都会触发(实测 299s 里 92 次),铺到密度曲线上等于把它压平。
|
|
415
|
+
const speechRateForEvents = winDur > 0
|
|
416
|
+
? relSegments.reduce((n, seg) => n + seg.text.length, 0) / winDur : 0;
|
|
417
|
+
const audioEvents = speechRateForEvents < 3
|
|
418
|
+
? [...allEvents]
|
|
419
|
+
.sort((a, b) => Math.abs(b.delta) - Math.abs(a.delta))
|
|
420
|
+
.slice(0, 12)
|
|
421
|
+
.sort((a, b) => a.t - b.t)
|
|
422
|
+
: [];
|
|
423
|
+
|
|
424
|
+
// ---- 格数:放在台词与音频之后,是为了让"口播多不多 / 是不是音乐驱动"参与决策
|
|
425
|
+
let cells = Math.max(0, Number(opts.cells) || 0);
|
|
426
|
+
let sheets = Math.max(0, Number(opts.sheets) || 0);
|
|
427
|
+
const autoPlan = cells === 0;
|
|
428
|
+
// 和 suggest() 用同一个口径;下面写进 plan.inputs,方便复现判定。
|
|
429
|
+
const speechRate = winDur > 0 ? transcriptChars / winDur : 0;
|
|
430
|
+
let suggestion;
|
|
431
|
+
if (cells === 0) {
|
|
432
|
+
suggestion = suggest({
|
|
433
|
+
duration: winDur,
|
|
434
|
+
cuts: cuts.length,
|
|
435
|
+
motion: scan.summary.p90,
|
|
436
|
+
aspect: info.aspect,
|
|
437
|
+
speechRate,
|
|
438
|
+
hasSubtitle: info.hasSubtitle,
|
|
439
|
+
meanLufs: audio?.mean,
|
|
440
|
+
...(planThresholds ? { thresholds: planThresholds } : {}),
|
|
441
|
+
});
|
|
442
|
+
cells = suggestion.cells;
|
|
443
|
+
sheets = sheets || suggestion.sheets;
|
|
444
|
+
}
|
|
445
|
+
// 音乐驱动**只影响取帧**,不影响格数(格数走 rodt)。音乐片的信息全在画面上,
|
|
446
|
+
// 所以把"摊开"的触发门槛压低:同样的段更容易摊、摊得更细。
|
|
447
|
+
// 用 isMusicDriven 单独判一次,而不是只读 suggestion —— 显式指定 cells 时 suggestion 是空的,
|
|
448
|
+
// 但"音乐片取帧更密"跟格数从哪来无关。
|
|
449
|
+
const musicDriven = suggestion?.musicDriven === true
|
|
450
|
+
|| isMusicDriven({ meanLufs: audio?.mean, speechRate, thresholds: planThresholds ?? {} });
|
|
451
|
+
sheets = sheets || 1;
|
|
452
|
+
// ---- 格数**往上补满**
|
|
453
|
+
// 5 格会排成 2×3(容量 6),右下留一个空格。空格和画面占的是同一张画布、同样的 token,
|
|
454
|
+
// 所以空着是纯损失 —— 把每张图的格数补到布局容量,再按补后的数去取帧。
|
|
455
|
+
// 往上补不往下砍:少一格等于少看一个瞬间,多一格只是多花一次取帧(约 0.3 s)。
|
|
456
|
+
const fitted = fillLayout(cells, info.aspect);
|
|
457
|
+
// 补过之后要能看出"你其实要了 5 格":清单里两个数都给,否则模型会以为自己看的是 5 格。
|
|
458
|
+
const filledFrom = fitted.cells > cells ? cells : null;
|
|
459
|
+
cells = fitted.cells;
|
|
460
|
+
// 本次实际输入 + 生效阈值。只记录,不做成十几个可配置旋钮。
|
|
461
|
+
const planInfo = {
|
|
462
|
+
cells, sheets, adaptive, pick, burn, minGap,
|
|
463
|
+
...(filledFrom ? { filledFrom } : {}),
|
|
464
|
+
reason: suggestion?.reason ?? 'explicit',
|
|
465
|
+
auto: autoPlan,
|
|
466
|
+
inputs: {
|
|
467
|
+
duration: +winDur.toFixed(2),
|
|
468
|
+
scanThreshold: scan.threshold,
|
|
469
|
+
meanLufs: Number.isFinite(audio?.mean) ? +audio.mean.toFixed(1) : null,
|
|
470
|
+
speechRate: +speechRate.toFixed(2),
|
|
471
|
+
motion: +(Number(scan.summary?.p90) || 0).toFixed(1),
|
|
472
|
+
cuts: cuts.length,
|
|
473
|
+
hasSubtitle: Boolean(info.hasSubtitle),
|
|
474
|
+
},
|
|
475
|
+
thresholds: { ...PLAN_THRESHOLDS, ...(planThresholds ?? {}) },
|
|
476
|
+
};
|
|
477
|
+
|
|
478
|
+
// 两条路:自适应按密度分配格位(快切区多给格),否则退回"并段到 k 格"
|
|
479
|
+
mark('transcript');
|
|
480
|
+
const relCuts = cuts.map((c) => c.t - winStart);
|
|
481
|
+
// **积分采样点(假切点)**:扫描之后立刻算好,交给下面"格内取几帧 / 取在哪"用。
|
|
482
|
+
// 它不进 `cuts` —— 清单里"切点 N 个"必须还是真切点,否则模型会以为那些地方有硬切。
|
|
483
|
+
// 阈值就是 equivSeconds(每条采样点代表多少秒的平均变化量),音频驱动只改这一个数:
|
|
484
|
+
// 音乐片信息全在画面上,所以每 4 秒等效变化就采一个点(默认 6 秒)。
|
|
485
|
+
const sampleMarks = scan.stats?.length
|
|
486
|
+
? integralMarks({
|
|
487
|
+
duration: winDur,
|
|
488
|
+
series: scan.stats,
|
|
489
|
+
cuts: cuts.map((c) => c.t),
|
|
490
|
+
start: winStart,
|
|
491
|
+
equivSeconds: musicDriven ? 4 : 6,
|
|
492
|
+
})
|
|
493
|
+
: [];
|
|
494
|
+
planInfo.sampleMarks = sampleMarks.length;
|
|
495
|
+
// 让 video_locate 能直接复用这次的转写,省掉一次 ASR
|
|
496
|
+
if (transcriptInfo?.segments?.length) rememberSegments(input, transcriptInfo.segments);
|
|
497
|
+
let cellRanges;
|
|
498
|
+
if (adaptive && relCuts.length > 0) {
|
|
499
|
+
// 密度来源:用**画面变化率**而不是切点计数(见 densityFromScore 的注释)。
|
|
500
|
+
// 复用缓存时逐帧 stats 还在(它跟着扫描结果一起存),所以这条不会退化。
|
|
501
|
+
// **黑场单独成段**:黑屏在分数上几乎是 0(前后都黑,没有"变化"),永远不会被当成切点,
|
|
502
|
+
// 于是它和后面的 logo/正片挤在同一格里,而那一格取中点数 —— 正好落在黑里,整格纯黑。
|
|
503
|
+
// 实测概念PV:片头 0–5.7s 全黑(亮度 1),0–37.6s 那一格的中点 18.8s 亮度是 0。
|
|
504
|
+
// 现在把 ≥2 秒的黑场各切出来独占一格,片头/片尾的黑屏不再吞掉内容。
|
|
505
|
+
// 黑场段是扫描时算好存进缓存的(见上面 darkRuns),不依赖本次有没有 means。
|
|
506
|
+
const darkRuns = (Array.isArray(scan.darkRuns) ? scan.darkRuns : [])
|
|
507
|
+
.filter((r) => r.to - r.from >= 2 && r.from < winDur);
|
|
508
|
+
let segRanges;
|
|
509
|
+
if (darkRuns.length > 0) {
|
|
510
|
+
const parts = [];
|
|
511
|
+
let cursor = 0;
|
|
512
|
+
for (const d of darkRuns) {
|
|
513
|
+
if (d.from > cursor + 0.5) parts.push({ from: cursor, to: d.from, dark: false });
|
|
514
|
+
parts.push({ from: d.from, to: Math.min(d.to, winDur), dark: true });
|
|
515
|
+
cursor = Math.min(d.to, winDur);
|
|
516
|
+
}
|
|
517
|
+
if (cursor < winDur - 0.5) parts.push({ from: cursor, to: winDur, dark: false });
|
|
518
|
+
|
|
519
|
+
// 黑场**额外占格**,不从内容格数里扣 —— 否则 4 段黑场就把 4 格吃光,
|
|
520
|
+
// 剩下 65 秒的内容挤成一格(实测踩过)。
|
|
521
|
+
const contentTotal = cells * sheets;
|
|
522
|
+
const countIn = (p2) => relCuts.filter((c) => c >= p2.from && c < p2.to).length;
|
|
523
|
+
const allContentCuts = parts.filter((x) => !x.dark).reduce((n, p2) => n + countIn(p2), 0);
|
|
524
|
+
|
|
525
|
+
segRanges = [];
|
|
526
|
+
for (const p2 of parts) {
|
|
527
|
+
if (p2.dark) {
|
|
528
|
+
segRanges.push({ from: p2.from, to: p2.to, density: 0, dark: true });
|
|
529
|
+
continue;
|
|
530
|
+
}
|
|
531
|
+
// 内容区按各自占的刀数比例分格,内部仍用 rodt
|
|
532
|
+
const share = allContentCuts > 0
|
|
533
|
+
? Math.max(1, Math.round((contentTotal * countIn(p2)) / allContentCuts))
|
|
534
|
+
: 1;
|
|
535
|
+
const rs = planByRodt({
|
|
536
|
+
duration: p2.to - p2.from,
|
|
537
|
+
cuts: relCuts.filter((c) => c >= p2.from && c < p2.to).map((c) => c - p2.from),
|
|
538
|
+
cells: share,
|
|
539
|
+
});
|
|
540
|
+
segRanges.push(...rs.map((r) => ({ from: r.from + p2.from, to: r.to + p2.from, density: r.density })));
|
|
541
|
+
}
|
|
542
|
+
segRanges.sort((a, b) => a.from - b.from);
|
|
543
|
+
} else {
|
|
544
|
+
// **rodt**:每格长度 = 常数 ÷ 该处的切点密度(B = K/A)。
|
|
545
|
+
// 一分钟切 70 刀的地方一格 5 秒,一分钟才 18 刀的地方一格 24 秒 —— 实测相差 4.6~5.5 倍。
|
|
546
|
+
// 而且因为用"累积切点等分"实现,每格的镜头数也顺带均匀(6~10 个),不用再单独约束。
|
|
547
|
+
segRanges = planByRodt({ duration: winDur, cuts: relCuts, cells: cells * sheets });
|
|
548
|
+
}
|
|
549
|
+
cellRanges = segRanges
|
|
550
|
+
.map((r) => ({ from: r.from + winStart, to: r.to + winStart, density: r.density, dark: r.dark === true }));
|
|
551
|
+
// 黑场是从"内容格数"里抠出来的(每段独占一格),所以总段数会比原计划多。
|
|
552
|
+
// 布局按 cells 分组,容量不够就会丢格 —— 这里把 cells 抬到实际段数。
|
|
553
|
+
if (cellRanges.length > cells * sheets) {
|
|
554
|
+
cells = Math.ceil(cellRanges.length / sheets);
|
|
555
|
+
}
|
|
556
|
+
} else {
|
|
557
|
+
const segs = segmentsFromCuts(winDur, relCuts, 0.4, winStart);
|
|
558
|
+
cellRanges = fitSegments(segs, cells * sheets, { minGap })
|
|
559
|
+
.map(([a, b]) => ({ from: a, to: b, density: 1 }));
|
|
560
|
+
}
|
|
561
|
+
const groups = [];
|
|
562
|
+
// **先排好画面,再按累计帧数切 sheet**(流程的最后一步)。
|
|
563
|
+
// 一格不摊是 1 帧、摊 3×3 是 9 帧,格数一样但信息量差 9 倍,
|
|
564
|
+
// 所以只能按"这一格贡献多少帧"来切,不能按格数均分。
|
|
565
|
+
// 切的是格点边界(= 切点),上一张末尾切点就是下一张起点,天然衔接不断裂。
|
|
566
|
+
if (!(Number(opts.sheets) > 0)) {
|
|
567
|
+
// 调用方没指定张数 → 按累计帧数切(自适应)
|
|
568
|
+
const kEst = cellRanges.map((r) => {
|
|
569
|
+
const cs = cuts.filter((c) => c.t >= r.from && c.t < r.to);
|
|
570
|
+
const marks = sampleMarks.filter((t) => t >= r.from && t < r.to);
|
|
571
|
+
const cutScore = cs.length ? cs.reduce((a, c) => a + (c.score ?? 0), 0) / cs.length : Infinity;
|
|
572
|
+
return chooseSubGrid({
|
|
573
|
+
shots: cs.length + 1 + marks.length, cellW: 250, cellH: 140, dur: r.to - r.from, cutScore,
|
|
574
|
+
});
|
|
575
|
+
});
|
|
576
|
+
groups.push(...planSheetsByFrames(
|
|
577
|
+
cellRanges.map((r, i) => ({ ...r, k: kEst[i] })),
|
|
578
|
+
{ frameBudget: 64, maxCellsPerSheet: 16 },
|
|
579
|
+
));
|
|
580
|
+
sheets = groups.length;
|
|
581
|
+
} else {
|
|
582
|
+
// 调用方显式指定了张数(测试、批量脚本)就尊重它,仍按格数均分
|
|
583
|
+
for (let i = 0; i < sheets; i++) groups.push(cellRanges.slice(i * cells, (i + 1) * cells));
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
// textOnly:只重算"格 → 时间段 → 台词",一帧都不解、一张图都不拼。
|
|
587
|
+
// 用途:总览文本被宿主截断后,按 cellRange 分批把剩下的台词取回来(第二次调用命中缓存,几乎瞬时)。
|
|
588
|
+
if (textOnly) {
|
|
589
|
+
const cellsMeta = [];
|
|
590
|
+
let n = 0;
|
|
591
|
+
for (const group of groups) {
|
|
592
|
+
const aligned = alignCells(group, transcriptInfo?.segments ?? []);
|
|
593
|
+
group.forEach(({ from: a, to: b }, gi) => {
|
|
594
|
+
n += 1;
|
|
595
|
+
const t = aligned[gi] ?? null;
|
|
596
|
+
cellsMeta.push({
|
|
597
|
+
i: n,
|
|
598
|
+
t_start: +a.toFixed(3),
|
|
599
|
+
t_end: +b.toFixed(3),
|
|
600
|
+
...(t?.text ? { text: t.text, charsPerSec: t.charsPerSec } : {}),
|
|
601
|
+
});
|
|
602
|
+
});
|
|
603
|
+
}
|
|
604
|
+
return {
|
|
605
|
+
info,
|
|
606
|
+
window: { from: winStart, to: winStart + winDur, duration: winDur },
|
|
607
|
+
cuts,
|
|
608
|
+
summary: scan.summary,
|
|
609
|
+
threshold: scan.threshold,
|
|
610
|
+
...(scan.degraded ? { degraded: scan.degraded } : {}),
|
|
611
|
+
cached: Boolean(scan.cached),
|
|
612
|
+
audio: null,
|
|
613
|
+
transcript: transcriptInfo
|
|
614
|
+
? { source: transcriptInfo.source, model: transcriptInfo.model ?? null,
|
|
615
|
+
segments: relSegments.length, chars: transcriptChars,
|
|
616
|
+
charsPerSec: +(transcriptChars / Math.max(1, winDur)).toFixed(2),
|
|
617
|
+
...(suspectInjection.length ? { suspectInjection } : {}) }
|
|
618
|
+
: null,
|
|
619
|
+
provenance,
|
|
620
|
+
plan: { ...planInfo, bursts: [] },
|
|
621
|
+
sheets: [],
|
|
622
|
+
cells: cellsMeta,
|
|
623
|
+
textOnly: true,
|
|
624
|
+
...(sourceInfo ? { source: sourceInfo } : {}),
|
|
625
|
+
// 哪些窗口被细扫过、粗扫/细扫各数出多少刀 —— 清单要据此说明"这段的镜头数可信"
|
|
626
|
+
...(refinedBursts.length ? { refinedBursts } : {}),
|
|
627
|
+
totalDuration: +cellRanges.reduce((n2, r) => n2 + (r.to - r.from), 0).toFixed(3),
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
const out = [];
|
|
632
|
+
let index = 0;
|
|
633
|
+
let fallbacks = 0;
|
|
634
|
+
for (const [si, group] of groups.entries()) {
|
|
635
|
+
if (group.length === 0) continue;
|
|
636
|
+
const { cols, rows } = bestLayout(Math.max(1, group.length), info.aspect);
|
|
637
|
+
// 有音频带时先扣掉条带占用的预算:layoutCanvas 与 composeSheet 必须用**同一个** budget,
|
|
638
|
+
// 否则取帧尺寸和拼图尺寸不一致,图会变成斜条纹(踩过)
|
|
639
|
+
const cellBudget = stripAudio ? Math.round(budget * 0.9) : budget;
|
|
640
|
+
const { width, height, cellW, cellH } = layoutCanvas(cols, rows, info.aspect, cellBudget);
|
|
641
|
+
const aligned = alignCells(group, transcriptInfo?.segments ?? []);
|
|
642
|
+
const frames = [];
|
|
643
|
+
const cellMeta = [];
|
|
644
|
+
// 摊格子要额外取 k²−1 帧(4×4 就是 15 次 ffmpeg)。整张图最多多取 32 帧,
|
|
645
|
+
// 否则一支全是快闪的片子会变成"每格取 16 张",渲染时间翻十几倍。
|
|
646
|
+
// 摊格子要额外取 k²−1 帧(4×4 就是 15 次 ffmpeg)。原来设 32,实测概念 PV 上
|
|
647
|
+
// 41 个镜头只覆盖到 33 个 —— 有 10 个镜头(24%)压根没出现在图上。
|
|
648
|
+
// 提到 48 就能全覆盖(画面 57 个、覆盖 41/41),代价约多 16 帧 × 并发 3 路 ≈ 0.3~0.5 秒。
|
|
649
|
+
const subBudget = 48;
|
|
650
|
+
// ---- 取帧:先算完所有格子的参数,再并发取帧,最后按顺序组装。
|
|
651
|
+
// 原来是一格一格 await(9 格串行,短视频里占 60% 的时间)。ffmpeg 每次只解一帧,
|
|
652
|
+
// 彼此没有依赖,并发 3 路就能把这部分压掉一半以上。
|
|
653
|
+
const plan = [];
|
|
654
|
+
for (const [gi, { from: a, to: b }] of group.entries()) {
|
|
655
|
+
const cellCutList = cuts.filter((c) => c.t >= a && c.t < b);
|
|
656
|
+
const cellCuts = cellCutList.length;
|
|
657
|
+
// 本格里的积分采样点:它们和真切点一样是"分段边界",所以合并成一份
|
|
658
|
+
// `marks` 传给下面 —— 摊几×几看它有几个分段,每个分段取一帧。
|
|
659
|
+
const cellMarks = sampleMarks.filter((t) => t >= a && t < b);
|
|
660
|
+
const cutScore = cellCuts > 0
|
|
661
|
+
? cellCutList.reduce((n, c) => n + (c.score ?? 0), 0) / cellCuts
|
|
662
|
+
: Infinity;
|
|
663
|
+
// 段内逐帧分数的均值 —— 静止约 0.2、匀速摇镜 1.5~3。
|
|
664
|
+
// 用来兜住"一个镜头但在动"的段,否则整段只取 1 帧,运动过程全丢。
|
|
665
|
+
const cellStats = (scan.stats ?? []).filter((x) => x.t >= a && x.t < b);
|
|
666
|
+
const meanMotion = cellStats.length
|
|
667
|
+
? cellStats.reduce((n2, x) => n2 + x.score, 0) / cellStats.length
|
|
668
|
+
: 0;
|
|
669
|
+
const want = chooseSubGrid({
|
|
670
|
+
shots: cellCuts + 1 + cellMarks.length, cellW, cellH, dur: b - a, cutScore, meanMotion,
|
|
671
|
+
// 音乐驱动:单镜头但有动静就摊(门槛 1.5 → 0.7)
|
|
672
|
+
minMotion: musicDriven ? 0.7 : 1.5,
|
|
673
|
+
});
|
|
674
|
+
plan.push({
|
|
675
|
+
gi, a, b, cellCuts,
|
|
676
|
+
// 本格的分段边界(真切点 + 积分采样点),摊开时用它决定每个子帧落在哪一段里
|
|
677
|
+
cutTimes: [...cellCutList.map((c) => c.t), ...cellMarks].sort((x, y) => x - y),
|
|
678
|
+
sub: want, want, rate: (cellCuts + 1 + cellMarks.length) / Math.max(0.1, b - a),
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
// 预算按「刀/秒」从高到低分配,**不按格序**。
|
|
682
|
+
// 原来按序发,密集的那格要是排在后面就拿不到预算 —— 实测 MAD 9 格里最密的第 8 格
|
|
683
|
+
// (1.51 刀/秒)正好排最后,能摊开纯属前面几格没抢。
|
|
684
|
+
let budgetLeft = subBudget;
|
|
685
|
+
for (const p of [...plan].sort((x, y) => y.rate - x.rate)) {
|
|
686
|
+
let s = p.want;
|
|
687
|
+
while (s > 1 && s * s - 1 > budgetLeft) s -= 1; // 预算不够就降档,降不下去就整格
|
|
688
|
+
if (s > 1) budgetLeft -= s * s - 1;
|
|
689
|
+
p.sub = s;
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
const _ex0 = Date.now();
|
|
693
|
+
const shots = await mapPool(plan, frameConcurrency, async ({ a, b, sub, cutTimes }) => {
|
|
694
|
+
if (sub > 1) {
|
|
695
|
+
// 快闪格:摊成 k×k,一张图交代 k² 个瞬间(token 不变)
|
|
696
|
+
return extractSubTile({
|
|
697
|
+
input, remote: remoteFrame, a, b, k: sub, cellW, cellH, ffmpegPath,
|
|
698
|
+
shots: cutTimes,
|
|
699
|
+
});
|
|
700
|
+
}
|
|
701
|
+
return extractFrameWithFallback({
|
|
702
|
+
input, remote: remoteFrame, at: a, dur: b - a, cellW, cellH, ffmpegPath, pick,
|
|
703
|
+
});
|
|
704
|
+
});
|
|
705
|
+
|
|
706
|
+
timing.extract = (timing.extract ?? 0) + (Date.now() - _ex0) / 1000;
|
|
707
|
+
for (const [ki, { gi, a, b, cellCuts, sub }] of plan.entries()) {
|
|
708
|
+
index += 1;
|
|
709
|
+
const frame = shots[ki];
|
|
710
|
+
if (frame.via === 'local-fallback') fallbacks += 1;
|
|
711
|
+
frames.push({ buffer: frame.buffer, index });
|
|
712
|
+
const text = aligned[gi] ?? null;
|
|
713
|
+
cellMeta.push({
|
|
714
|
+
i: index,
|
|
715
|
+
sheet: si + 1,
|
|
716
|
+
t_start: +a.toFixed(3),
|
|
717
|
+
t_end: +b.toFixed(3),
|
|
718
|
+
// 平铺格的画面是 k² 个瞬间,不存在"这一格的取帧时刻";
|
|
719
|
+
// 不写 t_frame,清单和 evidence 都不会给出误导性的 frame@。
|
|
720
|
+
...(sub > 1 ? { sub } : { t_frame: +frame.t.toFixed(3) }),
|
|
721
|
+
// 黑场格:整段没有内容,清单要写明,否则模型会以为"这一格是空的、可能采样失败"
|
|
722
|
+
...(group[gi]?.dark ? { dark: true } : {}),
|
|
723
|
+
...(cellCuts > 0 ? { cuts: cellCuts } : {}),
|
|
724
|
+
...(frame.sharp !== undefined ? { sharp: +frame.sharp.toFixed(1) } : {}),
|
|
725
|
+
...(text?.text ? { text: text.text, charsPerSec: text.charsPerSec } : {}),
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
let sheet = composeSheet({
|
|
729
|
+
frames, cols, rows, cellAspect: info.aspect, budget: cellBudget, burn, badgeRatio,
|
|
730
|
+
});
|
|
731
|
+
if (stripAudio) {
|
|
732
|
+
// 条带高度按"宽的 5.5%"会在大长条上失控(2476px 宽 → 136px 高,占掉 37% 画面),
|
|
733
|
+
// 所以同时受格高的 40% 约束。
|
|
734
|
+
const stripH = Math.max(24, Math.min(Math.round(width * 0.055), Math.round(cellH * 0.28)));
|
|
735
|
+
sheet = addAudioStrip(sheet, {
|
|
736
|
+
loudness: stripAudio, silences: stripAudio.silences, cuts: cuts.map((c) => c.t),
|
|
737
|
+
window: { from: winStart, to: winStart + winDur }, stripH,
|
|
738
|
+
});
|
|
739
|
+
}
|
|
740
|
+
out.push({
|
|
741
|
+
sheet: si + 1, cols, rows, cellW, cellH,
|
|
742
|
+
width: sheet.width, height: sheet.height, buffer: sheet.buffer, cells: cellMeta,
|
|
743
|
+
...(sheet.stripH ? { stripH: sheet.stripH } : {}),
|
|
744
|
+
...(encode ? { png: await encodePngBuffer(sheet.buffer, sheet.width, sheet.height, { ffmpegPath }) } : {}),
|
|
745
|
+
});
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
const totalDuration = +cellRanges.reduce((n, r) => n + (r.to - r.from), 0).toFixed(3);
|
|
749
|
+
|
|
750
|
+
// 记一笔"看过什么":下次 probe 能告诉模型"这部片子你看过",避免重新描述一遍。
|
|
751
|
+
// 失败不影响结果(记忆是锦上添花)。
|
|
752
|
+
// 必须 await:不 await 的话下一次 probe 可能读不到这一笔(实测踩到,少了一整段)
|
|
753
|
+
await remember(info, {
|
|
754
|
+
from: winStart, to: winStart + winDur, cells: cellRanges.length, cuts: cuts.length,
|
|
755
|
+
}).catch(() => {});
|
|
756
|
+
|
|
757
|
+
mark('frames');
|
|
758
|
+
// 本次运行结束:如果是我们拉起的本地 ASR,安排它空闲后自动退出
|
|
759
|
+
// (own 的才停 —— 别人启动的实例无权杀,杀了会打断正在用它的任务)
|
|
760
|
+
if (asrLife?.owned || isOwned()) {
|
|
761
|
+
const c = resolveAsrConfig();
|
|
762
|
+
scheduleStop({
|
|
763
|
+
owned: true, config: c, baseUrl: c.baseUrl,
|
|
764
|
+
minIdleMs: Number.isFinite(asrIdleMs) ? asrIdleMs : undefined,
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
// **这里是赋值,不是 return。**
|
|
769
|
+
// 原来是 `return {`:函数当场结束,后面记 cell 表的 `saveCells()` 和 `return result`
|
|
770
|
+
// 全成了死代码 —— 所以 0.4.4 的 cell 表**从来没写进去过**,
|
|
771
|
+
// `video_zoom({ cellId })` 一直找不到格子,只能退回 from/to。
|
|
772
|
+
const result = {
|
|
773
|
+
timing,
|
|
774
|
+
...(ocrReport ? { ocr: ocrReport } : {}),
|
|
775
|
+
info,
|
|
776
|
+
provenance,
|
|
777
|
+
window: { from: winStart, to: winStart + winDur, duration: winDur },
|
|
778
|
+
cuts,
|
|
779
|
+
summary: scan.summary,
|
|
780
|
+
threshold: scan.threshold,
|
|
781
|
+
...(scan.degraded ? { degraded: scan.degraded } : {}),
|
|
782
|
+
cached: Boolean(scan.cached),
|
|
783
|
+
// 链接来源的元信息(本地文件时没有这一段)。直链不在里面,那是临时凭证。
|
|
784
|
+
...(sourceInfo ? { source: sourceInfo } : {}),
|
|
785
|
+
// 哪些窗口被细扫过、粗扫/细扫各数出多少刀 —— 清单要据此说明"这段的镜头数可信"
|
|
786
|
+
...(refinedBursts.length ? { refinedBursts } : {}),
|
|
787
|
+
// 有高清直链却有格子落了回来 —— 要报,否则"这格怎么这么糊"没有解释
|
|
788
|
+
...(fallbacks > 0 ? { frameFallbacks: fallbacks } : {}),
|
|
789
|
+
audio: stripAudio
|
|
790
|
+
? {
|
|
791
|
+
...stripAudio,
|
|
792
|
+
events: allEvents,
|
|
793
|
+
summary: describeAudio(stripAudio, winDur),
|
|
794
|
+
}
|
|
795
|
+
: null,
|
|
796
|
+
transcript: transcriptInfo
|
|
797
|
+
? { source: transcriptInfo.source, model: transcriptInfo.model ?? null,
|
|
798
|
+
segments: relSegments.length,
|
|
799
|
+
chars: transcriptChars,
|
|
800
|
+
charsPerSec: +(transcriptChars / Math.max(1, winDur)).toFixed(2),
|
|
801
|
+
...(suspectInjection.length ? { suspectInjection } : {}),
|
|
802
|
+
...(transcriptInfo.chunks ? { chunks: transcriptInfo.chunks } : {}),
|
|
803
|
+
...(transcriptInfo.suspect ? {
|
|
804
|
+
suspect: transcriptInfo.suspect, suspectDetail: transcriptInfo.suspectDetail,
|
|
805
|
+
} : {}),
|
|
806
|
+
...(transcriptInfo.termsFixed ? { termsFixed: transcriptInfo.termsFixed } : {}),
|
|
807
|
+
...(textInSilence ? { textInSilence } : {}),
|
|
808
|
+
...(transcriptInfo.error ? { error: transcriptInfo.error } : {}) }
|
|
809
|
+
: null,
|
|
810
|
+
plan: {
|
|
811
|
+
...planInfo,
|
|
812
|
+
// 实际出片格数:minGap 会把"要 16 格"压成 8 格,清单必须两个数都给,
|
|
813
|
+
// 否则首行写 16、末尾写 total 8,读起来像是出错了。
|
|
814
|
+
produced: cellRanges.length,
|
|
815
|
+
bursts: findBursts(relCuts, winDur).map((b) => ({
|
|
816
|
+
from: +(b.from + winStart).toFixed(2), to: +(b.to + winStart).toFixed(2),
|
|
817
|
+
shots: b.shots, density: b.density,
|
|
818
|
+
})),
|
|
819
|
+
},
|
|
820
|
+
sheets: out,
|
|
821
|
+
totalDuration,
|
|
822
|
+
};
|
|
823
|
+
|
|
824
|
+
// 记下"这一格 = 这段绝对时间",供 video_zoom({ cellId }) 直接寻址(清单里的 t_start 是窗口相对值)。
|
|
825
|
+
// 不 await:写失败不该影响出图,寻址会退回 from/to。
|
|
826
|
+
if (!textOnly) {
|
|
827
|
+
const cellTimes = [];
|
|
828
|
+
for (const sheet of out) {
|
|
829
|
+
for (const c of sheet.cells) {
|
|
830
|
+
cellTimes.push({ i: c.i, from: c.t_start + winStart, to: c.t_end + winStart });
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
// 必须 await:紧接着的 video_zoom({cellId}) 可能立刻来查;saveCells 自己吞写失败,
|
|
834
|
+
// 不会影响出图。URL 输入还要拿原始 URL 当别名(此时 input 已是下载到本地的路径)。
|
|
835
|
+
await saveCells([inputRaw, input].filter(Boolean), cellTimes);
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
return result;
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
/* ---- 兼容入口 ---------------------------------------------------------------
|
|
842
|
+
* `./pipeline` 是 package.json 里公开的子路径(老版本把清单渲染也放在这里)。
|
|
843
|
+
* 内部代码一律直接从 format.js / frames.js / scan.js 取;这一段只为不让已经
|
|
844
|
+
* `import { formatManifest } from 'dsh-video-storyboard/pipeline'` 的调用方断掉。
|
|
845
|
+
*/
|
|
846
|
+
export {
|
|
847
|
+
DETAIL_CHARS, buildEvidence, countTextInSilence, formatForDetail, formatManifest,
|
|
848
|
+
formatProbe, formatRemoteProbe, formatTimeline, saveStoryboards, truncateAtSentence,
|
|
849
|
+
withSheetSuffix,
|
|
850
|
+
} from './format.js';
|
|
851
|
+
export { chooseSubGrid } from './frames.js';
|
|
852
|
+
export { refineCutsByWindow } from './scan.js';
|
|
853
|
+
|