dsh-gallery 0.15.0 → 0.16.3
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 +87 -0
- package/README.md +37 -5
- package/client.js +1324 -25
- package/host/clipboard.js +211 -0
- package/host/derive.js +62 -0
- package/host/http.js +448 -1
- package/host/scan.js +33 -5
- package/host/session-index.js +34 -1
- package/host/trim.js +134 -0
- package/package.json +100 -91
package/host/trim.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v0.16.0 音视频裁剪核心(从 host/http.js 抽出来,便于真机单测)。
|
|
3
|
+
*
|
|
4
|
+
* 关键事实(实测得出,别凭直觉改):
|
|
5
|
+
* · `-c copy` 只能从**关键帧**起切。6 秒 25fps 的测试片切 1.5–4s,
|
|
6
|
+
* 实际得到 0–4s(时长 4.0 而非 2.5)——起点被拉回到上一个关键帧。
|
|
7
|
+
* · 音频流通常每个包都可切,所以纯音频 copy 基本准确,问题集中在视频。
|
|
8
|
+
* · 因此策略是「先 copy,再用 ffprobe 量真实时长,偏差 > 0.5s 才重编码」:
|
|
9
|
+
* 常见情况仍是秒级无损裁剪,少数少关键帧素材才付重编码代价。
|
|
10
|
+
*/
|
|
11
|
+
import { spawn } from 'node:child_process'
|
|
12
|
+
import fsp from 'node:fs/promises'
|
|
13
|
+
import path from 'node:path'
|
|
14
|
+
|
|
15
|
+
const FFMPEG_CANDIDATES = [
|
|
16
|
+
'G:/Program Files/ffmpeg/bin/ffmpeg.exe',
|
|
17
|
+
'G:/Program Files (x86)/ffmpeg/bin/ffmpeg.exe',
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
/** 找 ffmpeg;找不到返回 'ffmpeg',交给 PATH 兜底。 */
|
|
21
|
+
export async function findFfmpeg() {
|
|
22
|
+
for (const c of FFMPEG_CANDIDATES) {
|
|
23
|
+
try {
|
|
24
|
+
const abs = path.resolve(c)
|
|
25
|
+
await fsp.access(abs, 0)
|
|
26
|
+
return abs
|
|
27
|
+
} catch { /* 换下一个 */ }
|
|
28
|
+
}
|
|
29
|
+
return 'ffmpeg'
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** 找同目录 ffprobe;找不到返回 null(退化为不做精度校验)。 */
|
|
33
|
+
export async function findFfprobe(ffmpeg) {
|
|
34
|
+
const candidates = []
|
|
35
|
+
if (typeof ffmpeg === 'string' && ffmpeg !== '' && ffmpeg !== 'ffmpeg') {
|
|
36
|
+
const dir = path.dirname(ffmpeg)
|
|
37
|
+
candidates.push(path.join(dir, 'ffprobe.exe'), path.join(dir, 'ffprobe'))
|
|
38
|
+
}
|
|
39
|
+
candidates.push('G:/Program Files/ffmpeg/bin/ffprobe.exe', 'G:/Program Files (x86)/ffmpeg/bin/ffprobe.exe')
|
|
40
|
+
for (const c of candidates) {
|
|
41
|
+
try { await fsp.access(c, 0); return c } catch { /* 换下一个 */ }
|
|
42
|
+
}
|
|
43
|
+
return null
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** 跑一次 ffmpeg;收集 stderr,非 0 退出视为失败。 */
|
|
47
|
+
export function runFfmpeg(ffmpeg, args) {
|
|
48
|
+
return new Promise((resolve, reject) => {
|
|
49
|
+
let child
|
|
50
|
+
try { child = spawn(ffmpeg, args, { windowsHide: true }) } catch (err) { reject(err); return }
|
|
51
|
+
let stderr = ''
|
|
52
|
+
child.stderr?.on('data', (d) => { stderr += String(d) })
|
|
53
|
+
child.on('error', (err) => reject(err))
|
|
54
|
+
child.on('close', (code) => {
|
|
55
|
+
if (code === 0) resolve()
|
|
56
|
+
else reject(new Error('ffmpeg exit ' + code + ': ' + stderr.slice(-800)))
|
|
57
|
+
})
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** 读媒体时长(秒);任何异常都返回 null,不抛。 */
|
|
62
|
+
export function probeDuration(ffprobe, file) {
|
|
63
|
+
return new Promise((resolve) => {
|
|
64
|
+
let child
|
|
65
|
+
try {
|
|
66
|
+
child = spawn(ffprobe, [
|
|
67
|
+
'-v', 'error', '-show_entries', 'format=duration',
|
|
68
|
+
'-of', 'default=noprint_wrappers=1:nokey=1', file,
|
|
69
|
+
], { windowsHide: true })
|
|
70
|
+
} catch { resolve(null); return }
|
|
71
|
+
let out = ''
|
|
72
|
+
child.stdout?.on('data', (d) => { out += String(d) })
|
|
73
|
+
child.on('error', () => resolve(null))
|
|
74
|
+
child.on('close', (code) => {
|
|
75
|
+
if (code !== 0) { resolve(null); return }
|
|
76
|
+
const n = Number(String(out).trim())
|
|
77
|
+
resolve(Number.isFinite(n) && n > 0 ? n : null)
|
|
78
|
+
})
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const AUDIO_EXTS = new Set(['mp3', 'wav', 'm4a', 'aac', 'flac', 'ogg', 'opus'])
|
|
83
|
+
|
|
84
|
+
/** 精度兜底用的重编码参数(按输出容器选编码器,保证扩展名与流匹配)。 */
|
|
85
|
+
export function reencodeArgs(src, start, end, out, outExt, kind) {
|
|
86
|
+
const base = ['-y', '-hide_banner', '-loglevel', 'error', '-ss', String(start), '-to', String(end), '-i', src]
|
|
87
|
+
const ext = String(outExt ?? '').toLowerCase()
|
|
88
|
+
if (AUDIO_EXTS.has(ext) || kind === 'audio') {
|
|
89
|
+
const codec = ext === 'wav' ? ['-c:a', 'pcm_s16le']
|
|
90
|
+
: ext === 'flac' ? ['-c:a', 'flac']
|
|
91
|
+
: (ext === 'ogg' || ext === 'opus') ? ['-c:a', 'libopus', '-b:a', '128k']
|
|
92
|
+
: ext === 'mp3' ? ['-c:a', 'libmp3lame', '-b:a', '192k']
|
|
93
|
+
: ['-c:a', 'aac', '-b:a', '192k']
|
|
94
|
+
return [...base, '-vn', ...codec, out]
|
|
95
|
+
}
|
|
96
|
+
if (ext === 'webm') {
|
|
97
|
+
return [...base, '-c:v', 'libvpx-vp9', '-crf', '32', '-b:v', '0', '-c:a', 'libopus', out]
|
|
98
|
+
}
|
|
99
|
+
return [...base, '-c:v', 'libx264', '-preset', 'veryfast', '-crf', '20',
|
|
100
|
+
'-pix_fmt', 'yuv420p', '-c:a', 'aac', '-b:a', '160k', '-movflags', '+faststart', out]
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* 裁一段音视频并写进 `out`。
|
|
105
|
+
*
|
|
106
|
+
* @returns {{ mode: 'copy'|'reencode'|'copy-keyframe', duration: number|null }}
|
|
107
|
+
* - copy:流拷贝且时长与期望相符(最理想)
|
|
108
|
+
* - reencode:copy 偏差过大,已重编码到精确切点
|
|
109
|
+
* - copy-keyframe:copy 有偏差且重编码失败,保留了可用但不精确的片段
|
|
110
|
+
*/
|
|
111
|
+
export async function cropMediaFile({ ffmpeg, src, start, end, out, outExt, kind }) {
|
|
112
|
+
const expected = end - start
|
|
113
|
+
await runFfmpeg(ffmpeg, [
|
|
114
|
+
'-y', '-hide_banner', '-loglevel', 'error',
|
|
115
|
+
'-ss', String(start), '-to', String(end),
|
|
116
|
+
'-i', src,
|
|
117
|
+
'-c', 'copy', '-avoid_negative_ts', 'make_zero',
|
|
118
|
+
out,
|
|
119
|
+
])
|
|
120
|
+
|
|
121
|
+
const ffprobe = await findFfprobe(ffmpeg)
|
|
122
|
+
if (ffprobe === null || !(expected > 0)) return { mode: 'copy', duration: null }
|
|
123
|
+
|
|
124
|
+
const got = await probeDuration(ffprobe, out)
|
|
125
|
+
if (got === null || Math.abs(got - expected) <= 0.5) return { mode: 'copy', duration: got }
|
|
126
|
+
|
|
127
|
+
try {
|
|
128
|
+
await runFfmpeg(ffmpeg, reencodeArgs(src, start, end, out, outExt, kind))
|
|
129
|
+
const fixed = await probeDuration(ffprobe, out)
|
|
130
|
+
return { mode: 'reencode', duration: fixed }
|
|
131
|
+
} catch {
|
|
132
|
+
return { mode: 'copy-keyframe', duration: got }
|
|
133
|
+
}
|
|
134
|
+
}
|
package/package.json
CHANGED
|
@@ -1,91 +1,100 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "dsh-gallery",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"type": "module",
|
|
5
|
-
"description": "产出台:图片 / 文件 / 音视频实时可见、当场校验;原生产出标签(素材 / 过程稿 / 定稿 / 未归类)可手动改且持久生效,改标签动作与图上圈选批注攒进反馈篮,由人审核合并后发送,全程零自动发送;视频「截取当前帧」自动存入当前对话资产;图上左键画矩形框、右键多点闭合成实心多边形,可导出 ComfyUI 直接可用的 RGBA 遮罩(选区内 alpha=0、RGB 保留原图),另出红 / 绿 / 蓝纯色半透明填充预览图供目视核对;把图拖进对话框会自动带上文件名与绝对路径(含对应主遮罩名),Agent 不必扫目录找图;批注框跟随图片缩放平移,标注态按住鼠标中键可平移且框不脱框。Output gallery for DeepSeek Harness: live image/file/audio/video preview, persistent manual asset labels, region annotations and label changes queued in a human-approved feedback basket, one-click video frame capture filed into the current session, rectangle and multi-point polygon selections exported as ComfyUI-ready RGBA masks (alpha=0 inside the selection, original RGB kept) plus a colored translucent fill preview, drag-to-chat that carries the file name and absolute path so agents need no directory scan; annotation boxes follow image zoom/pan, and holding the middle mouse button pans the image while annotating without losing the boxes.",
|
|
6
|
-
"repository": {
|
|
7
|
-
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/Hope2023Dcr/dsh-gallery.git"
|
|
9
|
-
},
|
|
10
|
-
"bugs": {
|
|
11
|
-
"url": "https://github.com/Hope2023Dcr/dsh-gallery/issues"
|
|
12
|
-
},
|
|
13
|
-
"homepage": "https://github.com/Hope2023Dcr/dsh-gallery#readme",
|
|
14
|
-
"exports": {
|
|
15
|
-
".": "./index.js",
|
|
16
|
-
"./client": "./client.js",
|
|
17
|
-
"./locale/*.json": "./locale/*.json",
|
|
18
|
-
"./icon": "./icon.svg"
|
|
19
|
-
},
|
|
20
|
-
"files": [
|
|
21
|
-
"install.mjs",
|
|
22
|
-
"index.js",
|
|
23
|
-
"client.js",
|
|
24
|
-
"session-index.js",
|
|
25
|
-
"host/*.js",
|
|
26
|
-
"cordis.patch.yml",
|
|
27
|
-
"locale/*.json",
|
|
28
|
-
"icon.svg",
|
|
29
|
-
"README.md",
|
|
30
|
-
"LICENSE",
|
|
31
|
-
"CHANGELOG.md",
|
|
32
|
-
"docs/screenshots/*.png"
|
|
33
|
-
],
|
|
34
|
-
"dsh": {
|
|
35
|
-
"bundle": {
|
|
36
|
-
"patch": "./cordis.patch.yml"
|
|
37
|
-
},
|
|
38
|
-
"client": {
|
|
39
|
-
"platform": "web",
|
|
40
|
-
"immediately": true,
|
|
41
|
-
"inject": [
|
|
42
|
-
"@deepseek-ai/dsh-client-ui-sidebar-right",
|
|
43
|
-
"@deepseek-ai/dsh-client-locale"
|
|
44
|
-
]
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
"author": {
|
|
48
|
-
"name": "Hope2023Dcr"
|
|
49
|
-
},
|
|
50
|
-
"license": "MIT",
|
|
51
|
-
"keywords": [
|
|
52
|
-
"dsh-plugin",
|
|
53
|
-
"deepseek-harness",
|
|
54
|
-
"dsh",
|
|
55
|
-
"output-gallery",
|
|
56
|
-
"image-gallery",
|
|
57
|
-
"file-preview",
|
|
58
|
-
"sidebar-plugin",
|
|
59
|
-
"agent-tools",
|
|
60
|
-
"media-gallery",
|
|
61
|
-
"video-preview",
|
|
62
|
-
"audio-preview",
|
|
63
|
-
"range-seek",
|
|
64
|
-
"filter",
|
|
65
|
-
"deliverable",
|
|
66
|
-
"human-in-the-loop",
|
|
67
|
-
"asset-tags",
|
|
68
|
-
"manual-label",
|
|
69
|
-
"feedback-basket",
|
|
70
|
-
"batch",
|
|
71
|
-
"region-selection",
|
|
72
|
-
"annotation",
|
|
73
|
-
"frame-capture",
|
|
74
|
-
"annotation-follow",
|
|
75
|
-
"middle-mouse-pan",
|
|
76
|
-
"polygon-selection",
|
|
77
|
-
"mask-export",
|
|
78
|
-
"rgba-mask",
|
|
79
|
-
"comfyui",
|
|
80
|
-
"inpainting",
|
|
81
|
-
"drag-metadata",
|
|
82
|
-
"external-assets"
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
"
|
|
90
|
-
|
|
91
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "dsh-gallery",
|
|
3
|
+
"version": "0.16.3",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "产出台:图片 / 文件 / 音视频实时可见、当场校验;原生产出标签(素材 / 过程稿 / 定稿 / 未归类)可手动改且持久生效,改标签动作与图上圈选批注攒进反馈篮,由人审核合并后发送,全程零自动发送;视频「截取当前帧」自动存入当前对话资产;图上左键画矩形框、右键多点闭合成实心多边形,可导出 ComfyUI 直接可用的 RGBA 遮罩(选区内 alpha=0、RGB 保留原图),另出红 / 绿 / 蓝纯色半透明填充预览图供目视核对;把图拖进对话框会自动带上文件名与绝对路径(含对应主遮罩名),Agent 不必扫目录找图;批注框跟随图片缩放平移,标注态按住鼠标中键可平移且框不脱框。Output gallery for DeepSeek Harness: live image/file/audio/video preview, persistent manual asset labels, region annotations and label changes queued in a human-approved feedback basket, one-click video frame capture filed into the current session, rectangle and multi-point polygon selections exported as ComfyUI-ready RGBA masks (alpha=0 inside the selection, original RGB kept) plus a colored translucent fill preview, drag-to-chat that carries the file name and absolute path so agents need no directory scan; annotation boxes follow image zoom/pan, and holding the middle mouse button pans the image while annotating without losing the boxes.",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/Hope2023Dcr/dsh-gallery.git"
|
|
9
|
+
},
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/Hope2023Dcr/dsh-gallery/issues"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/Hope2023Dcr/dsh-gallery#readme",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": "./index.js",
|
|
16
|
+
"./client": "./client.js",
|
|
17
|
+
"./locale/*.json": "./locale/*.json",
|
|
18
|
+
"./icon": "./icon.svg"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"install.mjs",
|
|
22
|
+
"index.js",
|
|
23
|
+
"client.js",
|
|
24
|
+
"session-index.js",
|
|
25
|
+
"host/*.js",
|
|
26
|
+
"cordis.patch.yml",
|
|
27
|
+
"locale/*.json",
|
|
28
|
+
"icon.svg",
|
|
29
|
+
"README.md",
|
|
30
|
+
"LICENSE",
|
|
31
|
+
"CHANGELOG.md",
|
|
32
|
+
"docs/screenshots/*.png"
|
|
33
|
+
],
|
|
34
|
+
"dsh": {
|
|
35
|
+
"bundle": {
|
|
36
|
+
"patch": "./cordis.patch.yml"
|
|
37
|
+
},
|
|
38
|
+
"client": {
|
|
39
|
+
"platform": "web",
|
|
40
|
+
"immediately": true,
|
|
41
|
+
"inject": [
|
|
42
|
+
"@deepseek-ai/dsh-client-ui-sidebar-right",
|
|
43
|
+
"@deepseek-ai/dsh-client-locale"
|
|
44
|
+
]
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"author": {
|
|
48
|
+
"name": "Hope2023Dcr"
|
|
49
|
+
},
|
|
50
|
+
"license": "MIT",
|
|
51
|
+
"keywords": [
|
|
52
|
+
"dsh-plugin",
|
|
53
|
+
"deepseek-harness",
|
|
54
|
+
"dsh",
|
|
55
|
+
"output-gallery",
|
|
56
|
+
"image-gallery",
|
|
57
|
+
"file-preview",
|
|
58
|
+
"sidebar-plugin",
|
|
59
|
+
"agent-tools",
|
|
60
|
+
"media-gallery",
|
|
61
|
+
"video-preview",
|
|
62
|
+
"audio-preview",
|
|
63
|
+
"range-seek",
|
|
64
|
+
"filter",
|
|
65
|
+
"deliverable",
|
|
66
|
+
"human-in-the-loop",
|
|
67
|
+
"asset-tags",
|
|
68
|
+
"manual-label",
|
|
69
|
+
"feedback-basket",
|
|
70
|
+
"batch",
|
|
71
|
+
"region-selection",
|
|
72
|
+
"annotation",
|
|
73
|
+
"frame-capture",
|
|
74
|
+
"annotation-follow",
|
|
75
|
+
"middle-mouse-pan",
|
|
76
|
+
"polygon-selection",
|
|
77
|
+
"mask-export",
|
|
78
|
+
"rgba-mask",
|
|
79
|
+
"comfyui",
|
|
80
|
+
"inpainting",
|
|
81
|
+
"drag-metadata",
|
|
82
|
+
"external-assets",
|
|
83
|
+
"clipboard-paste",
|
|
84
|
+
"image-crop",
|
|
85
|
+
"magnifier",
|
|
86
|
+
"media-trim",
|
|
87
|
+
"ffmpeg",
|
|
88
|
+
"audio-trim",
|
|
89
|
+
"video-trim",
|
|
90
|
+
"copy-file",
|
|
91
|
+
"viewer-shortcut"
|
|
92
|
+
],
|
|
93
|
+
"publishConfig": {
|
|
94
|
+
"access": "public",
|
|
95
|
+
"registry": "https://registry.npmjs.org/"
|
|
96
|
+
},
|
|
97
|
+
"engines": {
|
|
98
|
+
"node": ">=20"
|
|
99
|
+
}
|
|
100
|
+
}
|