fix(server): video duration extraction (#11610)

This commit is contained in:
Michel Heusschen
2024-08-06 18:27:05 +02:00
committed by GitHub
parent f040c9fb38
commit 325fb4b5d1
2 changed files with 72 additions and 53 deletions
+26 -30
View File
@@ -214,28 +214,7 @@ export class MetadataService implements OnEvents {
const { exifData, tags } = await this.exifData(asset);
if (asset.type === AssetType.VIDEO) {
const { videoStreams } = await this.mediaRepository.probe(asset.originalPath);
if (videoStreams[0]) {
switch (videoStreams[0].rotation) {
case -90: {
exifData.orientation = Orientation.Rotate90CW;
break;
}
case 0: {
exifData.orientation = Orientation.Horizontal;
break;
}
case 90: {
exifData.orientation = Orientation.Rotate270CW;
break;
}
case 180: {
exifData.orientation = Orientation.Rotate180;
break;
}
}
}
await this.applyVideoMetadata(asset, exifData);
}
await this.applyMotionPhotos(asset, tags);
@@ -252,7 +231,7 @@ export class MetadataService implements OnEvents {
}
await this.assetRepository.update({
id: asset.id,
duration: tags.Duration ? this.getDuration(tags.Duration) : null,
duration: asset.duration,
localDateTime,
fileCreatedAt: exifData.dateTimeOriginal ?? undefined,
});
@@ -567,16 +546,33 @@ export class MetadataService implements OnEvents {
return bitsPerSample;
}
private getDuration(seconds?: ImmichTags['Duration']): string {
let _seconds = seconds as number;
private async applyVideoMetadata(asset: AssetEntity, exifData: ExifEntityWithoutGeocodeAndTypeOrm) {
const { videoStreams, format } = await this.mediaRepository.probe(asset.originalPath);
if (typeof seconds === 'object') {
_seconds = seconds.Value * (seconds?.Scale || 1);
} else if (typeof seconds === 'string') {
_seconds = Duration.fromISOTime(seconds).as('seconds');
if (videoStreams[0]) {
switch (videoStreams[0].rotation) {
case -90: {
exifData.orientation = Orientation.Rotate90CW;
break;
}
case 0: {
exifData.orientation = Orientation.Horizontal;
break;
}
case 90: {
exifData.orientation = Orientation.Rotate270CW;
break;
}
case 180: {
exifData.orientation = Orientation.Rotate180;
break;
}
}
}
return Duration.fromObject({ seconds: _seconds }).toFormat('hh:mm:ss.SSS');
if (format.duration) {
asset.duration = Duration.fromObject({ seconds: format.duration }).toFormat('hh:mm:ss.SSS');
}
}
private async processSidecar(id: string, isSync: boolean): Promise<JobStatus> {