JamesHeinrich / getID3

http://www.getid3.org/
Other
1.15k stars 246 forks source link

For apple videos, the duration is off by 10 times! #456

Open vhdmoradi opened 1 month ago

vhdmoradi commented 1 month ago

$fileInfo['video']['dataformat'] === 'quicktime' for the dataformat of quicktime, the video duration here: $duration = $fileInfo['playtime_seconds']; is 10 times the real value in seconds. for example if the video is 3.34 seconds, the result is 33.4. I wrote this ugly way around, but I wonder why this happens?

private function isIOSVideo($fileInfo): bool
    {
        // Check for iOS-specific data-type
        if ($fileInfo['video']['dataformat'] === 'quicktime') {
            return true; // Video is likely recorded on an iOS device
        }

        return false;
    }
    private function getVideoDuration($file)
    {
        // Initialize getID3 engine
        $getID3 = new getID3();
        $fileInfo = $getID3->analyze($file->getPathname());

        if (isset($fileInfo['playtime_seconds'])) {
            $duration = $fileInfo['playtime_seconds'];

            // Apply correction factor for iOS videos if detected
            if ($this->isIOSVideo($fileInfo)) {
                $duration = $duration / 10;
            }

            return $duration; // Duration in seconds
        }

        return null; // Return null if duration cannot be extracted
    }
JamesHeinrich commented 1 month ago

I'd need a sample file that shows this behaviour to even guess.