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): use correct file extension for motion photo videos #8659

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

lukashass
Copy link
Contributor

@lukashass lukashass commented Apr 9, 2024

Closes #8658

Set originalFileName extension of motion assets to mp4

TODO

  • migration for existing assets

@lukashass lukashass changed the title fix(server): use mp4 file extension for motion photo videos in archive download fix(server): use correct file extension for motion photo videos in archive download Apr 9, 2024
@lukashass lukashass marked this pull request as ready for review April 9, 2024 14:43
@lukashass
Copy link
Contributor Author

@alextran1502 I saw that since #7679 the file extension for the archive download is only taken from originalFileName. Maybe a better fix than this one would be to set the correct extension in that property in the first place 🤔

@danieldietzler
Copy link
Member

Yeah, IMO originalFileName should always have the correct file name.

@lukashass
Copy link
Contributor Author

On the other hand I'm wondering if the video should be downloaded at all, since it seems to still be embedded in the downloaded jpg and thus downloaded twice.

Copy link
Contributor

@jrasm91 jrasm91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should probably fix the original filename which is wrong, no?

@lukashass
Copy link
Contributor Author

The video is extracted from the jpg on upload, so the filename is kind of correct (since it says "original").

It is a little ambiguous, that's why I'm questioning the download of the separate video altogether 🤔

@lukashass
Copy link
Contributor Author

So from what I'm reading there are motion photo formats which

  • embed the video in the jpg
  • are two separate files from the beginning

This means the correct fix for the issue is to only download a separate video when the jpg does not contain the video, right?

How would we detect that? I could think of two ways:

  • save this information (separate/embedded video) in a new property
  • compare the file extension of originalFileName of video and photo, if the same, do not download the video

@@ -96,7 +96,8 @@ export class DownloadService {

const { originalPath, originalFileName } = asset;

let filename = originalFileName;
const extension = parse(originalPath).ext;
let filename = `${parse(originalFileName).name}${extension}`;
Copy link
Contributor

@jrasm91 jrasm91 Apr 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does it have the wrong extension to begin with? I think I would rather fix the root cause instead of patching it everywhere it is used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jrasm91 I agree (sort of). Hence my comments #8659 (comment) and #8659 (comment).

What is your opinion on that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iOS doesn't have it embedded but Android does. Either way getting the extracted video might be nice when you download it. The name for the motion asset should come from the original when it is uploaded, but that should not include the extension...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A filename includes the extension (by definition), which makes it confusing as that does not match what users perceive as such.

Having said that I'd say its fair to transform the (original)filename of files when converted (thus, if I am following, never having the incorrect extension for these records at time of download).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure the old extension is coming from here:

https://github.com/immich-app/immich/blob/main/server/src/services/metadata.service.ts#L441

If you are going to fix anything, it should be here instead. It is probably possible to write a migration to fix affected files as well.

IMO we should store the correct filename and extension when the asset is created and then never touch or need to touch/modify if moving forward. The current solution also introduces the possibility of the extension case changing between upload and download.

@jrasm91 jrasm91 marked this pull request as draft May 8, 2024 03:31
@lukashass lukashass changed the title fix(server): use correct file extension for motion photo videos in archive download fix(server): use correct file extension for motion photo videos May 11, 2024
Copy link
Contributor

@jrasm91 jrasm91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great imo. Once the tests are passing I think we'll be good to go.

}

public async down(): Promise<void> {
// TODO
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably can leave blank

@@ -438,7 +438,7 @@ export class MetadataService {
checksum,
ownerId: asset.ownerId,
originalPath: motionPath,
originalFileName: asset.originalFileName,
originalFileName: `${path.parse(asset.originalFileName).name}.mp4`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perfect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Motion photo video extension is .jpg in archive downloads
5 participants