Skip to content

Error date on some mp4/m4v files. #1450

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

Open
Forza-tng opened this issue May 11, 2025 · 1 comment
Open

Error date on some mp4/m4v files. #1450

Forza-tng opened this issue May 11, 2025 · 1 comment
Labels
needs triage To be triaged

Comments

@Forza-tng
Copy link

Forza-tng commented May 11, 2025

Describe the bug

On some video files, the date ends up decades in the past. I think it is due to a problem in how the metadata in the videos is encoded.

Steps To Reproduce

For example, video file 20120529_085506.m4v is detected as being created in 1946.

When looking at the timestamps we see the following:

❯ exiftool  -time:all  20120529_085506.m4v
File Modification Date/Time     : 2012:05:29 08:55:06+02:00
File Access Date/Time           : 2012:05:29 08:55:06+02:00
File Inode Change Date/Time     : 2024:10:12 16:27:45+02:00
Create Date                     : 2012:05:29 08:55:06
Modify Date                     : 2012:05:29 08:55:06
Track Create Date               : 2012:05:29 08:55:06
Track Modify Date               : 2012:05:29 08:55:06
Media Create Date               : 2012:05:29 08:55:06
Media Modify Date               : 2012:05:29 08:55:06

However when using the QuickTime API, we can see where the wrong year comes from:

❯ exiftool  -time:all  -api QuickTimeUTC 20120529_085506.m4v
File Modification Date/Time     : 2012:05:29 08:55:06+02:00
File Access Date/Time           : 2012:05:29 08:55:06+02:00
File Inode Change Date/Time     : 2024:10:12 16:27:45+02:00
Create Date                     : 1946:05:29 10:55:06+02:00
Modify Date                     : 1946:05:29 10:55:06+02:00
Track Create Date               : 1946:05:29 10:55:06+02:00
Track Modify Date               : 1946:05:29 10:55:06+02:00
Media Create Date               : 1946:05:29 10:55:06+02:00
Media Modify Date               : 1946:05:29 10:55:06+02:00

Platform

- OS: Android, Linux
- Browser: Opera, Firefox
- Memories Version: 7.5.2
- Nextcloud Version: 31.0.4
- PHP Version: 8.3.20
- exiftool: 13.10 (using system version)
- Host OS: Gentoo Linux x86_64

Screenshots

Image

Additional context

There is some information on exiftool website about this: https://exiftool.org/TagNames/QuickTime.html and https://exiftool.org/ExifTool.html#QuickTimeUTC

I am not exactly sure how to solve the issue. Perhaps Memories can try with and without the QuickTimeUTC option to detect obviously wrong dates.

@Forza-tng Forza-tng added the needs triage To be triaged label May 11, 2025
@toksoyy
Copy link

toksoyy commented Jun 6, 2025

Hi. I'm having the same problem with whatsapp videos I backed up. I temporarily solved the problem by making an arrangement like this. I didn't do detailed research. I don't know where the real problem is.

I edited the getDateTaken function in apps/memories/lib/exif.php like this and indexed again with
occ memories:index --clear command.

 public static function getDateTaken(File $file, array $exif): \DateTime
{
    // If it is a WhatsApp video, pull the date from the file name
    $filename = $file->getName(); // edit

    if (preg_match('/VID-(\d{8})-WA\d+/', $filename, $matches)) {
        $dateStr = $matches[1]; 

        try {
            $dt = \DateTime::createFromFormat('Ymd', $dateStr);
            // timezone settings
            $tz = getenv('TZ') ?: date_default_timezone_get();
            $dt->setTime(12, 0); we give a fixed time because there is no time information in the file
            $dt->setTimezone(new \DateTimeZone($tz));

            return $dt;
        } catch (\Exception) {
            // If the file name is wrong, return to normal EXIF
        }
    }

    // Try with normal EXIF date
    try {
        $date = self::parseExifDate($exif);
        if ($date->getTimestamp() === -2082844800) {
            throw new \Exception("Blacklisted date, fallback to mtime");
        }
        return $date;
    } catch (\Exception) {
    } catch (\ValueError) {
    }

    // If the date is still not found, use the time the file was modified
    $dt = new \DateTime('@'.$file->getMtime());
    $tz = getenv('TZ') ?: date_default_timezone_get();

    try {
        $dt->setTimezone(new \DateTimeZone($tz));
    } catch (\Exception) {
        throw new \Error("FATAL: system timezone is invalid (TZ): {$tz}");
    }

    return $dt;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage To be triaged
Projects
None yet
Development

No branches or pull requests

2 participants