API query for asset returns incorrectly formatted duration if asset is gif #7453

Closed
opened 2026-02-05 13:02:54 +03:00 by OVERLORD · 6 comments
Owner

Originally created by @VargaBenceLevente on GitHub (Oct 6, 2025).

I have searched the existing issues, both open and closed, to make sure this is not a duplicate report.

  • Yes

The bug

if I query a gif (originalMimeType: "image/gif") in the API, the duration is not given in 0:00:00.00000 format, but instead is just the number of seconds (formatted "duration": "0.98" or "duration": "2").

For video (video/mp4, recorded from an Android 10 smartphone), the result was formatted "duration": "00:00:08.475", but for an image taken with the same phone has "duration": "0:00:00.00000".

The OS that Immich Server is running on

Debian

Version of Immich Server

v2.0.1

Version of Immich Mobile App

v2.0.1

Platform with the issue

  • Server
  • Web
  • Mobile

Device make and model

API

Your docker-compose.yml content

Irrelevant

Your .env content

Irrelevant

Reproduction steps

  1. Set up API key
  2. Query the API endpoint "search/metadata" with any search term (I happened to use isArchived = true)
  3. Ensure that among the results is a gif and a video (or even image).
  4. I tried to parse the Json with C#'s Newtonsoft.Json.JsonConvert.DeserializeObject into a List with the Asset class having the following property: public TimeSpan Duration { get; set; }. This throws an error on the gifs' durations "2" or "0.98".

Example API result with gif:

{
"createdAt": "2025-03-11T04:01:27.258Z",
"deviceAssetId": "something.gif",
"deviceId": "Library Import",
"duplicateId": null,
"duration": "0.98",
"fileCreatedAt": "2020-02-09T21:33:40.000Z",
"fileModifiedAt": "2020-02-09T21:33:40.000Z",
"hasMetadata": true,
"isArchived": false,
"isFavorite": false,
"isOffline": false,
"isTrashed": false,
"livePhotoVideoId": null,
"localDateTime": "2020-02-09T21:33:40.000Z",
"originalFileName": "something.gif",
"originalMimeType": "image/gif",
"originalPath": "...../something.gif",
"people": [],
"resized": true,
"type": "IMAGE",
"updatedAt": "2025-08-17T18:44:07.290Z",
"visibility": "timeline"
I removed some fields such as IDs,
},

Other gif has "duration": "2"

Example video has "duration": "00:00:08.475", in the same query

Example image (media/jpeg) has "duration": "0:00:00.00000".

Additional information

To clarify, my query had 1000 results, since it is one page in the paginated query.

Originally created by @VargaBenceLevente on GitHub (Oct 6, 2025). ### I have searched the existing issues, both open and closed, to make sure this is not a duplicate report. - [x] Yes ### The bug if I query a gif (originalMimeType: "image/gif") in the API, the duration is not given in 0:00:00.00000 format, but instead is just the number of seconds (formatted `"duration": "0.98"` or `"duration": "2"`). For video (video/mp4, recorded from an Android 10 smartphone), the result was formatted `"duration": "00:00:08.475"`, but for an image taken with the same phone has `"duration": "0:00:00.00000"`. ### The OS that Immich Server is running on Debian ### Version of Immich Server v2.0.1 ### Version of Immich Mobile App v2.0.1 ### Platform with the issue - [x] Server - [ ] Web - [ ] Mobile ### Device make and model API ### Your docker-compose.yml content ```YAML Irrelevant ``` ### Your .env content ```Shell Irrelevant ``` ### Reproduction steps 1. Set up API key 2. Query the API endpoint "search/metadata" with any search term (I happened to use isArchived = true) 3. Ensure that among the results is a gif and a video (or even image). 4. I tried to parse the Json with C#'s Newtonsoft.Json.JsonConvert.DeserializeObject into a List<Asset> with the Asset class having the following property: `public TimeSpan Duration { get; set; }`. This throws an error on the gifs' durations "2" or "0.98". ### Example API result with gif: ``` { "createdAt": "2025-03-11T04:01:27.258Z", "deviceAssetId": "something.gif", "deviceId": "Library Import", "duplicateId": null, "duration": "0.98", "fileCreatedAt": "2020-02-09T21:33:40.000Z", "fileModifiedAt": "2020-02-09T21:33:40.000Z", "hasMetadata": true, "isArchived": false, "isFavorite": false, "isOffline": false, "isTrashed": false, "livePhotoVideoId": null, "localDateTime": "2020-02-09T21:33:40.000Z", "originalFileName": "something.gif", "originalMimeType": "image/gif", "originalPath": "...../something.gif", "people": [], "resized": true, "type": "IMAGE", "updatedAt": "2025-08-17T18:44:07.290Z", "visibility": "timeline" I removed some fields such as IDs, }, ``` Other gif has `"duration": "2"` Example video has `"duration": "00:00:08.475",` in the same query Example image (media/jpeg) has `"duration": "0:00:00.00000"`. ### Additional information To clarify, my query had 1000 results, since it is one page in the paginated query.
Author
Owner

