mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-19 14:16:29 +00:00
* feat(transcode): add multi-resolution strategy with configurable ladders and fallback * feat(settings): show toast on settings update and add manual verification plan to PR template * fix(webui): preserve video resolution and fix 480p label in download dropdowns * fix(webui): display standard short-side resolution for vertical videos in seekbar * fix(webui): fix portrait transcode resolution labeling and serialize settings toggles
878 lines
26 KiB
TypeScript
878 lines
26 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
import { transcodeVideoWorkflow } from './transcode-video'
|
|
import { WorkflowTask, WorkflowTaskStatus, WorkflowTaskType, AssetStatus } from '@shumai/db'
|
|
import * as workflowUtils from '@shumai/workflow-core'
|
|
|
|
vi.mock('@shumai/workflow-core', async (importOriginal) => {
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
const actual = (await importOriginal()) as any
|
|
return {
|
|
...actual,
|
|
getActivities: vi.fn(),
|
|
executeActivity: vi.fn(),
|
|
sleep: vi.fn(),
|
|
}
|
|
})
|
|
|
|
describe('transcodeVideoWorkflow', () => {
|
|
const mockActivities = {
|
|
updateTaskStatusActivity: Object.assign(vi.fn(), {
|
|
_activityName: 'updateTaskStatusActivity',
|
|
}),
|
|
updateAssetStatusActivity: Object.assign(vi.fn(), {
|
|
_activityName: 'updateAssetStatusActivity',
|
|
}),
|
|
getAssetActivity: Object.assign(vi.fn(), { _activityName: 'getAssetActivity' }),
|
|
getMediaInfoActivity: Object.assign(vi.fn(), { _activityName: 'getMediaInfoActivity' }),
|
|
transcodeVideoActivity: Object.assign(vi.fn(), { _activityName: 'transcodeVideoActivity' }),
|
|
transcodeHlsActivity: Object.assign(vi.fn(), { _activityName: 'transcodeHlsActivity' }),
|
|
transcodeAudioActivity: Object.assign(vi.fn(), { _activityName: 'transcodeAudioActivity' }),
|
|
transcodeImageActivity: Object.assign(vi.fn(), { _activityName: 'transcodeImageActivity' }),
|
|
generateSpriteActivity: Object.assign(vi.fn(), { _activityName: 'generateSpriteActivity' }),
|
|
updateAssetMediaActivity: Object.assign(vi.fn(), {
|
|
_activityName: 'updateAssetMediaActivity',
|
|
}),
|
|
getTranscodeWorkerQueueActivity: Object.assign(vi.fn(), {
|
|
_activityName: 'getTranscodeWorkerQueueActivity',
|
|
}),
|
|
downloadMediaToTmpActivity: Object.assign(vi.fn(), {
|
|
_activityName: 'downloadMediaToTmpActivity',
|
|
}),
|
|
cleanupTmpDirActivity: Object.assign(vi.fn(), { _activityName: 'cleanupTmpDirActivity' }),
|
|
createEmbeddingTaskIfEnabledActivity: Object.assign(vi.fn(), {
|
|
_activityName: 'createEmbeddingTaskIfEnabledActivity',
|
|
}),
|
|
createAutofillTaskIfEnabledActivity: Object.assign(vi.fn(), {
|
|
_activityName: 'createAutofillTaskIfEnabledActivity',
|
|
}),
|
|
extractPosterActivity: Object.assign(vi.fn(), {
|
|
_activityName: 'extractPosterActivity',
|
|
}),
|
|
}
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
;(workflowUtils.getActivities as any).mockReturnValue(mockActivities)
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
;(workflowUtils.executeActivity as any).mockImplementation(
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
(_queue: string, fn: any, ...args: any[]) => {
|
|
if (typeof fn !== 'function') {
|
|
throw new Error(`fn is not a function in executeActivity. Queue: ${_queue}`)
|
|
}
|
|
return fn(...args)
|
|
},
|
|
)
|
|
|
|
mockActivities.getTranscodeWorkerQueueActivity.mockResolvedValue('transcode_worker_queue')
|
|
mockActivities.downloadMediaToTmpActivity.mockResolvedValue({
|
|
filePath: '/tmp/video.mp4',
|
|
tmpDir: '/tmp',
|
|
})
|
|
mockActivities.extractPosterActivity.mockResolvedValue({
|
|
poster: { key: 'files/asset-1/poster.webp', width: 1920, height: 1080 },
|
|
})
|
|
})
|
|
|
|
it('should process video transcode successfully', async () => {
|
|
const task: WorkflowTask = {
|
|
id: 'task-1',
|
|
assetId: 'asset-1',
|
|
type: WorkflowTaskType.transcode_video,
|
|
status: WorkflowTaskStatus.pending,
|
|
sessionId: null,
|
|
output: null,
|
|
payload: {
|
|
projectId: 'proj-1',
|
|
transcode: {
|
|
videoStrategy: 'best_match',
|
|
thumbnail: true,
|
|
},
|
|
},
|
|
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-1',
|
|
storageKey: { key: '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,
|
|
hasAudio: false,
|
|
format: {},
|
|
},
|
|
videoTranscodes: [],
|
|
imageTranscodes: [],
|
|
})
|
|
|
|
mockActivities.transcodeVideoActivity.mockResolvedValue({
|
|
key: 'v.mp4',
|
|
width: 1920,
|
|
height: 1080,
|
|
})
|
|
mockActivities.transcodeImageActivity.mockResolvedValue({
|
|
key: 't.webp',
|
|
width: 300,
|
|
height: 300,
|
|
})
|
|
|
|
await transcodeVideoWorkflow(task)
|
|
|
|
expect(mockActivities.updateAssetStatusActivity).toHaveBeenCalledWith({
|
|
assetId: 'asset-1',
|
|
status: AssetStatus.processing,
|
|
})
|
|
|
|
expect(mockActivities.updateAssetMediaActivity).toHaveBeenCalledWith({
|
|
assetId: 'asset-1',
|
|
mediaInfo: expect.objectContaining({
|
|
thumbnail: expect.objectContaining({
|
|
key: 't.webp',
|
|
}),
|
|
}),
|
|
})
|
|
expect(mockActivities.updateAssetStatusActivity).toHaveBeenCalledWith({
|
|
assetId: 'asset-1',
|
|
status: AssetStatus.processed,
|
|
})
|
|
|
|
expect(mockActivities.createEmbeddingTaskIfEnabledActivity).toHaveBeenCalledWith({
|
|
assetId: 'asset-1',
|
|
teamId: 'team-1',
|
|
projectId: 'proj-1',
|
|
})
|
|
|
|
expect(mockActivities.transcodeVideoActivity).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
assetKey: 'video.mp4',
|
|
filePath: '/tmp/video.mp4',
|
|
hardwareAcceleration: undefined,
|
|
}),
|
|
)
|
|
|
|
expect(mockActivities.updateTaskStatusActivity).toHaveBeenCalledWith({
|
|
taskId: 'task-1',
|
|
status: WorkflowTaskStatus.completed,
|
|
})
|
|
})
|
|
|
|
it('should forward hardwareAcceleration to transcodeVideoActivity when specified', async () => {
|
|
const task: WorkflowTask = {
|
|
id: 'task-hw',
|
|
assetId: 'asset-hw',
|
|
type: WorkflowTaskType.transcode_video,
|
|
status: WorkflowTaskStatus.pending,
|
|
sessionId: null,
|
|
output: null,
|
|
payload: {
|
|
projectId: 'proj-1',
|
|
transcode: {
|
|
videoStrategy: 'best_match',
|
|
hardwareAcceleration: 'auto',
|
|
threads: 8,
|
|
},
|
|
},
|
|
createdAt: new Date(),
|
|
updatedAt: new Date(),
|
|
heartbeat: null,
|
|
teamId: 'team-1',
|
|
projectId: 'proj-1',
|
|
uid: 'task-uid-hw',
|
|
model: null,
|
|
inputTokens: 0,
|
|
outputTokens: 0,
|
|
}
|
|
|
|
mockActivities.getAssetActivity.mockResolvedValue({
|
|
id: 'asset-hw',
|
|
storageKey: { key: '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: {},
|
|
},
|
|
videoTranscodes: [],
|
|
imageTranscodes: [],
|
|
})
|
|
|
|
mockActivities.transcodeVideoActivity.mockResolvedValue({
|
|
key: 'v.mp4',
|
|
width: 1920,
|
|
height: 1080,
|
|
})
|
|
|
|
await transcodeVideoWorkflow(task)
|
|
|
|
expect(mockActivities.transcodeVideoActivity).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
assetKey: 'video.mp4',
|
|
filePath: '/tmp/video.mp4',
|
|
hardwareAcceleration: 'auto',
|
|
sourceVideoBitrate: 850000,
|
|
threads: 8,
|
|
}),
|
|
)
|
|
})
|
|
|
|
it('should run audio transcoding workflow successfully', async () => {
|
|
const task: WorkflowTask = {
|
|
id: 'task-audio',
|
|
assetId: 'asset-audio',
|
|
type: WorkflowTaskType.transcode_video,
|
|
status: WorkflowTaskStatus.pending,
|
|
sessionId: null,
|
|
output: null,
|
|
payload: {
|
|
projectId: 'proj-1',
|
|
transcode: {
|
|
threads: 4,
|
|
},
|
|
},
|
|
createdAt: new Date(),
|
|
updatedAt: new Date(),
|
|
heartbeat: null,
|
|
teamId: 'team-1',
|
|
projectId: 'proj-1',
|
|
uid: 'task-uid-2',
|
|
model: null,
|
|
inputTokens: 0,
|
|
outputTokens: 0,
|
|
}
|
|
|
|
mockActivities.getAssetActivity.mockResolvedValue({
|
|
id: 'asset-audio',
|
|
storageKey: { key: 'audio.wav' },
|
|
mediaType: 'audio/wav',
|
|
})
|
|
|
|
mockActivities.getMediaInfoActivity.mockResolvedValue({
|
|
proxyType: 'audio',
|
|
metadata: {
|
|
originalWidth: 0,
|
|
originalHeight: 0,
|
|
duration: 30,
|
|
bitRate: 1411200,
|
|
frameRate: 0,
|
|
totalFrames: 0,
|
|
hasAudio: true,
|
|
audioCodec: 'pcm_s16le',
|
|
audioChannels: 2,
|
|
},
|
|
original: {
|
|
key: 'audio.wav',
|
|
filesizeInBytes: 0,
|
|
codec: '',
|
|
},
|
|
videoTranscodes: [],
|
|
})
|
|
|
|
mockActivities.transcodeAudioActivity.mockResolvedValue({
|
|
width: 0,
|
|
height: 0,
|
|
key: 'files/asset-audio/audio-audio-proxy.mp4',
|
|
})
|
|
|
|
await transcodeVideoWorkflow(task)
|
|
|
|
expect(mockActivities.transcodeAudioActivity).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
assetKey: 'audio.wav',
|
|
filePath: '/tmp/video.mp4',
|
|
threads: 4,
|
|
}),
|
|
)
|
|
|
|
expect(mockActivities.updateAssetMediaActivity).toHaveBeenCalledWith({
|
|
assetId: 'asset-audio',
|
|
mediaInfo: expect.objectContaining({
|
|
proxyType: 'audio',
|
|
videoTranscodes: [
|
|
{
|
|
width: 0,
|
|
height: 0,
|
|
key: 'files/asset-audio/audio-audio-proxy.mp4',
|
|
},
|
|
],
|
|
}),
|
|
})
|
|
|
|
expect(mockActivities.updateTaskStatusActivity).toHaveBeenCalledWith({
|
|
taskId: 'task-audio',
|
|
status: WorkflowTaskStatus.completed,
|
|
})
|
|
})
|
|
|
|
it('should extract poster upfront when spec.poster is true', async () => {
|
|
const task: WorkflowTask = {
|
|
id: 'task-poster',
|
|
assetId: 'asset-poster',
|
|
type: WorkflowTaskType.transcode_video,
|
|
status: WorkflowTaskStatus.pending,
|
|
sessionId: null,
|
|
output: null,
|
|
payload: {
|
|
projectId: 'proj-1',
|
|
transcode: {
|
|
poster: true,
|
|
videoStrategy: 'best_match',
|
|
},
|
|
},
|
|
createdAt: new Date(),
|
|
updatedAt: new Date(),
|
|
heartbeat: null,
|
|
teamId: 'team-1',
|
|
projectId: 'proj-1',
|
|
uid: 'task-uid-poster',
|
|
model: null,
|
|
inputTokens: 0,
|
|
outputTokens: 0,
|
|
}
|
|
|
|
mockActivities.getAssetActivity.mockResolvedValue({
|
|
id: 'asset-poster',
|
|
storageKey: { key: 'files/asset-poster/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,
|
|
hasAudio: false,
|
|
format: {},
|
|
},
|
|
videoTranscodes: [],
|
|
imageTranscodes: [],
|
|
})
|
|
|
|
mockActivities.extractPosterActivity.mockResolvedValue({
|
|
poster: { key: 'files/asset-poster/poster.webp', width: 1920, height: 1080 },
|
|
})
|
|
|
|
await transcodeVideoWorkflow(task)
|
|
|
|
expect(mockActivities.extractPosterActivity).toHaveBeenCalledWith({
|
|
assetKey: 'files/asset-poster/video.mp4',
|
|
posterSpec: {
|
|
key: 'files/asset-poster/poster.webp',
|
|
},
|
|
taskId: 'task-poster',
|
|
})
|
|
|
|
expect(mockActivities.updateAssetMediaActivity).toHaveBeenCalledWith({
|
|
assetId: 'asset-poster',
|
|
mediaInfo: expect.objectContaining({
|
|
poster: { key: 'files/asset-poster/poster.webp', width: 1920, height: 1080 },
|
|
}),
|
|
})
|
|
})
|
|
|
|
it('should persist poster/sprite before transcoding proxies so previews are available early', async () => {
|
|
const task: WorkflowTask = {
|
|
id: 'task-sprite',
|
|
assetId: 'asset-sprite',
|
|
type: WorkflowTaskType.transcode_video,
|
|
status: WorkflowTaskStatus.pending,
|
|
sessionId: null,
|
|
output: null,
|
|
payload: {
|
|
projectId: 'proj-1',
|
|
transcode: {
|
|
poster: true,
|
|
sprite: true,
|
|
videoStrategy: 'best_match',
|
|
},
|
|
},
|
|
createdAt: new Date(),
|
|
updatedAt: new Date(),
|
|
heartbeat: null,
|
|
teamId: 'team-1',
|
|
projectId: 'proj-1',
|
|
uid: 'task-uid-sprite',
|
|
model: null,
|
|
inputTokens: 0,
|
|
outputTokens: 0,
|
|
}
|
|
|
|
mockActivities.getAssetActivity.mockResolvedValue({
|
|
id: 'asset-sprite',
|
|
storageKey: { key: 'files/asset-sprite/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,
|
|
hasAudio: false,
|
|
format: {},
|
|
},
|
|
videoTranscodes: [],
|
|
imageTranscodes: [],
|
|
})
|
|
|
|
mockActivities.extractPosterActivity.mockResolvedValue({
|
|
poster: { key: 'files/asset-sprite/poster.webp' },
|
|
})
|
|
mockActivities.generateSpriteActivity.mockResolvedValue({
|
|
sprite: { key: 'files/asset-sprite/sprite.webp', frames: 100, tileX: 10, tileY: 10 },
|
|
poster: { key: 'files/asset-sprite/poster.webp' },
|
|
})
|
|
mockActivities.transcodeVideoActivity.mockResolvedValue({
|
|
key: 'files/asset-sprite/video-180p.mp4',
|
|
width: 320,
|
|
height: 180,
|
|
})
|
|
|
|
// Capture a snapshot of the media payload at each commit: the workflow mutates the same
|
|
// `mediaInfo` object in place, so the recorded mock call args would reflect the final state.
|
|
const commitSnapshots: Array<{ sprite?: unknown; videoTranscodes: unknown[] }> = []
|
|
mockActivities.updateAssetMediaActivity.mockImplementation(
|
|
(params: { mediaInfo: { sprite?: unknown; videoTranscodes?: unknown[] } }) => {
|
|
commitSnapshots.push({
|
|
sprite: params.mediaInfo.sprite,
|
|
videoTranscodes: [...(params.mediaInfo.videoTranscodes ?? [])],
|
|
})
|
|
return Promise.resolve()
|
|
},
|
|
)
|
|
|
|
await transcodeVideoWorkflow(task)
|
|
|
|
const spriteOrder = mockActivities.generateSpriteActivity.mock.invocationCallOrder[0]
|
|
const firstProxyOrder = mockActivities.transcodeVideoActivity.mock.invocationCallOrder[0]
|
|
|
|
// Sprite generation must run before any proxy transcode.
|
|
expect(spriteOrder).toBeLessThan(firstProxyOrder)
|
|
|
|
// The media commit that carries the sprite must land before the first proxy transcode too,
|
|
// and must not yet contain any proxy transcodes.
|
|
const spriteCommitIndex = commitSnapshots.findIndex((snapshot) => snapshot.sprite !== undefined)
|
|
expect(spriteCommitIndex).toBeGreaterThanOrEqual(0)
|
|
expect(commitSnapshots[spriteCommitIndex].videoTranscodes).toEqual([])
|
|
|
|
expect(
|
|
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,
|
|
})
|
|
})
|
|
|
|
it('should trigger HLS transcoding when hlsEnabled is true', async () => {
|
|
const task: WorkflowTask = {
|
|
id: 'task-hls',
|
|
assetId: 'asset-hls',
|
|
type: WorkflowTaskType.transcode_video,
|
|
status: WorkflowTaskStatus.pending,
|
|
sessionId: null,
|
|
output: null,
|
|
payload: {
|
|
projectId: 'proj-1',
|
|
transcode: {
|
|
videoStrategy: 'best_match',
|
|
hlsEnabled: true,
|
|
hlsResolutions: ['480p', '720p', '1080p'],
|
|
},
|
|
},
|
|
createdAt: new Date(),
|
|
updatedAt: new Date(),
|
|
heartbeat: null,
|
|
teamId: 'team-1',
|
|
projectId: 'proj-1',
|
|
uid: 'task-uid-hls',
|
|
model: null,
|
|
inputTokens: 0,
|
|
outputTokens: 0,
|
|
}
|
|
|
|
mockActivities.getAssetActivity.mockResolvedValue({
|
|
id: 'asset-hls',
|
|
storageKey: { key: 'files/asset-hls/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: {},
|
|
},
|
|
videoTranscodes: [],
|
|
imageTranscodes: [],
|
|
})
|
|
|
|
mockActivities.transcodeVideoActivity.mockResolvedValue({
|
|
key: 'files/asset-hls/video-1080p.mp4',
|
|
width: 1920,
|
|
height: 1080,
|
|
resolution: '1080p',
|
|
})
|
|
|
|
mockActivities.transcodeHlsActivity.mockResolvedValue({
|
|
key: 'files/asset-hls/hls/master.m3u8',
|
|
resolutions: ['1080p', '720p', '480p'],
|
|
})
|
|
|
|
await transcodeVideoWorkflow(task)
|
|
|
|
expect(mockActivities.transcodeHlsActivity).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
taskId: 'task-hls',
|
|
assetKey: 'files/asset-hls/video.mp4',
|
|
filePath: '/tmp/video.mp4',
|
|
ladders: ['1080p', '720p', '480p'],
|
|
originalWidth: 1920,
|
|
originalHeight: 1080,
|
|
}),
|
|
)
|
|
|
|
expect(mockActivities.updateAssetMediaActivity).toHaveBeenCalledWith({
|
|
assetId: 'asset-hls',
|
|
mediaInfo: expect.objectContaining({
|
|
isHls: true,
|
|
hls: {
|
|
key: 'files/asset-hls/hls/master.m3u8',
|
|
resolutions: ['1080p', '720p', '480p'],
|
|
},
|
|
}),
|
|
})
|
|
|
|
expect(mockActivities.updateTaskStatusActivity).toHaveBeenCalledWith({
|
|
taskId: 'task-hls',
|
|
status: WorkflowTaskStatus.completed,
|
|
})
|
|
})
|
|
|
|
it('should transcode selected multi resolutions when videoStrategy is multi', () => {
|
|
const task: WorkflowTask = {
|
|
id: 'task-multi',
|
|
assetId: 'asset-multi',
|
|
type: WorkflowTaskType.transcode_video,
|
|
status: WorkflowTaskStatus.pending,
|
|
sessionId: null,
|
|
output: null,
|
|
payload: {
|
|
projectId: 'proj-1',
|
|
transcode: {
|
|
videoStrategy: 'multi',
|
|
videoResolutions: ['720p', '1080p', '2160p'],
|
|
},
|
|
},
|
|
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-multi',
|
|
storageKey: { key: 'files/asset-multi/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,
|
|
hasAudio: false,
|
|
format: {},
|
|
},
|
|
videoTranscodes: [],
|
|
imageTranscodes: [],
|
|
})
|
|
|
|
mockActivities.transcodeVideoActivity.mockImplementation(async (params) => ({
|
|
key: `files/asset-multi/${params.videoSpec.resolution}.mp4`,
|
|
width: params.videoSpec.width,
|
|
height: params.videoSpec.height,
|
|
resolution: params.videoSpec.resolution,
|
|
}))
|
|
|
|
return transcodeVideoWorkflow(task).then(() => {
|
|
// 180p preview + 1080p + 720p (2160p is skipped since > 1920)
|
|
expect(mockActivities.transcodeVideoActivity).toHaveBeenCalledTimes(3)
|
|
|
|
expect(mockActivities.transcodeVideoActivity).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
videoSpec: expect.objectContaining({ resolution: '180p' }),
|
|
}),
|
|
)
|
|
expect(mockActivities.transcodeVideoActivity).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
videoSpec: expect.objectContaining({ resolution: '1080p' }),
|
|
}),
|
|
)
|
|
expect(mockActivities.transcodeVideoActivity).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
videoSpec: expect.objectContaining({ resolution: '720p' }),
|
|
}),
|
|
)
|
|
})
|
|
})
|
|
})
|