mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-22 15:18:24 +00:00
feat(transcode): add initial camera RAW image support (#435)
- Add centralized RAW file extension set and detection helper for 23 common camera RAW formats - Update getProxyType and EXTENSION_MIME_TYPES to route RAW formats into the image pipeline - Add exiftool-vendored runtime dependency and mark as external in build-npm script - Implement embedded JPEG extraction to temporary file with priority JpgFromRaw2 -> JpgFromRaw -> PreviewImage - Read and apply EXIF orientation from RAW container to prevent rotation/mirroring issues - Integrate into TranscodeService.getImageInfo and transcodeImage with proper temporary file cleanup - Add hasUsablePreview guard in transcodeImageWorkflow to gracefully handle RAW files without embedded previews - Add unit, service, workflow, and E2E tests for RAW processing
This commit is contained in:
@@ -155,4 +155,73 @@ describe('transcodeImageWorkflow', () => {
|
||||
projectId: 'proj-1',
|
||||
})
|
||||
})
|
||||
|
||||
it('should handle RAW image without usable preview by skipping transcodes and marking processed', async () => {
|
||||
const task: WorkflowTask = {
|
||||
id: 'task-raw-nopreview',
|
||||
assetId: 'asset-raw',
|
||||
type: WorkflowTaskType.transcode_image,
|
||||
status: WorkflowTaskStatus.pending,
|
||||
sessionId: null,
|
||||
output: null,
|
||||
payload: {
|
||||
projectId: 'proj-1',
|
||||
transcode: {
|
||||
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-raw',
|
||||
storageKey: { key: 'photo.cr2' },
|
||||
mediaType: 'image/x-canon-cr2',
|
||||
})
|
||||
|
||||
// RAW file without usable preview returns originalWidth: 0, originalHeight: 0
|
||||
mockActivities.getMediaInfoActivity.mockResolvedValue({
|
||||
proxyType: 'image',
|
||||
metadata: {
|
||||
originalWidth: 0,
|
||||
originalHeight: 0,
|
||||
duration: 0,
|
||||
frameRate: 0,
|
||||
totalFrames: 0,
|
||||
startTimecode: undefined,
|
||||
bitRate: 0,
|
||||
hasAudio: false,
|
||||
format: {},
|
||||
},
|
||||
videoTranscodes: [],
|
||||
imageTranscodes: [],
|
||||
})
|
||||
|
||||
await transcodeImageWorkflow(task)
|
||||
|
||||
// transcodeImageActivity should NOT be called since hasUsablePreview is false
|
||||
expect(mockActivities.transcodeImageActivity).not.toHaveBeenCalled()
|
||||
|
||||
// Asset media should still be updated
|
||||
expect(mockActivities.updateAssetMediaActivity).toHaveBeenCalledWith({
|
||||
assetId: 'asset-raw',
|
||||
mediaInfo: expect.objectContaining({
|
||||
imageTranscodes: [],
|
||||
}),
|
||||
})
|
||||
|
||||
// Asset should still be marked as processed
|
||||
expect(mockActivities.updateAssetStatusActivity).toHaveBeenCalledWith({
|
||||
assetId: 'asset-raw',
|
||||
status: AssetStatus.processed,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -54,9 +54,10 @@ export async function transcodeImageWorkflow(task: WorkflowTask): Promise<void>
|
||||
}
|
||||
|
||||
const metadata = mediaInfo.metadata
|
||||
const hasUsablePreview = metadata && metadata.originalWidth > 0 && metadata.originalHeight > 0
|
||||
|
||||
const isImage = mediaInfo.proxyType === 'image'
|
||||
if (isImage && metadata) {
|
||||
if (isImage && hasUsablePreview && metadata) {
|
||||
const imageSpec: PrismaJson.ImageTranscode = {
|
||||
width: metadata.originalWidth,
|
||||
height: metadata.originalHeight,
|
||||
@@ -71,7 +72,7 @@ export async function transcodeImageWorkflow(task: WorkflowTask): Promise<void>
|
||||
mediaInfo.imageTranscodes.push(imageTranscode)
|
||||
}
|
||||
|
||||
if (spec.thumbnail) {
|
||||
if (spec.thumbnail && hasUsablePreview) {
|
||||
const thumbTranscode = await executeActivity(workerQueue, transcodeImageActivity, {
|
||||
assetKey: key,
|
||||
filePath,
|
||||
|
||||
Reference in New Issue
Block a user