mirror of
https://github.com/immich-app/immich.git
synced 2025-02-11 01:18:24 -05:00
fix: duration string parsing (#1923)
This commit is contained in:
parent
d5d0624311
commit
a5f49b065c
1 changed files with 11 additions and 14 deletions
|
@ -14,13 +14,16 @@ import { ConfigService } from '@nestjs/config';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { Job } from 'bull';
|
import { Job } from 'bull';
|
||||||
import { ExifDateTime, exiftool, Tags } from 'exiftool-vendored';
|
import { ExifDateTime, exiftool, Tags } from 'exiftool-vendored';
|
||||||
import ffmpeg from 'fluent-ffmpeg';
|
import ffmpeg, { FfprobeData } from 'fluent-ffmpeg';
|
||||||
import { getName } from 'i18n-iso-countries';
|
import { getName } from 'i18n-iso-countries';
|
||||||
import geocoder, { InitOptions } from 'local-reverse-geocoder';
|
import geocoder, { InitOptions } from 'local-reverse-geocoder';
|
||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import sharp from 'sharp';
|
import sharp from 'sharp';
|
||||||
import { Repository } from 'typeorm/repository/Repository';
|
import { Repository } from 'typeorm/repository/Repository';
|
||||||
|
import { promisify } from 'util';
|
||||||
|
|
||||||
|
const ffprobe = promisify<string, FfprobeData>(ffmpeg.ffprobe);
|
||||||
|
|
||||||
interface ImmichTags extends Tags {
|
interface ImmichTags extends Tags {
|
||||||
ContentIdentifier?: string;
|
ContentIdentifier?: string;
|
||||||
|
@ -255,19 +258,10 @@ export class MetadataExtractionProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const data = await new Promise<ffmpeg.FfprobeData>((resolve, reject) =>
|
const data = await ffprobe(asset.originalPath);
|
||||||
ffmpeg.ffprobe(asset.originalPath, (err, data) => {
|
const durationString = this.extractDuration(data.format.duration || asset.duration);
|
||||||
if (err) return reject(err);
|
|
||||||
return resolve(data);
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
let durationString = asset.duration;
|
|
||||||
let fileCreatedAt = asset.fileCreatedAt;
|
let fileCreatedAt = asset.fileCreatedAt;
|
||||||
|
|
||||||
if (data.format.duration) {
|
|
||||||
durationString = this.extractDuration(data.format.duration);
|
|
||||||
}
|
|
||||||
|
|
||||||
const videoTags = data.format.tags;
|
const videoTags = data.format.tags;
|
||||||
if (videoTags) {
|
if (videoTags) {
|
||||||
if (videoTags['com.apple.quicktime.creationdate']) {
|
if (videoTags['com.apple.quicktime.creationdate']) {
|
||||||
|
@ -365,8 +359,11 @@ export class MetadataExtractionProcessor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private extractDuration(duration: number) {
|
private extractDuration(duration: number | string | null) {
|
||||||
const videoDurationInSecond = parseInt(duration.toString(), 0);
|
const videoDurationInSecond = Number(duration);
|
||||||
|
if (!videoDurationInSecond) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const hours = Math.floor(videoDurationInSecond / 3600);
|
const hours = Math.floor(videoDurationInSecond / 3600);
|
||||||
const minutes = Math.floor((videoDurationInSecond - hours * 3600) / 60);
|
const minutes = Math.floor((videoDurationInSecond - hours * 3600) / 60);
|
||||||
|
|
Loading…
Add table
Reference in a new issue