mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-23 19:48:39 +00:00
feat(agent): improve timestamp precision and proxy selection for video screenshots (#374)
This commit is contained in:
@@ -107,4 +107,63 @@ describe('takeVideoScreenshotsWorkflow', () => {
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it('should prefer highest-resolution video transcode proxy over master storageKey', async () => {
|
||||
const task: WorkflowTask = {
|
||||
id: 'task-screenshot-proxy',
|
||||
assetId: 'asset-video-proxy',
|
||||
type: WorkflowTaskType.transcode_screenshot,
|
||||
status: WorkflowTaskStatus.pending,
|
||||
sessionId: null,
|
||||
output: null,
|
||||
payload: {
|
||||
projectId: 'proj-1',
|
||||
screenshot: {
|
||||
start: 1.2345,
|
||||
end: 1.2345,
|
||||
count: 1,
|
||||
commentTimestamp: 1.2345,
|
||||
annotations: [],
|
||||
},
|
||||
},
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
heartbeat: null,
|
||||
teamId: 'team-1',
|
||||
projectId: 'proj-1',
|
||||
uid: 'task-uid',
|
||||
model: null,
|
||||
inputTokens: 0,
|
||||
outputTokens: 0,
|
||||
}
|
||||
|
||||
mockActivities.getAssetActivity.mockResolvedValue({
|
||||
id: 'asset-video-proxy',
|
||||
storageKey: { key: 'raw-master.mp4' },
|
||||
mediaType: 'video/mp4',
|
||||
media: {
|
||||
videoTranscodes: [
|
||||
{ key: 'proxy-720p.mp4', height: 720, width: 1280 },
|
||||
{ key: 'proxy-1080p.mp4', height: 1080, width: 1920 },
|
||||
{ key: 'proxy-360p.mp4', height: 360, width: 640 },
|
||||
],
|
||||
},
|
||||
})
|
||||
|
||||
mockActivities.takeScreenshotsActivity.mockResolvedValue([
|
||||
{ key: 'files/asset-video-proxy/screenshots/shot1.webp', timestamp: 1.2345 },
|
||||
])
|
||||
|
||||
await takeVideoScreenshotsWorkflow(task)
|
||||
|
||||
expect(mockActivities.takeScreenshotsActivity).toHaveBeenCalledWith({
|
||||
assetKey: 'proxy-1080p.mp4',
|
||||
assetId: 'asset-video-proxy',
|
||||
start: 1.2345,
|
||||
end: 1.2345,
|
||||
count: 1,
|
||||
commentTimestamp: 1.2345,
|
||||
annotations: [],
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -17,10 +17,23 @@ export async function takeVideoScreenshotsWorkflow(task: WorkflowTask): Promise<
|
||||
}
|
||||
|
||||
const { asset, key } = await fetchAssetWithKey(workerQueue, task.assetId)
|
||||
let targetKey = key
|
||||
if (asset?.media) {
|
||||
const mediaInfo = asset.media as unknown as PrismaJson.MediaInfo
|
||||
if (mediaInfo.videoTranscodes && mediaInfo.videoTranscodes.length > 0) {
|
||||
const sorted = [...mediaInfo.videoTranscodes]
|
||||
.filter((t) => t.key)
|
||||
.sort((a, b) => (b.height || 0) - (a.height || 0))
|
||||
if (sorted.length > 0 && sorted[0].key) {
|
||||
targetKey = sorted[0].key
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const { takeScreenshotsActivity } = getActivities()
|
||||
|
||||
const screenshots = await executeActivity(workerQueue, takeScreenshotsActivity, {
|
||||
assetKey: key,
|
||||
assetKey: targetKey,
|
||||
assetId: asset.id,
|
||||
start: payload.screenshot.start,
|
||||
end: payload.screenshot.end,
|
||||
|
||||
Reference in New Issue
Block a user