dsh-ffmpeg 0.6.4 → 0.7.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/CHANGELOG.md +10 -0
- package/README.en.md +1 -0
- package/README.md +1 -0
- package/docs/USAGE.en.md +5 -1
- package/docs/USAGE.md +5 -1
- package/lib/storyboard.d.ts +5 -0
- package/lib/storyboard.js +110 -0
- package/lib/tools.d.ts +1 -0
- package/lib/tools.js +2 -1
- package/lib/update-client.js +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,16 @@
|
|
|
4
4
|
|
|
5
5
|
[历史英文记录](docs/CHANGELOG.en.md)
|
|
6
6
|
|
|
7
|
+
## 0.7.1 (2026-10-29)
|
|
8
|
+
|
|
9
|
+
- 修复极短、分数帧率视频的采样时间取整越过最后一帧:向下取微秒精度,源文件保持不变。
|
|
10
|
+
- Avoid rounding past the final frame when sampling short fractional-frame-rate clips.
|
|
11
|
+
|
|
12
|
+
## 0.7.0 (2026-10-29)
|
|
13
|
+
|
|
14
|
+
- 新增 ffmpeg_storyboard:均匀采样并拼成单张 PNG 总览图,附每格采样目标时间;可指定片段范围,保留原视频与已有成品。失败或取消会清理临时采样,不发布半成品。
|
|
15
|
+
- Add ffmpeg_storyboard for bounded, uniform video contact sheets with per-cell target times and optional time ranges. Preserve source files and existing output; clean scratch and publish only a completed PNG.
|
|
16
|
+
|
|
7
17
|
## 0.6.4 (2026-10-29)
|
|
8
18
|
|
|
9
19
|
- 同步仓库与 npm 的简明介绍、中英文 README 和反馈入口;本次为文档与包元数据更新。
|
package/README.en.md
CHANGED
|
@@ -12,6 +12,7 @@ Feedback and contributions are welcome: report [issues](https://github.com/STARD
|
|
|
12
12
|
|
|
13
13
|
## What it does
|
|
14
14
|
|
|
15
|
+
- Create a PNG contact sheet with per-cell sample times, optional time ranges, source protection and cancellation.
|
|
15
16
|
- Inspect media and trim, join or transcode video.
|
|
16
17
|
- Fit clips with different sizes and frame rates to one canvas; silent clips receive silence without muting the other clips.
|
|
17
18
|
- Add subtitles, create GIFs and extract frames.
|
package/README.md
CHANGED
package/docs/USAGE.en.md
CHANGED
|
@@ -75,9 +75,13 @@ ffmpeg_gif { input: E:\videos\raw.mp4, duration: 3, width: 480 }
|
|
|
75
75
|
|
|
76
76
|
```bash
|
|
77
77
|
pnpm install
|
|
78
|
-
pnpm test # build +
|
|
78
|
+
pnpm test # build + 121 tests
|
|
79
79
|
```
|
|
80
80
|
|
|
81
81
|
## License
|
|
82
82
|
|
|
83
83
|
MIT
|
|
84
|
+
|
|
85
|
+
## Video contact sheet
|
|
86
|
+
|
|
87
|
+
Use `ffmpeg_storyboard({input:"movie.mp4",count:12,columns:4,width:320})` to create one PNG. Optional `start` and `end` accept seconds or HH:MM:SS.mmm. Count is 2–36, columns 1–6 and cell width 160–640. Cells use a 16:9 letterbox and preserve source aspect ratio. The tool result maps each cell to a requested seek time, not an exact decoded frame timecode. Uniform sampling does not detect scenes or guarantee coverage of short shots. Requires a seekable local video with a known duration. Sources and existing outputs are preserved by default; cancellation/failure cleans scratch and publishes no partial sheet.
|
package/docs/USAGE.md
CHANGED
|
@@ -79,9 +79,13 @@ ffmpeg_adjust { input: E:\videos\raw.mp4, volume: +2dB }
|
|
|
79
79
|
|
|
80
80
|
```bash
|
|
81
81
|
pnpm install
|
|
82
|
-
pnpm test # 构建 +
|
|
82
|
+
pnpm test # 构建 + 121 个测试
|
|
83
83
|
```
|
|
84
84
|
|
|
85
85
|
## License
|
|
86
86
|
|
|
87
87
|
MIT
|
|
88
|
+
|
|
89
|
+
## 视频总览图
|
|
90
|
+
|
|
91
|
+
调用 `ffmpeg_storyboard({input:"movie.mp4",count:12,columns:4,width:320})` 生成单张 PNG。可用 start/end 指定片段,接受秒数或 HH:MM:SS.mmm;count 为 2–36,columns 为 1–6,每格 width 为 160–640。画面按 16:9 留黑边,不拉伸原比例。工具结果附每格的采样目标时间,不是实际解码帧的精确时间码;均匀采样不等于镜头检测,也不保证覆盖所有短镜头。需要可定位、时长已知的本地视频。默认保留源文件与重名成品;取消或失败会清理临时采样,不发布半成品。
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type ResolvedFfmpegConfig } from './config.js';
|
|
2
|
+
import type { ProcessRunner } from './exec.js';
|
|
3
|
+
import type { FfmpegToolDefinition } from './tools.js';
|
|
4
|
+
/** A bounded contact sheet, assembled in private scratch before publishing its PNG. */
|
|
5
|
+
export declare function createStoryboardTool(config: ResolvedFfmpegConfig, runner: ProcessRunner): FfmpegToolDefinition;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { constants, copyFileSync, existsSync, lstatSync, mkdirSync, mkdtempSync, rmSync } from 'node:fs';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { dirname, extname, join } from 'node:path';
|
|
4
|
+
import { probeArgs } from './args.js';
|
|
5
|
+
import { parseTimeArg } from './config.js';
|
|
6
|
+
import { parseProbeJson } from './ffprobe.js';
|
|
7
|
+
import { assertInputFile, assertOutputNotSource, resolveOutputPath } from './paths.js';
|
|
8
|
+
function integer(value, fallback, min, max, name) {
|
|
9
|
+
if (value === undefined)
|
|
10
|
+
return fallback;
|
|
11
|
+
if (typeof value !== 'number' || !Number.isInteger(value) || value < min || value > max)
|
|
12
|
+
throw new Error(name + ' 必须是 ' + min + '–' + max + ' 的整数。');
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
function seconds(value, fallback, name) {
|
|
16
|
+
if (value === undefined)
|
|
17
|
+
return fallback;
|
|
18
|
+
const parsed = parseTimeArg(value);
|
|
19
|
+
if (parsed === null)
|
|
20
|
+
throw new Error(name + ' 请使用非负秒数或 HH:MM:SS.mmm。');
|
|
21
|
+
return parsed;
|
|
22
|
+
}
|
|
23
|
+
/** A bounded contact sheet, assembled in private scratch before publishing its PNG. */
|
|
24
|
+
export function createStoryboardTool(config, runner) {
|
|
25
|
+
return {
|
|
26
|
+
name: 'ffmpeg_storyboard',
|
|
27
|
+
description: '把本地视频按时长均匀采样,拼成一张 PNG 总览图,返回每格序号和采样目标秒数,便于人工或视觉模型快速检查内容。默认 12 格、4 列;不代表自动镜头识别,也不保证覆盖所有短镜头。可设置 start/end 检查片段。保留源视频;默认给重名输出另取文件名。',
|
|
28
|
+
parameters: {
|
|
29
|
+
type: 'object', additionalProperties: false, required: ['input'], properties: {
|
|
30
|
+
input: { type: 'string', description: '本地视频路径,相对当前会话工作区。' },
|
|
31
|
+
output: { type: 'string', description: 'PNG 输出路径,默认源文件旁的 <文件名>-storyboard.png。' },
|
|
32
|
+
count: { type: 'integer', minimum: 2, maximum: 36, description: '采样格数,2–36,默认 12。' },
|
|
33
|
+
columns: { type: 'integer', minimum: 1, maximum: 6, description: '列数,1–6,默认 4;不超过采样格数。' },
|
|
34
|
+
width: { type: 'integer', minimum: 160, maximum: 640, description: '每格宽度,160–640 像素,默认 320;保持比例并留黑边。' },
|
|
35
|
+
start: { oneOf: [{ type: 'number' }, { type: 'string' }], description: '开始位置,秒数或 HH:MM:SS.mmm,默认 0。' },
|
|
36
|
+
end: { oneOf: [{ type: 'number' }, { type: 'string' }], description: '结束位置,秒数或 HH:MM:SS.mmm,默认视频结尾。' },
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
output: {
|
|
40
|
+
schema: { type: 'object', additionalProperties: true, required: ['output', 'count', 'frames'], properties: { output: { type: 'string' }, count: { type: 'integer' }, frames: { type: 'array', items: { type: 'object', additionalProperties: true } } } },
|
|
41
|
+
render(_args, value) {
|
|
42
|
+
const result = value;
|
|
43
|
+
return [{ type: 'text', text: ['视频总览图:' + result.output, result.columns + ' 列 × ' + result.rows + ' 行;从左到右、从上到下。下面是采样目标时间,非逐帧时间码:', ...result.frames.map(f => '#' + f.index + '(' + f.row + ' 行 ' + f.column + ' 列):' + f.seconds + ' 秒')].join('\n') }];
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
async execute(raw, execution) {
|
|
47
|
+
const args = raw && typeof raw === 'object' && !Array.isArray(raw) ? raw : {};
|
|
48
|
+
if (typeof args.input !== 'string' || !args.input.trim())
|
|
49
|
+
throw new Error('input 请提供本地视频路径。');
|
|
50
|
+
if (args.output !== undefined && (typeof args.output !== 'string' || !args.output.trim()))
|
|
51
|
+
throw new Error('output 请提供 PNG 文件路径。');
|
|
52
|
+
const count = integer(args.count, 12, 2, 36, 'count'), columns = Math.min(count, integer(args.columns, 4, 1, 6, 'columns'));
|
|
53
|
+
const cellWidth = integer(args.width, 320, 160, 640, 'width'), cellHeight = Math.round(cellWidth * 9 / 16), rows = Math.ceil(count / columns);
|
|
54
|
+
const cwd = execution?.agent?.session?.header?.cwd || process.cwd(), input = assertInputFile(args.input, cwd);
|
|
55
|
+
const output = resolveOutputPath(input, args.output, '-storyboard', '.png', config.overwrite, cwd);
|
|
56
|
+
if (extname(output).toLowerCase() !== '.png')
|
|
57
|
+
throw new Error('视频总览图的 output 必须使用 .png 扩展名。');
|
|
58
|
+
const deadline = Date.now() + config.timeoutMs, signal = execution?.signal;
|
|
59
|
+
async function invoke(argv, label) {
|
|
60
|
+
signal?.throwIfAborted();
|
|
61
|
+
const remaining = deadline - Date.now();
|
|
62
|
+
if (remaining <= 0)
|
|
63
|
+
throw new Error('视频总览图生成超时,源文件保留。');
|
|
64
|
+
const result = await runner.run(argv, { timeoutMs: remaining, ...(signal ? { signal } : {}) });
|
|
65
|
+
signal?.throwIfAborted();
|
|
66
|
+
if (result.exitCode !== 0)
|
|
67
|
+
throw new Error(label + '失败:' + (result.stderr.trim().split(/\r?\n/).slice(-4).join(' | ') || '退出码 ' + result.exitCode));
|
|
68
|
+
return result.stdout;
|
|
69
|
+
}
|
|
70
|
+
const info = parseProbeJson(await invoke(probeArgs(config.ffprobePath, input), '读取视频信息'));
|
|
71
|
+
if (!info.video)
|
|
72
|
+
throw new Error('输入文件没有视频画面,无法生成视频总览图。');
|
|
73
|
+
const duration = info.video.durationSeconds ?? info.durationSeconds;
|
|
74
|
+
if (duration === null || !Number.isFinite(duration) || duration <= 0)
|
|
75
|
+
throw new Error('无法确定视频时长,请先用 ffmpeg_probe 检查文件。');
|
|
76
|
+
const start = seconds(args.start, 0, 'start'), end = seconds(args.end, duration, 'end');
|
|
77
|
+
if (start >= end || end > duration)
|
|
78
|
+
throw new Error('采样范围必须满足 0 ≤ start < end ≤ 视频时长(' + duration + ' 秒)。');
|
|
79
|
+
const lastFrame = info.video.fps && info.video.fps > 0 ? Math.max(0, duration - 1 / info.video.fps) : duration;
|
|
80
|
+
if (start > lastFrame)
|
|
81
|
+
throw new Error('所选范围太靠近结尾,无法取得视频帧;请提前 start。');
|
|
82
|
+
// Round down to FFmpeg's microsecond clock. Millisecond rounding can seek
|
|
83
|
+
// beyond the final frame of a short fractional-frame-rate video.
|
|
84
|
+
const frames = Array.from({ length: count }, (_, i) => ({ index: i + 1, row: Math.floor(i / columns) + 1, column: i % columns + 1, seconds: Math.floor(Math.min(lastFrame, start + (end - start) * i / count) * 1e6) / 1e6 }));
|
|
85
|
+
const scratch = mkdtempSync(join(tmpdir(), 'dsh-ffmpeg-storyboard-'));
|
|
86
|
+
try {
|
|
87
|
+
for (const frame of frames) {
|
|
88
|
+
const image = join(scratch, 'frame-' + String(frame.index).padStart(3, '0') + '.png');
|
|
89
|
+
const filter = 'scale=' + cellWidth + ':' + cellHeight + ':force_original_aspect_ratio=decrease,pad=' + cellWidth + ':' + cellHeight + ':(ow-iw)/2:(oh-ih)/2:color=black,setsar=1';
|
|
90
|
+
await invoke([config.ffmpegPath, '-nostdin', '-v', 'error', '-n', '-ss', frame.seconds.toFixed(6), '-i', input, '-map', '0:v:0', '-frames:v', '1', '-an', '-vf', filter, '-update', '1', image], '采样 #' + frame.index);
|
|
91
|
+
if (!existsSync(image) || !lstatSync(image).isFile() || lstatSync(image).size === 0)
|
|
92
|
+
throw new Error('无法取得第 ' + frame.index + ' 格(' + frame.seconds + ' 秒)的画面,请缩短采样范围后重试。');
|
|
93
|
+
}
|
|
94
|
+
const assembled = join(scratch, 'storyboard.png');
|
|
95
|
+
await invoke([config.ffmpegPath, '-nostdin', '-v', 'error', '-n', '-framerate', '1', '-start_number', '1', '-i', join(scratch, 'frame-%03d.png'), '-vf', 'tile=' + columns + 'x' + rows + ':nb_frames=' + count + ':padding=8:margin=8:color=black', '-frames:v', '1', '-update', '1', assembled], '拼接视频总览图');
|
|
96
|
+
if (!existsSync(assembled) || !lstatSync(assembled).isFile() || lstatSync(assembled).size === 0)
|
|
97
|
+
throw new Error('视频总览图未生成,输出文件保留。');
|
|
98
|
+
signal?.throwIfAborted();
|
|
99
|
+
assertOutputNotSource([input], output, cwd);
|
|
100
|
+
mkdirSync(dirname(output), { recursive: true });
|
|
101
|
+
copyFileSync(assembled, output, config.overwrite ? 0 : constants.COPYFILE_EXCL);
|
|
102
|
+
return { output, input, count, columns, rows, cellWidth, cellHeight, width: columns * cellWidth + (columns - 1) * 8 + 16, height: rows * cellHeight + (rows - 1) * 8 + 16, start, end, durationSeconds: duration, timestampKind: 'requested-seek-time', frames };
|
|
103
|
+
}
|
|
104
|
+
finally {
|
|
105
|
+
rmSync(scratch, { recursive: true, force: true });
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
timeoutMs: config.timeoutMs,
|
|
109
|
+
};
|
|
110
|
+
}
|
package/lib/tools.d.ts
CHANGED
package/lib/tools.js
CHANGED
|
@@ -12,6 +12,7 @@ import { adjustArgs, concatArgs, concatListContent, cutArgs, ENCODE_PRESETS, enc
|
|
|
12
12
|
import { parseProbeJson } from './ffprobe.js';
|
|
13
13
|
import { assertInputFile, resolveOutputPath, resolveFramePattern, sanitizeName } from './paths.js';
|
|
14
14
|
import { parseTimeArg } from './config.js';
|
|
15
|
+
import { createStoryboardTool } from './storyboard.js';
|
|
15
16
|
function executionCwd(exec) { return exec?.agent?.session?.header?.cwd || process.cwd(); }
|
|
16
17
|
/** 编译作者 DSL 为原始 JSON Schema(正是 defineTool 存为 definition.parameters 的值)。 */
|
|
17
18
|
function compileParameters(spec) {
|
|
@@ -668,5 +669,5 @@ export function buildFfmpegTools(config, runner) {
|
|
|
668
669
|
},
|
|
669
670
|
timeoutMs: 30000,
|
|
670
671
|
};
|
|
671
|
-
return [probe, cut, concat, encode, subtitle, extract, gif, frames, adjust, health];
|
|
672
|
+
return [probe, cut, concat, encode, subtitle, extract, gif, frames, createStoryboardTool(cfg, runner), adjust, health];
|
|
672
673
|
}
|
package/lib/update-client.js
CHANGED
|
@@ -437,7 +437,7 @@ function __stardustUpdatesClient(ctx, React, require, shared) {
|
|
|
437
437
|
}
|
|
438
438
|
|
|
439
439
|
/* STARDUSTLC_UPDATE_CLIENT_BODY_START */
|
|
440
|
-
window.__ModuleLoader__.load(__stardustUpdatesWrap({id:"dsh-ffmpeg",factory:require=>({apply(){}})},{"name":"dsh-ffmpeg","version":"0.1.0","hasWorkbench":false,"packageVersion":"0.
|
|
440
|
+
window.__ModuleLoader__.load(__stardustUpdatesWrap({id:"dsh-ffmpeg",factory:require=>({apply(){}})},{"name":"dsh-ffmpeg","version":"0.1.0","hasWorkbench":false,"packageVersion":"0.7.1","label":"FFmpeg","labelEn":"FFmpeg","suiteComponent":true}));
|
|
441
441
|
|
|
442
442
|
/* STARDUSTLC_UPDATE_CLIENT_BODY_END */
|
|
443
443
|
})();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-ffmpeg",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "DSH 音视频处理:本机 FFmpeg
|
|
3
|
+
"version": "0.7.1",
|
|
4
|
+
"description": "DSH 音视频处理:本机 FFmpeg 裁切、转码、字幕、音轨、GIF、抽帧与视频总览图。欢迎提交 issues 和 PR。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"types": "lib/index.d.ts",
|