refactor: 视频提取进度实时更新卡片,不再刷日志面板
- 主进程通过 video:progress IPC 推送当前帧数 - 前端监听进度事件,直接更新视频芯片的 meta 文本 - 日志面板只保留开始和完成两条记录
This commit is contained in:
+5
-5
@@ -569,15 +569,15 @@ function extractVideoFrames(filePath: string, maxFrames: number, maxWidth: numbe
|
||||
});
|
||||
child.stderr?.on('data', (data: Buffer) => {
|
||||
ffmpegStderr += data.toString();
|
||||
// 实时解析进度 frame=\d+
|
||||
const progressMatch = ffmpegStderr.match(/frame=\s*(\d+)/g);
|
||||
if (progressMatch) {
|
||||
const last = progressMatch[progressMatch.length - 1];
|
||||
// 实时推送进度到渲染进程(每秒一次,覆盖更新)
|
||||
const match = ffmpegStderr.match(/frame=\s*(\d+)/g);
|
||||
if (match) {
|
||||
const last = match[match.length - 1];
|
||||
const currentFrame = parseInt(last.replace(/\D/g, ''));
|
||||
if (currentFrame > lastProgressFrame && Date.now() - lastProgressTime > 1000) {
|
||||
lastProgressFrame = currentFrame;
|
||||
lastProgressTime = Date.now();
|
||||
sendLog('debug', `🎬 提取进度`, `${currentFrame} 帧`);
|
||||
mainWindow?.webContents.send('video:progress', { current: currentFrame });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
+7
-1
@@ -127,6 +127,12 @@ contextBridge.exposeInMainWorld('metonaDesktop', {
|
||||
},
|
||||
video: {
|
||||
extractFrames: (filePath: string, options?: { maxFrames?: number; maxWidth?: number; maxSize?: number }) =>
|
||||
ipcRenderer.invoke('video:extractFrames', filePath, options)
|
||||
ipcRenderer.invoke('video:extractFrames', filePath, options),
|
||||
onProgress: (callback: (data: { current: number }) => void) => {
|
||||
ipcRenderer.on('video:progress', (_: unknown, data: { current: number }) => callback(data));
|
||||
},
|
||||
removeProgressListener: () => {
|
||||
ipcRenderer.removeAllListeners('video:progress');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user