mirror of
https://github.com/immich-app/immich.git
synced 2025-05-24 01:12:58 -04:00
fix(server): use preview path for person thumbnails from videos (#18419)
use preview path for person thumbnails from videos
This commit is contained in:
parent
188188a844
commit
493b9b7a54
@ -941,6 +941,48 @@ describe(MediaService.name, () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should use preview path if video', async () => {
|
||||||
|
mocks.person.getDataForThumbnailGenerationJob.mockResolvedValue(personThumbnailStub.videoThumbnail);
|
||||||
|
mocks.media.generateThumbnail.mockResolvedValue();
|
||||||
|
const data = Buffer.from('');
|
||||||
|
const info = { width: 1000, height: 1000 } as OutputInfo;
|
||||||
|
mocks.media.decodeImage.mockResolvedValue({ data, info });
|
||||||
|
|
||||||
|
await expect(sut.handleGeneratePersonThumbnail({ id: personStub.primaryPerson.id })).resolves.toBe(
|
||||||
|
JobStatus.SUCCESS,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(mocks.person.getDataForThumbnailGenerationJob).toHaveBeenCalledWith(personStub.primaryPerson.id);
|
||||||
|
expect(mocks.storage.mkdirSync).toHaveBeenCalledWith('upload/thumbs/admin_id/pe/rs');
|
||||||
|
expect(mocks.media.decodeImage).toHaveBeenCalledWith(personThumbnailStub.newThumbnailMiddle.previewPath, {
|
||||||
|
colorspace: Colorspace.P3,
|
||||||
|
orientation: undefined,
|
||||||
|
processInvalidImages: false,
|
||||||
|
});
|
||||||
|
expect(mocks.media.generateThumbnail).toHaveBeenCalledWith(
|
||||||
|
data,
|
||||||
|
{
|
||||||
|
colorspace: Colorspace.P3,
|
||||||
|
format: ImageFormat.JPEG,
|
||||||
|
quality: 80,
|
||||||
|
crop: {
|
||||||
|
left: 238,
|
||||||
|
top: 163,
|
||||||
|
width: 274,
|
||||||
|
height: 274,
|
||||||
|
},
|
||||||
|
raw: info,
|
||||||
|
processInvalidImages: false,
|
||||||
|
size: 250,
|
||||||
|
},
|
||||||
|
'upload/thumbs/admin_id/pe/rs/person-1.jpeg',
|
||||||
|
);
|
||||||
|
expect(mocks.person.update).toHaveBeenCalledWith({
|
||||||
|
id: 'person-1',
|
||||||
|
thumbnailPath: 'upload/thumbs/admin_id/pe/rs/person-1.jpeg',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should generate a thumbnail without going negative', async () => {
|
it('should generate a thumbnail without going negative', async () => {
|
||||||
mocks.person.getDataForThumbnailGenerationJob.mockResolvedValue(personThumbnailStub.newThumbnailStart);
|
mocks.person.getDataForThumbnailGenerationJob.mockResolvedValue(personThumbnailStub.newThumbnailStart);
|
||||||
mocks.media.generateThumbnail.mockResolvedValue();
|
mocks.media.generateThumbnail.mockResolvedValue();
|
||||||
|
@ -328,15 +328,13 @@ export class MediaService extends BaseService {
|
|||||||
|
|
||||||
const { ownerId, x1, y1, x2, y2, oldWidth, oldHeight, exifOrientation, previewPath, originalPath } = data;
|
const { ownerId, x1, y1, x2, y2, oldWidth, oldHeight, exifOrientation, previewPath, originalPath } = data;
|
||||||
let inputImage: string | Buffer;
|
let inputImage: string | Buffer;
|
||||||
if (mimeTypes.isVideo(originalPath)) {
|
if (data.type === AssetType.VIDEO) {
|
||||||
if (!previewPath) {
|
if (!previewPath) {
|
||||||
this.logger.error(`Could not generate person thumbnail for video ${id}: missing preview path`);
|
this.logger.error(`Could not generate person thumbnail for video ${id}: missing preview path`);
|
||||||
return JobStatus.FAILED;
|
return JobStatus.FAILED;
|
||||||
}
|
}
|
||||||
inputImage = previewPath;
|
inputImage = previewPath;
|
||||||
}
|
} else if (image.extractEmbedded && mimeTypes.isRaw(originalPath)) {
|
||||||
|
|
||||||
if (image.extractEmbedded && mimeTypes.isRaw(originalPath)) {
|
|
||||||
const extracted = await this.extractImage(originalPath, image.preview.size);
|
const extracted = await this.extractImage(originalPath, image.preview.size);
|
||||||
inputImage = extracted ? extracted.buffer : originalPath;
|
inputImage = extracted ? extracted.buffer : originalPath;
|
||||||
} else {
|
} else {
|
||||||
|
13
server/test/fixtures/person.stub.ts
vendored
13
server/test/fixtures/person.stub.ts
vendored
@ -246,4 +246,17 @@ export const personThumbnailStub = {
|
|||||||
exifOrientation: '1',
|
exifOrientation: '1',
|
||||||
previewPath: previewFile.path,
|
previewPath: previewFile.path,
|
||||||
}),
|
}),
|
||||||
|
videoThumbnail: Object.freeze({
|
||||||
|
ownerId: userStub.admin.id,
|
||||||
|
x1: 100,
|
||||||
|
y1: 100,
|
||||||
|
x2: 200,
|
||||||
|
y2: 200,
|
||||||
|
oldHeight: 500,
|
||||||
|
oldWidth: 400,
|
||||||
|
type: AssetType.VIDEO,
|
||||||
|
originalPath: '/original/path.mp4',
|
||||||
|
exifOrientation: '1',
|
||||||
|
previewPath: previewFile.path,
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user