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

Distinguish UTC vs local video takestamps #680

Merged
merged 2 commits into from
Aug 17, 2020
Merged

Conversation

kamil4
Copy link
Contributor

@kamil4 kamil4 commented Jul 30, 2020

Fixes #675.

This adds a heuristic to determine whether the takestamp embedded in a video file is in UTC or in local time. The heuristic is based on the filename extension. There is a new config variable, local_takestamp_video_formats, that provides a list the extensions for files that should be treated as having a takestamp in the local time zone. It defaults to AVI and MOV, as those are the two most commonly used in digital cameras, which typically use the local time zone. For files that don't match (such as MP4 files from Android phones) the takestamp is considered to be in UTC and is converted at import time to the local time zone of the server.

While working on this I noticed several bugs that this PR also fixes. In particular:

  • MPG files were treated as image files because at least on my system that's what the MIME says (image/x-tga)?!

  • file_type method in PhotoFunctions was fundamentally broken; it would return photo for video files. Fixing its twisted logic required a complete refactoring.

  • With that fixed, I was able to replace all the ad-hoc tests for video files based on MIME, which didn't work for MPG files (see above).

  • WMV videos misbehaved when using the Exiftool metadata extractor because of conflicting MIME data (Exiftool identifies them as video/x-ms-wmv). There were many other issues when using Exiftool instead of FFmpeg for video files' metadata, which were addressed in Video fixes php-exif#22 (now merged).

  • If FFmpeg is disabled in the config, we shouldn't try to use it to for anything, including extracting a video frame for the thumb. I fixed that particular use case but it appears that there may be more left in the new live photos support? I'm not familiar with that feature so I didn't touch it. @tmp-hallenser?

@@ -237,7 +272,7 @@ public function extract(string $filename, string $type): array
$metadata['position'] = implode(', ', $fields);
}

if (strpos($type, 'video') !== 0) {
Copy link
Member

Choose a reason for hiding this comment

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

are you sure about that one ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See above...

Copy link
Member

Choose a reason for hiding this comment

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

yeap I'm reading I'm reading. :) I just quickly commented. :p

@@ -82,7 +82,7 @@ public function extract(string $filename, string $type): array
$is_raw = true;
}

if (strpos($type, 'video') !== 0) {
Copy link
Member

Choose a reason for hiding this comment

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

are you sure about that one ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pretty sure... It's because of those crazy MPG files being identified by mime_content_type as image/x-tga. So I added image/x-tga to $validVideoTypes, fixed file_type to do what it was actually supposed to (so that it actually returns 'video' for video files), and then replaced all these ad-hoc tests by the more robust checks based on the value returned by file_type.

Handle MPG videos correctly.

Handle WMV videos with Exiftool extractor correctly.

Fix the broken PhotoFunctions::file_type method which would not
distinguish between images and videos.

Don't extract a video frame if FFmpeg is disabled in the config.
@sonarcloud
Copy link

sonarcloud bot commented Aug 3, 2020

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@codecov
Copy link

codecov bot commented Aug 3, 2020

Codecov Report

Merging #680 into master will decrease coverage by 0.04%.
The diff coverage is 37.14%.

@kamil4 kamil4 merged commit 3203891 into master Aug 17, 2020
@kamil4 kamil4 deleted the fix-video-takestamps branch August 17, 2020 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong takestamp on some videos
3 participants