mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-23 06:06:37 +00:00
feat(transcode): add HDR video proxy support and playback (#424)
* feat(transcode): add HDR output proxy support * fix(transcode): auto-detect MoltenVK Vulkan ICD on macOS for libplacebo filters * fix(transcode): split filter in generateSprite to ensure poster uses tone-mapped stream * docs(changelog): update docs/changelog.mdx and ignore in prettier * fix(transcode): respect video rotation metadata to preserve display aspect ratio * fix(webui): render native video with hardware EDR acceleration instead of 2D canvas * fix(webui): show HDR label on mobile video control bar * fix(share): preserve hdr flag on watermarked video transcodes * fix(webui): differentiate HDR download options in video player * fix(transcode): handle Dolby Vision Profile 5 via standard HDR pipeline without libplacebo * fix(transcode): prepend setparams filter to prevent zscale colorspace path error for DV P5 * refactor(transcode): simplify HDR proxies to always produce HDR without SDR setting
This commit is contained in:
@@ -168,4 +168,58 @@ describe('takeVideoScreenshotsWorkflow', () => {
|
||||
annotations: [],
|
||||
})
|
||||
})
|
||||
|
||||
it('should prioritize SDR proxy over higher-resolution HDR proxy to avoid washed-out annotations', async () => {
|
||||
const task: WorkflowTask = {
|
||||
id: 'task-screenshot-sdr-prioritized',
|
||||
assetId: 'asset-video-hdr',
|
||||
type: WorkflowTaskType.transcode_screenshot,
|
||||
status: WorkflowTaskStatus.pending,
|
||||
sessionId: null,
|
||||
output: null,
|
||||
payload: {
|
||||
projectId: 'proj-1',
|
||||
screenshot: {
|
||||
start: 2.0,
|
||||
end: 2.0,
|
||||
count: 1,
|
||||
commentTimestamp: 2.0,
|
||||
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-hdr',
|
||||
storageKey: { key: 'raw-hdr.mp4' },
|
||||
mediaType: 'video/mp4',
|
||||
media: {
|
||||
videoTranscodes: [
|
||||
{ key: 'proxy-1080p-hdr.mp4', height: 1080, width: 1920, hdr: true },
|
||||
{ key: 'proxy-720p.mp4', height: 720, width: 1280, hdr: false },
|
||||
],
|
||||
},
|
||||
})
|
||||
|
||||
mockActivities.takeScreenshotsActivity.mockResolvedValue([
|
||||
{ key: 'files/asset-video-hdr/screenshots/shot1.webp', timestamp: 2.0 },
|
||||
])
|
||||
|
||||
await takeVideoScreenshotsWorkflow(task)
|
||||
|
||||
expect(mockActivities.takeScreenshotsActivity).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
assetKey: 'proxy-720p.mp4',
|
||||
}),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -23,7 +23,12 @@ export async function takeVideoScreenshotsWorkflow(task: WorkflowTask): Promise<
|
||||
if (mediaInfo.videoTranscodes && mediaInfo.videoTranscodes.length > 0) {
|
||||
const sorted = [...mediaInfo.videoTranscodes]
|
||||
.filter((t) => t.key)
|
||||
.sort((a, b) => (b.height || 0) - (a.height || 0))
|
||||
.sort((a, b) => {
|
||||
// Prioritize SDR over HDR to avoid washed out screenshots
|
||||
if (!a.hdr && b.hdr) return -1
|
||||
if (a.hdr && !b.hdr) return 1
|
||||
return (b.height || 0) - (a.height || 0)
|
||||
})
|
||||
if (sorted.length > 0 && sorted[0].key) {
|
||||
targetKey = sorted[0].key
|
||||
}
|
||||
|
||||
@@ -497,4 +497,209 @@ describe('transcodeVideoWorkflow', () => {
|
||||
mockActivities.updateAssetMediaActivity.mock.invocationCallOrder[spriteCommitIndex],
|
||||
).toBeLessThan(firstProxyOrder)
|
||||
})
|
||||
|
||||
it('should transcode only HDR proxies and HDR 180p preview when source is HDR', async () => {
|
||||
const task: WorkflowTask = {
|
||||
id: 'task-hdr',
|
||||
assetId: 'asset-hdr',
|
||||
type: WorkflowTaskType.transcode_video,
|
||||
status: WorkflowTaskStatus.pending,
|
||||
sessionId: null,
|
||||
output: null,
|
||||
payload: {
|
||||
projectId: 'proj-1',
|
||||
transcode: {
|
||||
videoStrategy: 'best_match',
|
||||
poster: true,
|
||||
},
|
||||
},
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
heartbeat: null,
|
||||
teamId: 'team-1',
|
||||
projectId: 'proj-1',
|
||||
uid: 'task-uid-hdr',
|
||||
model: null,
|
||||
inputTokens: 0,
|
||||
outputTokens: 0,
|
||||
}
|
||||
|
||||
mockActivities.getAssetActivity.mockResolvedValue({
|
||||
id: 'asset-hdr',
|
||||
storageKey: { key: 'hdr-video.mp4' },
|
||||
mediaType: 'video/mp4',
|
||||
})
|
||||
|
||||
mockActivities.getMediaInfoActivity.mockResolvedValue({
|
||||
proxyType: 'video',
|
||||
metadata: {
|
||||
originalWidth: 1920,
|
||||
originalHeight: 1080,
|
||||
duration: 10,
|
||||
frameRate: 30,
|
||||
totalFrames: 300,
|
||||
startTimecode: '00:00:00:00',
|
||||
bitRate: 1000,
|
||||
videoBitRate: 850000,
|
||||
hasAudio: false,
|
||||
format: {},
|
||||
isHdr: true,
|
||||
hdrType: 'pq',
|
||||
colorTransfer: 'smpte2084',
|
||||
colorPrimaries: 'bt2020',
|
||||
colorSpace: 'bt2020nc',
|
||||
},
|
||||
videoTranscodes: [],
|
||||
imageTranscodes: [],
|
||||
})
|
||||
|
||||
mockActivities.transcodeVideoActivity.mockImplementation(async (params) => {
|
||||
return {
|
||||
key: `files/asset-hdr/video-${params.videoSpec.resolution}${params.videoSpec.hdr ? '-hdr' : ''}.mp4`,
|
||||
width: params.videoSpec.width,
|
||||
height: params.videoSpec.height,
|
||||
resolution: params.videoSpec.resolution,
|
||||
hdr: params.videoSpec.hdr,
|
||||
}
|
||||
})
|
||||
|
||||
await transcodeVideoWorkflow(task)
|
||||
|
||||
// Poster extraction must use SDR tone mapping
|
||||
expect(mockActivities.extractPosterActivity).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
isHdr: true,
|
||||
hdrType: 'pq',
|
||||
colorTransfer: 'smpte2084',
|
||||
}),
|
||||
)
|
||||
|
||||
// 180p preview must be generated as HDR (hdr: true)
|
||||
expect(mockActivities.transcodeVideoActivity).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
videoSpec: expect.objectContaining({
|
||||
resolution: '180p',
|
||||
hdr: true,
|
||||
}),
|
||||
}),
|
||||
)
|
||||
|
||||
// Main resolution (1080p) must be called as HDR (hdr: true)
|
||||
expect(mockActivities.transcodeVideoActivity).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
videoSpec: expect.objectContaining({
|
||||
resolution: '1080p',
|
||||
hdr: true,
|
||||
}),
|
||||
}),
|
||||
)
|
||||
|
||||
// No calls should have been made with hdr: false for HDR source
|
||||
const calls = mockActivities.transcodeVideoActivity.mock.calls
|
||||
const sdrCalls = calls.filter(
|
||||
(c: unknown[]) => (c[0] as { videoSpec: { hdr?: boolean } }).videoSpec.hdr === false,
|
||||
)
|
||||
expect(sdrCalls).toHaveLength(0)
|
||||
|
||||
expect(mockActivities.updateTaskStatusActivity).toHaveBeenCalledWith({
|
||||
taskId: 'task-hdr',
|
||||
status: WorkflowTaskStatus.completed,
|
||||
})
|
||||
})
|
||||
|
||||
it('should transcode only SDR proxy and SDR 180p preview when source is SDR', async () => {
|
||||
const task: WorkflowTask = {
|
||||
id: 'task-sdr-source',
|
||||
assetId: 'asset-sdr-source',
|
||||
type: WorkflowTaskType.transcode_video,
|
||||
status: WorkflowTaskStatus.pending,
|
||||
sessionId: null,
|
||||
output: null,
|
||||
payload: {
|
||||
projectId: 'proj-1',
|
||||
transcode: {
|
||||
videoStrategy: 'best_match',
|
||||
poster: true,
|
||||
},
|
||||
},
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
heartbeat: null,
|
||||
teamId: 'team-1',
|
||||
projectId: 'proj-1',
|
||||
uid: 'task-uid-sdr-source',
|
||||
model: null,
|
||||
inputTokens: 0,
|
||||
outputTokens: 0,
|
||||
}
|
||||
|
||||
mockActivities.getAssetActivity.mockResolvedValue({
|
||||
id: 'asset-sdr-source',
|
||||
storageKey: { key: 'sdr-video.mp4' },
|
||||
mediaType: 'video/mp4',
|
||||
})
|
||||
|
||||
mockActivities.getMediaInfoActivity.mockResolvedValue({
|
||||
proxyType: 'video',
|
||||
metadata: {
|
||||
originalWidth: 1920,
|
||||
originalHeight: 1080,
|
||||
duration: 10,
|
||||
frameRate: 30,
|
||||
totalFrames: 300,
|
||||
startTimecode: '00:00:00:00',
|
||||
bitRate: 1000,
|
||||
videoBitRate: 850000,
|
||||
hasAudio: false,
|
||||
format: {},
|
||||
isHdr: false,
|
||||
},
|
||||
videoTranscodes: [],
|
||||
imageTranscodes: [],
|
||||
})
|
||||
|
||||
mockActivities.transcodeVideoActivity.mockImplementation(async (params) => {
|
||||
return {
|
||||
key: `files/asset-sdr-source/video-${params.videoSpec.resolution}.mp4`,
|
||||
width: params.videoSpec.width,
|
||||
height: params.videoSpec.height,
|
||||
resolution: params.videoSpec.resolution,
|
||||
hdr: params.videoSpec.hdr,
|
||||
}
|
||||
})
|
||||
|
||||
await transcodeVideoWorkflow(task)
|
||||
|
||||
// 180p preview must be generated as SDR (hdr: false)
|
||||
expect(mockActivities.transcodeVideoActivity).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
videoSpec: expect.objectContaining({
|
||||
resolution: '180p',
|
||||
hdr: false,
|
||||
}),
|
||||
}),
|
||||
)
|
||||
|
||||
// Main resolution (1080p) must be generated as SDR (hdr: false)
|
||||
expect(mockActivities.transcodeVideoActivity).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
videoSpec: expect.objectContaining({
|
||||
resolution: '1080p',
|
||||
hdr: false,
|
||||
}),
|
||||
}),
|
||||
)
|
||||
|
||||
// No calls should have been made with hdr: true for SDR source
|
||||
const calls = mockActivities.transcodeVideoActivity.mock.calls
|
||||
const hdrCalls = calls.filter(
|
||||
(c: unknown[]) => (c[0] as { videoSpec: { hdr?: boolean } }).videoSpec.hdr === true,
|
||||
)
|
||||
expect(hdrCalls).toHaveLength(0)
|
||||
|
||||
expect(mockActivities.updateTaskStatusActivity).toHaveBeenCalledWith({
|
||||
taskId: 'task-sdr-source',
|
||||
status: WorkflowTaskStatus.completed,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -69,6 +69,9 @@ export async function transcodeVideoWorkflow(task: WorkflowTask): Promise<void>
|
||||
assetKey: key,
|
||||
posterSpec,
|
||||
taskId: task.id,
|
||||
isHdr: mediaInfo.metadata?.isHdr,
|
||||
hdrType: mediaInfo.metadata?.hdrType,
|
||||
colorTransfer: mediaInfo.metadata?.colorTransfer,
|
||||
})
|
||||
mediaInfo.poster = posterResult.poster
|
||||
await executeActivity(workerQueue, updateAssetMediaActivity, {
|
||||
@@ -129,10 +132,42 @@ export async function transcodeVideoWorkflow(task: WorkflowTask): Promise<void>
|
||||
metadata.originalHeight,
|
||||
)
|
||||
|
||||
const isHdr = Boolean(metadata.isHdr)
|
||||
|
||||
if (res === '180p') {
|
||||
const videoSpec: PrismaJson.VideoTranscode = {
|
||||
resolution: res,
|
||||
width,
|
||||
height,
|
||||
hdr: isHdr,
|
||||
}
|
||||
|
||||
const videoTranscode = await executeActivity(workerQueue, transcodeVideoActivity, {
|
||||
taskId: task.id,
|
||||
assetKey: key,
|
||||
filePath,
|
||||
videoSpec,
|
||||
duration: metadata.duration,
|
||||
originalFps: metadata.frameRate,
|
||||
hardwareAcceleration: spec.hardwareAcceleration,
|
||||
sourceVideoBitrate: metadata.videoBitRate || metadata.bitRate,
|
||||
threads: spec.threads,
|
||||
sourceIsHdr: metadata.isHdr,
|
||||
sourceHdrType: metadata.hdrType,
|
||||
sourceColorTransfer: metadata.colorTransfer,
|
||||
sourceColorPrimaries: metadata.colorPrimaries,
|
||||
sourceColorSpace: metadata.colorSpace,
|
||||
})
|
||||
|
||||
mediaInfo.videoPreview = videoTranscode
|
||||
continue
|
||||
}
|
||||
|
||||
const videoSpec: PrismaJson.VideoTranscode = {
|
||||
resolution: res,
|
||||
width,
|
||||
height,
|
||||
hdr: isHdr,
|
||||
}
|
||||
|
||||
const videoTranscode = await executeActivity(workerQueue, transcodeVideoActivity, {
|
||||
@@ -145,13 +180,14 @@ export async function transcodeVideoWorkflow(task: WorkflowTask): Promise<void>
|
||||
hardwareAcceleration: spec.hardwareAcceleration,
|
||||
sourceVideoBitrate: metadata.videoBitRate || metadata.bitRate,
|
||||
threads: spec.threads,
|
||||
sourceIsHdr: metadata.isHdr,
|
||||
sourceHdrType: metadata.hdrType,
|
||||
sourceColorTransfer: metadata.colorTransfer,
|
||||
sourceColorPrimaries: metadata.colorPrimaries,
|
||||
sourceColorSpace: metadata.colorSpace,
|
||||
})
|
||||
|
||||
if (res === '180p') {
|
||||
mediaInfo.videoPreview = videoTranscode
|
||||
} else {
|
||||
mediaInfo.videoTranscodes.push(videoTranscode)
|
||||
}
|
||||
mediaInfo.videoTranscodes.push(videoTranscode)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user