@MontejoJorge commented on GitHub (Oct 7, 2025):

While videos convert the duration here:
966ab22065/server/src/services/metadata.service.ts (L952-L956)

and GIF is considered AssetType.Image the duration is not formatted but plain metadata tags

966ab22065/server/src/services/metadata.service.ts (L462-L464)

We could format the duration if its not undefined and other but 0

@MontejoJorge commented on GitHub (Oct 7, 2025): While videos convert the duration here: https://github.com/immich-app/immich/blob/966ab220656850d0173b4f58d2807fec0f2e0885/server/src/services/metadata.service.ts#L952-L956 and GIF is considered `AssetType.Image` the duration is not formatted but plain metadata tags https://github.com/immich-app/immich/blob/966ab220656850d0173b4f58d2807fec0f2e0885/server/src/services/metadata.service.ts#L462-L464 We could format the duration if its not `undefined` and other but 0
Author
Owner

@VargaBenceLevente commented on GitHub (Oct 7, 2025):

Even if it's 0, I would suggest that it should be formatted in a standardised way. Currently images with "livePhotoVideoId": null are formatted "duration": "0:00:00.00000" already. However, I'd suggest changing this to match the exact format Immich uses for video (hh:mm:ss.SSS) as well.

@VargaBenceLevente commented on GitHub (Oct 7, 2025): Even if it's 0, I would suggest that it should be formatted in a standardised way. Currently images with `"livePhotoVideoId": null` are formatted `"duration": "0:00:00.00000"` already. However, I'd suggest changing this to match the exact format Immich uses for video (`hh:mm:ss.SSS`) as well.
Author
Owner

@AnanthVivekanand commented on GitHub (Oct 9, 2025):

Reformatting seems straightforward, so I ran it through a tool I've been working on that runs multiple agents in parallel, this is the diffs it came up with: https://www.codearena.com/4c752bd1-f234-470d-bb31-46beb6495114

Diff seems alright. You can open a branch, pull it locally to test, and open a PR if it works as expected.

@AnanthVivekanand commented on GitHub (Oct 9, 2025): Reformatting seems straightforward, so I ran it through a tool I've been working on that runs multiple agents in parallel, this is the diffs it came up with: https://www.codearena.com/4c752bd1-f234-470d-bb31-46beb6495114 Diff seems alright. You can open a branch, pull it locally to test, and open a PR if it works as expected.
Author
Owner

@MontejoJorge commented on GitHub (Oct 9, 2025):

This is what i have: 5ada05b801 I might open a PR later this day, but seems like a good idea too @AnanthVivekanand hmmm

@MontejoJorge commented on GitHub (Oct 9, 2025): This is what i have: https://github.com/MontejoJorge/immich/commit/5ada05b801e8dab2961ea71b64429c3889270ea5 I might open a PR later this day, but seems like a good idea too @AnanthVivekanand hmmm
Author
Owner

@meesfrensel commented on GitHub (Dec 5, 2025):

The duration of animated images was being extracted and stored in the database as the number of seconds you saw. #24178 fixed that part of the duration extraction. You can run metadata extraction again on gifs to fix this data, when v2.4.0 is released.

I cannot close the issue myself, but it has been fixed in #24178.

@meesfrensel commented on GitHub (Dec 5, 2025): The duration of animated images was being extracted and stored in the database as the number of seconds you saw. #24178 fixed that part of the duration extraction. You can run metadata extraction again on gifs to fix this data, when v2.4.0 is released. I cannot close the issue myself, but it has been fixed in #24178.
Author
Owner

@VargaBenceLevente commented on GitHub (Dec 9, 2025):

Closed issue due to completion.

@VargaBenceLevente commented on GitHub (Dec 9, 2025): Closed issue due to completion.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: immich-app/immich#7453