Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(server): extract duration from video as ISO time #6863

Merged
merged 3 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions server/src/domain/metadata/metadata.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,22 @@ describe(MetadataService.name, () => {
);
});

it('should handle duration in ISO time string', async () => {
assetMock.getByIds.mockResolvedValue([assetStub.image]);
metadataMock.readTags.mockResolvedValue({ Duration: '00:00:08.41' });

await sut.handleMetadataExtraction({ id: assetStub.image.id });

expect(assetMock.getByIds).toHaveBeenCalledWith([assetStub.image.id]);
expect(assetMock.upsertExif).toHaveBeenCalled();
expect(assetMock.save).toHaveBeenCalledWith(
expect.objectContaining({
id: assetStub.image.id,
duration: '00:00:08.410',
}),
);
});

it('should handle duration as an object without Scale', async () => {
assetMock.getByIds.mockResolvedValue([assetStub.image]);
metadataMock.readTags.mockResolvedValue({ Duration: { Value: 6.2 } });
Expand Down
6 changes: 5 additions & 1 deletion server/src/domain/metadata/metadata.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,11 +555,15 @@ export class MetadataService {
return bitsPerSample;
}

private getDuration(seconds?: number | ExifDuration): string {
private getDuration(seconds?: ImmichTags['Duration']): string {
let _seconds = seconds as number;

if (typeof seconds === 'object') {
_seconds = seconds.Value * (seconds?.Scale || 1);
} else if (typeof seconds === 'string') {
_seconds = Duration.fromISOTime(seconds).as('seconds');
}

return Duration.fromObject({ seconds: _seconds }).toFormat('hh:mm:ss.SSS');
}
}
2 changes: 1 addition & 1 deletion server/src/domain/repositories/metadata.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface ImmichTags extends Omit<Tags, 'FocalLength' | 'Duration'> {
MediaGroupUUID?: string;
ImagePixelDepth?: string;
FocalLength?: number;
Duration?: number | ExifDuration;
Duration?: number | string | ExifDuration;
EmbeddedVideoType?: string;
EmbeddedVideoFile?: BinaryField;
MotionPhotoVideo?: BinaryField;
Expand Down