dsh-drawai 0.4.0 → 0.4.2

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.
Files changed (45) hide show
  1. package/LICENSE +430 -418
  2. package/README.md +96 -249
  3. package/lib/audio-media.js +5 -2
  4. package/lib/client.js +45 -12
  5. package/lib/drawing-runner.js +6 -4
  6. package/lib/ffmpeg-manager.js +1056 -0
  7. package/lib/index.js +7719 -7396
  8. package/lib/motion/apply.js +4 -3
  9. package/lib/motion/asset-pack.js +394 -335
  10. package/lib/motion/assets.js +4 -3
  11. package/lib/motion/beats.js +3 -2
  12. package/lib/motion/collect.js +3 -1
  13. package/lib/motion/delivery.js +29 -1
  14. package/lib/motion/demo-assets-lock.js +10 -0
  15. package/lib/motion/ffmpeg.js +5 -4
  16. package/lib/motion/jobs.js +5 -1
  17. package/lib/motion/mgstyles/vendor/README.md +28 -0
  18. package/lib/motion/mgstyles/vendor/modules/d3/LICENSE +13 -0
  19. package/lib/motion/mgstyles/vendor/modules/d3/dist/d3.min.js +2 -0
  20. package/lib/motion/mgstyles/vendor/modules/opentype.js/LICENSE +20 -0
  21. package/lib/motion/mgstyles/vendor/modules/opentype.js/dist/opentype.mjs +14460 -0
  22. package/lib/motion/mgstyles/vendor/modules/simplex-noise/LICENSE +21 -0
  23. package/lib/motion/mgstyles/vendor/modules/simplex-noise/dist/esm/simplex-noise.js +466 -0
  24. package/lib/motion/mgstyles/vendor/modules/topojson-client/LICENSE +13 -0
  25. package/lib/motion/mgstyles/vendor/modules/topojson-client/dist/topojson-client.min.js +2 -0
  26. package/lib/motion/preview.js +13 -4
  27. package/lib/motion/render.js +179 -159
  28. package/lib/motion/runtime/package-lock.json +3058 -0
  29. package/lib/motion/runtime/package.json +16 -0
  30. package/lib/motion/style-frames.js +306 -268
  31. package/lib/motion/sync.js +214 -214
  32. package/lib/motion/video-runtime.js +192 -0
  33. package/lib/motion-capture.js +2 -1
  34. package/lib/motion-film-review.js +2 -2
  35. package/lib/motion-project.js +105 -79
  36. package/lib/motion-render-worker.js +174 -144
  37. package/lib/motion-vision.js +3 -2
  38. package/lib/routing/router.js +222 -211
  39. package/lib/routing/vendor/README.md +96 -96
  40. package/lib/routing/vendor/libavoid-routing.js +753 -753
  41. package/lib/routing/vendor/libavoid.min.js +59 -59
  42. package/lib/shotcard-reference.js +2 -2
  43. package/lib/style-kernel.js +16 -6
  44. package/lib/video-export.js +32 -20
  45. package/package.json +17 -12
@@ -13,7 +13,7 @@ import { promisify } from 'node:util'
13
13
  import { open as openFile } from 'node:fs/promises'
14
14
  import { chmodSync, closeSync, copyFileSync, existsSync, mkdirSync, openSync, readSync, readFileSync, readdirSync, statSync, unlinkSync, writeFileSync } from 'node:fs'
15
15
  import { basename, extname, join } from 'node:path'
16
- import { ffmpegBinary } from '../video-export.js'
16
+ import { ensureFfmpeg } from '../ffmpeg-manager.js'
17
17
  import { parseProjectJson } from './json.js'
18
18
 
19
19
  const exec = promisify(execFile)
@@ -27,8 +27,9 @@ const MAX_BYTES = 24 * 1024 * 1024
27
27
  const MAX_VIDEO_BYTES = 256 * 1024 * 1024
28
28
  export const MEDIA_EXT = new Set([...IMAGE_EXT, ...AUDIO_EXT, ...VIDEO_EXT, ...VECTOR_EXT])
29
29
 
