@@ -354,7 +354,7 @@ export class MetadataService {
354
354
}
355
355
356
356
private async applyMotionPhotos ( asset : AssetEntity , tags : ImmichTags ) {
357
- if ( asset . type !== AssetType . IMAGE || asset . livePhotoVideoId ) {
357
+ if ( asset . type !== AssetType . IMAGE ) {
358
358
return ;
359
359
}
360
360
@@ -381,7 +381,11 @@ export class MetadataService {
381
381
length = videoOffset ;
382
382
}
383
383
384
- if ( ! length ) {
384
+ if (
385
+ length === 0 &&
386
+ tags . MotionPhotoVideo === undefined &&
387
+ ( tags . EmbeddedVideoFile === undefined || tags . EmbeddedVideoType !== 'MotionPhoto_Data' )
388
+ ) {
385
389
return ;
386
390
}
387
391
@@ -392,11 +396,11 @@ export class MetadataService {
392
396
const position = stat . size - length - padding ;
393
397
let video : Buffer ;
394
398
// Samsung MotionPhoto video extraction
395
- // HEIC-encoded
399
+ // HEIC-encoded
396
400
if ( tags . MotionPhotoVideo ) {
397
401
video = await this . repository . extractBinaryTag ( asset . originalPath , 'MotionPhotoVideo' ) ;
398
402
}
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
400
404
else if ( tags . EmbeddedVideoType === 'MotionPhoto_Data' && tags . EmbeddedVideoFile ) {
401
405
video = await this . repository . extractBinaryTag ( asset . originalPath , 'EmbeddedVideoFile' ) ;
402
406
}
@@ -436,6 +440,23 @@ export class MetadataService {
436
440
await this . jobRepository . queue ( { name : JobName . METADATA_EXTRACTION , data : { id : motionAsset . id } } ) ;
437
441
}
438
442
443
+ if ( asset . livePhotoVideoId ) {
444
+ const old_asset = await this . assetRepository . getById ( asset . livePhotoVideoId ) ;
445
+ if ( old_asset ) {
446
+ try {
447
+ await this . assetRepository . remove ( old_asset ) ;
448
+ await this . storageRepository . unlink ( old_asset . originalPath ) ;
449
+ } catch ( error : Error | any ) {
450
+ this . logger . error ( `Failed to remove old asset ${ old_asset . originalPath } : ${ error } ` , error ?. stack ) ;
451
+ }
452
+ this . logger . log ( `Removed old motion photo video asset (${ old_asset . id } )` ) ;
453
+ } else {
454
+ this . logger . warn (
455
+ `Tried to remove old motion photo video but asset did not exist (${ asset . livePhotoVideoId } )` ,
456
+ ) ;
457
+ }
458
+ }
459
+
439
460
await this . assetRepository . save ( { id : asset . id , livePhotoVideoId : motionAsset . id } ) ;
440
461
441
462
this . logger . debug ( `Finished motion photo video extraction (${ asset . id } )` ) ;
0 commit comments