@@ -291,7 +291,7 @@ export class MetadataService extends BaseService {
291291 this . assetRepository . upsertExif ( exifData ) ,
292292 this . assetRepository . update ( {
293293 id : asset . id ,
294- duration : exifTags . Duration ?. toString ( ) ?? null ,
294+ duration : this . getDuration ( exifTags ) ,
295295 localDateTime : dates . localDateTime ,
296296 fileCreatedAt : dates . dateTimeOriginal ?? undefined ,
297297 fileModifiedAt : stats . mtime ,
@@ -457,19 +457,7 @@ export class MetadataService extends BaseService {
457457 return { width, height } ;
458458 }
459459
460- private getExifTags ( asset : {
461- originalPath : string ;
462- sidecarPath : string | null ;
463- type : AssetType ;
464- } ) : Promise < ImmichTags > {
465- if ( ! asset . sidecarPath && asset . type === AssetType . Image ) {
466- return this . metadataRepository . readTags ( asset . originalPath ) ;
467- }
468-
469- return this . mergeExifTags ( asset ) ;
470- }
471-
472- private async mergeExifTags ( asset : {
460+ private async getExifTags ( asset : {
473461 originalPath : string ;
474462 sidecarPath : string | null ;
475463 type : AssetType ;
@@ -492,7 +480,11 @@ export class MetadataService extends BaseService {
492480 }
493481
494482 // prefer duration from video tags
495- delete mediaTags . Duration ;
483+ if ( videoTags ) {
484+ delete mediaTags . Duration ;
485+ }
486+
487+ // never use duration from sidecar
496488 delete sidecarTags ?. Duration ;
497489
498490 return { ...mediaTags , ...videoTags , ...sidecarTags } ;
@@ -934,6 +926,20 @@ export class MetadataService extends BaseService {
934926 return bitsPerSample ;
935927 }
936928
929+ private getDuration ( tags : ImmichTags ) : string | null {
930+ const duration = tags . Duration ;
931+
932+ if ( typeof duration === 'string' ) {
933+ return duration ;
934+ }
935+
936+ if ( typeof duration === 'number' ) {
937+ return Duration . fromObject ( { seconds : duration } ) . toFormat ( 'hh:mm:ss.SSS' ) ;
938+ }
939+
940+ return null ;
941+ }
942+
937943 private async getVideoTags ( originalPath : string ) {
938944 const { videoStreams, format } = await this . mediaRepository . probe ( originalPath ) ;
939945
@@ -961,7 +967,7 @@ export class MetadataService extends BaseService {
961967 }
962968
963969 if ( format . duration ) {
964- tags . Duration = Duration . fromObject ( { seconds : format . duration } ) . toFormat ( 'hh:mm:ss.SSS' ) ;
970+ tags . Duration = format . duration ;
965971 }
966972
967973 return tags ;
0 commit comments