30
- function run(args, options = {}) {
31
- return exec(ffmpegBinary(), args, { windowsHide: true, timeout: 60000, maxBuffer: 8 * 1024 * 1024, ...options })
30
+ async function run(args, options = {}) {
31
+ const binary = await ensureFfmpeg({ signal: options.signal })
32
+ return exec(binary, args, { windowsHide: true, timeout: 60000, maxBuffer: 8 * 1024 * 1024, ...options })
32
33
  }
33
34
 
34
35
  export function assetsDirectory(projectDir) {
@@ -11,7 +11,7 @@
11
11
  import { execFile } from 'node:child_process'
12
12
  import { promisify } from 'node:util'
13
13
  import { existsSync } from 'node:fs'
14
- import { ffmpegBinary } from '../video-export.js'
14
+ import { ensureFfmpeg } from '../ffmpeg-manager.js'
15
15
 
16
16
  const exec = promisify(execFile)
17
17
  const SAMPLE_RATE = 22050
@@ -20,7 +20,8 @@ const WINDOW = 1024
20
20
 
21
21
  export async function decodePcm(file) {
22
22
  if (!existsSync(file)) throw new Error('找不到音频文件:' + file)
23
- const { stdout } = await exec(ffmpegBinary(), ['-hide_banner', '-loglevel', 'error', '-i', file, '-vn', '-ac', '1', '-ar', String(SAMPLE_RATE), '-f', 's16le', '-'], { encoding: 'buffer', windowsHide: true, timeout: 120000, maxBuffer: 256 * 1024 * 1024 })
23
+ const binary = await ensureFfmpeg()
24
+ const { stdout } = await exec(binary, ['-hide_banner', '-loglevel', 'error', '-i', file, '-vn', '-ac', '1', '-ar', String(SAMPLE_RATE), '-f', 's16le', '-'], { encoding: 'buffer', windowsHide: true, timeout: 120000, maxBuffer: 256 * 1024 * 1024 })
24
25
  return { pcm: stdout, sampleRate: SAMPLE_RATE, hop: HOP, window: WINDOW }
25
26
  }
26
27
 
@@ -12,7 +12,7 @@
12
12
  //
13
13
  // 抓下来的每一条都带 source URL,交付时能说清"这张图哪来的"。
14
14
 
15
- import { openBrowser } from '@remotion/renderer'
15
+ import { loadVideoModule } from './video-runtime.js'
16
16
  import { createHash } from 'node:crypto'
17
17
  import { mkdirSync, writeFileSync } from 'node:fs'
18
18
  import { join } from 'node:path'
@@ -303,6 +303,7 @@ export async function collectPageAssets(projectDir, rawUrl, options = {}) {
303
303
  const minWidth = clamp(options.minWidth || 240, 40, 2000)
304
304
 
305
305
  mkdirSync(join(projectDir, '.out'), { recursive: true })
306
+ const { openBrowser } = await loadVideoModule('@remotion/renderer', options)
306
307
  const browser = await openBrowser('chrome', { browserExecutable: browserExecutable(), logLevel: 'error' })
307
308
  let scan
308
309
  try {
@@ -367,6 +368,7 @@ export async function gatherAssets(projectDir, options = {}) {
367
368
  mkdirSync(join(projectDir, '.out'), { recursive: true })
368
369
  const scans = []
369
370
  const failedPages = []
371
+ const { openBrowser } = await loadVideoModule('@remotion/renderer', options)
370
372
  const browser = await openBrowser('chrome', { browserExecutable: browserExecutable(), logLevel: 'error' })
371
373
  try {
372
374
  let index = 0
@@ -16,9 +16,13 @@ const POLISH = `#!/usr/bin/env node
16
16
  // node tools/polish.mjs --web 平台版:1080p / 720p,crf 18,faststart
17
17
  // node tools/polish.mjs --vertical 竖版:等比缩放 + 模糊底,抖音/Reels
18
18
  // node tools/polish.mjs --loudness 只量响度,不产出文件
19
+ //
20
+ // FFmpeg 查找顺序:DRAWAI_FFMPEG_PATH → FFMPEG_PATH → PATH → DrawAI 缓存
21
+ // (~/.dsh/drawai-ffmpeg/<平台>-<架构>/,可用 DRAWAI_FFMPEG_DIR 覆盖)。
19
22
 
20
23
  import { spawnSync } from 'node:child_process'
21
24
  import { existsSync, mkdirSync, readFileSync } from 'node:fs'
25
+ import { homedir } from 'node:os'
22
26
  import { dirname, join, resolve } from 'node:path'
23
27
  import { fileURLToPath } from 'node:url'
24
28
 
@@ -26,7 +30,31 @@ const here = dirname(fileURLToPath(import.meta.url))
26
30
  const project = resolve(here, '..')
27
31
  const source = join(project, '.out', 'film.mp4')
28
32
  const dist = join(project, 'dist')
29
- const ffmpeg = process.env.FFMPEG_PATH || 'ffmpeg'
33
+
34
+ // 查找顺序与插件一致:显式路径 → 旧环境变量 → PATH → DrawAI 的独立缓存。
35
+ // 显式路径无效时直接报错,不会悄悄换成别的 FFmpeg。
36
+ function usable(candidate) {
37
+ if (!candidate) return false
38
+ const result = spawnSync(candidate, ['-hide_banner', '-version'], { stdio: 'ignore' })
39
+ return !result.error && result.status === 0
40
+ }
41
+ function resolveFfmpeg() {
42
+ const explicit = process.env.DRAWAI_FFMPEG_PATH
43
+ if (explicit) {
44
+ if (!usable(explicit)) {
45
+ console.error('DRAWAI_FFMPEG_PATH 指定的 FFmpeg 不可用:' + explicit + '。请修正这个路径,或删除这个环境变量,让脚本使用 PATH / DrawAI 缓存。')
46
+ process.exit(1)
47
+ }
48
+ return explicit
49
+ }
50
+ for (const candidate of [process.env.FFMPEG_PATH, 'ffmpeg']) if (usable(candidate)) return candidate
51
+ const cacheRoot = process.env.DRAWAI_FFMPEG_DIR || join(homedir(), '.dsh', 'drawai-ffmpeg')
52
+ const cached = join(cacheRoot, process.platform + '-' + process.arch, process.platform === 'win32' ? 'ffmpeg.exe' : 'ffmpeg')
53
+ if (usable(cached)) return cached
54
+ console.error('找不到 FFmpeg:先在 DrawAI 里导出一次视频(首次使用会自动下载并校验),或把 ffmpeg 加入 PATH,或设置 DRAWAI_FFMPEG_PATH 指向可执行文件。')
55
+ process.exit(1)
56
+ }
57
+ const ffmpeg = resolveFfmpeg()
30
58
 
31
59
  if (!existsSync(source)) {
32
60
  console.error('找不到成片:' + source + '(先 motion_render start 渲整片)')
@@ -0,0 +1,10 @@
1
+ // 由 tools/build-demo-assets-pack.mjs 生成,勿手改。
2
+ export const DEMO_ASSETS_LOCK = {
3
+ "version": "v1",
4
+ "file": "drawai-demo-assets-v1.tar.gz",
5
+ "bytes": 169794,
6
+ "sha256": "05a6fb947cb71bf51af309134d3d83a978dd5a6eb1ce1799779eb4346d519bce",
7
+ "files": 1,
8
+ "rawBytes": 549376,
9
+ "builtAt": "2026-11-08T16:48:01.972Z"
10
+ }
@@ -6,11 +6,12 @@
6
6
  import { existsSync, openSync, closeSync, readFileSync } from 'node:fs'
7
7
  import { join, isAbsolute } from 'node:path'
8
8
  import { spawn } from 'node:child_process'
9
- import { ffmpegBinary } from '../video-export.js'
9
+ import { ensureFfmpeg, ffmpegPathSync } from '../ffmpeg-manager.js'
10
10
 
11
- export function runFfmpeg(args, options = {}) {
11
+ export async function runFfmpeg(args, options = {}) {
12
12
  const cwd = options.cwd || process.cwd()
13
13
  const logPath = isAbsolute(options.log || '') ? options.log : join(cwd, options.log || 'ff.log')
14
+ const binary = options.binary || await ensureFfmpeg({ signal: options.signal, onProgress: options.onProgress })
14
15
  return new Promise((resolve, reject) => {
15
16
  let fd
16
17
  try {
@@ -19,7 +20,7 @@ export function runFfmpeg(args, options = {}) {
19
20
  reject(error)
20
21
  return
21
22
  }
22
- const child = spawn(ffmpegBinary(), ['-hide_banner', '-nostdin', '-y', ...args], {
23
+ const child = spawn(binary, ['-hide_banner', '-nostdin', '-y', ...args], {
23
24
  cwd, windowsHide: true, stdio: ['ignore', 'ignore', fd],
24
25
  })
25
26
  const timer = setTimeout(() => child.kill(), options.timeoutMs || 300000)
@@ -38,5 +39,5 @@ export function runFfmpeg(args, options = {}) {
38
39
  }
39
40
 
40
41
  export function ffmpegAvailable() {
41
- return existsSync(ffmpegBinary())
42
+ return existsSync(ffmpegPathSync())
42
43
  }
@@ -62,9 +62,13 @@ export class RenderJobs {
62
62
  }
63
63
 
64
64
  // 进度只在内存里刷:每 1% 写一次盘既慢又没意义。
65
- progress(job, phase, value) {
65
+ progress(job, phase, value, message) {
66
+ const changed = phase && phase !== job.phase
66
67
  if (phase) job.phase = phase
68
+ if (message) job.message = message
69
+ else if (changed) job.message = ''
67
70
  if (Number.isFinite(value)) job.progress = value
71
+ if (changed) this.save(job)
68
72
  return job
69
73
  }
70
74
 
@@ -0,0 +1,28 @@
1
+ # vendored demo 依赖
2
+
3
+ `upstream/demos/*/index.html` 的 importmap 和 `<script src>` 指向 `/node_modules/*`。这些包不在
4
+ 视频运行时(`src/motion/runtime/package.json`)的依赖里,装到用户机器上就无从服务,于是
5
+ `mg_style action:"frames"` 直接报「依赖没装在本机」(issue #27)。
6
+
7
+ 这里按**原包内路径**放好被引用的构建产物,`src/motion/style-frames.js` 在服务 `/node_modules/*`
8
+ 时先查视频运行时、再回落到本目录,所以用户什么都不用装。
9
+
10
+ ```
11
+ modules/<包名>/<包内原路径>
12
+ ```
13
+
14
+ | 包 | 版本 | 文件 | 许可证 |
15
+ | --- | --- | --- | --- |
16
+ | d3 | 7.9.0 | `d3/dist/d3.min.js` | ISC(见 `d3/LICENSE`) |
17
+ | topojson-client | 3.1.0 | `topojson-client/dist/topojson-client.min.js` | ISC(见 `topojson-client/LICENSE`) |
18
+ | opentype.js | 1.3.4 | `opentype.js/dist/opentype.mjs` | MIT(见 `opentype.js/LICENSE`) |
19
+ | simplex-noise | 4.0.3 | `simplex-noise/dist/esm/simplex-noise.js` | MIT(见 `simplex-noise/LICENSE`) |
20
+
21
+ - 只用到的文件放进来了,没有整包拷(约 780 KB)。
22
+ - 目录叫 `modules` 而不是 `node_modules`:npm 打包会无条件跳过任何名为 `node_modules` 的目录,
23
+ 那样 vendored 文件进不了 tarball。`.gitignore` / `.npmignore` 里给了 `dist/` 的例外规则,
24
+ 否则这几个文件会被当成构建产物忽略。
25
+ - `opentype.js` 1.3.4 的 ESM 构建叫 `dist/opentype.module.js`,demo 按 `dist/opentype.mjs` 引用,
26
+ 所以这里用前者的内容放到后者的文件名下;升级时按同样规则替换。
27
+ - `three` 不在这里:视频运行时的依赖清单已包含 three 0.183.2,`/node_modules/three/*` 由运行时提供。
28
+ - 升级包时同步改本表版本号,并重跑 `node tools/check-package.mjs`(它校验这几个文件是否存在)。
@@ -0,0 +1,13 @@
1
+ Copyright 2010-2023 Mike Bostock
2
+
3
+ Permission to use, copy, modify, and/or distribute this software for any purpose
4
+ with or without fee is hereby granted, provided that the above copyright notice
5
+ and this permission notice appear in all copies.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
9
+ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
11
+ OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
12
+ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
13
+ THIS SOFTWARE.