Skip to content

Commit 91de06e

Browse files
committed
Remove old motion photo video assets when a new one is extracted
1 parent 8769506 commit 91de06e

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

Diff for: server/src/domain/metadata/metadata.service.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ export class MetadataService {
354354
}
355355

356356
private async applyMotionPhotos(asset: AssetEntity, tags: ImmichTags) {
357-
if (asset.type !== AssetType.IMAGE || asset.livePhotoVideoId) {
357+
if (asset.type !== AssetType.IMAGE) {
358358
return;
359359
}
360360

@@ -381,7 +381,11 @@ export class MetadataService {
381381
length = videoOffset;
382382
}
383383

384-
if (!length) {
384+
if (
385+
length === 0 &&
386+
tags.MotionPhotoVideo === undefined &&
387+
(tags.EmbeddedVideoFile === undefined || tags.EmbeddedVideoType !== 'MotionPhoto_Data')
388+
) {
385389
return;
386390
}
387391

@@ -392,11 +396,11 @@ export class MetadataService {
392396
const position = stat.size - length - padding;
393397
let video: Buffer;
394398
// Samsung MotionPhoto video extraction
395-
// HEIC-encoded
399+
// HEIC-encoded
396400
if (tags.MotionPhotoVideo) {
397401
video = await this.repository.extractBinaryTag(asset.originalPath, 'MotionPhotoVideo');
398402
}
399-
// JPEG-encoded; HEIC also contains these tags, so this conditional must come second
403+
// JPEG-encoded; HEIC also contains these tags, so this conditional must come second
400404
else if (tags.EmbeddedVideoType === 'MotionPhoto_Data' && tags.EmbeddedVideoFile) {
401405
video = await this.repository.extractBinaryTag(asset.originalPath, 'EmbeddedVideoFile');
402406
}
@@ -436,6 +440,11 @@ export class MetadataService {
436440
await this.jobRepository.queue({ name: JobName.METADATA_EXTRACTION, data: { id: motionAsset.id } });
437441
}
438442

443+
if (asset.livePhotoVideoId) {
444+
await this.jobRepository.queue({ name: JobName.ASSET_DELETION, data: { id: asset.livePhotoVideoId } });
445+
this.logger.log(`Removed old motion photo video asset (${asset.livePhotoVideoId})`);
446+
}
447+
439448
await this.assetRepository.save({ id: asset.id, livePhotoVideoId: motionAsset.id });
440449

441450
this.logger.debug(`Finished motion photo video extraction (${asset.id})`);

0 commit comments

Comments
 (0)