Getting Metadata from MP4 and MOV (h.264 Codec) video files

Locked
marcbraulio
User
Posts: 11
Joined: Thu Oct 18, 2012 7:15 pm
Are you a spambot?: no

Getting Metadata from MP4 and MOV (h.264 Codec) video files

Post by marcbraulio » Thu Oct 18, 2012 7:32 pm

First of all, thank you for such a incredible library, truly great. I am trying to get some metadata from MP4 and MOV video files, mostly encoded in h.264. So far I had no luck. I keep getting the following error: "unable to determine file format". I am currently running "Latest 1.x beta version: 1.9.4b1" of getID3 on PHP Version 5.4.3. Everything works great for images. Is there something extra that I need to do for video files or is this a bug? I am primarily interested in the width and height of the videos.

Any help is appreciated and once again thank you!

James Heinrich
getID3() v1 developer
Posts: 1457
Joined: Fri May 04, 2001 4:00 pm
Are you a spambot?: no
Location: Northern Ontario, Canada
Contact:

Re: Getting Metadata from MP4 and MOV (h.264 Codec) video fi

Post by James Heinrich » Thu Oct 18, 2012 9:00 pm

There should be no problem getting that information for most MP4 and/or MOV files.

Please send a sample file to info@getid3.org that gives this error.
(if >10MB, please email a link to the sample file)

marcbraulio
User
Posts: 11
Joined: Thu Oct 18, 2012 7:15 pm
Are you a spambot?: no

Re: Getting Metadata from MP4 and MOV (h.264 Codec) video fi

Post by marcbraulio » Fri Oct 19, 2012 12:24 pm

Hi James, thanks for the super fast reply, awesome support. So far I have tried two versions of the "Big Buck Bunny" open rights videos. You can download them at: http://www.bigbuckbunny.org/index.php/download/ In particular I have tried the one titled "IPod 5G 320×180, 62 MB" and the "854 x 480" H.264 version. Let me know your findings. Much appreciated!

James Heinrich
getID3() v1 developer
Posts: 1457
Joined: Fri May 04, 2001 4:00 pm
Are you a spambot?: no
Location: Northern Ontario, Canada
Contact:

Re: Getting Metadata from MP4 and MOV (h.264 Codec) video fi

Post by James Heinrich » Fri Oct 19, 2012 6:35 pm

Using provided sample file, a quick look at the file in demo.browse.php seemed to work as expected (320x240 resolution, for example).

Please open demo/demo.browse.php in your browser and browse to one of the files that you're having trouble with and let me know if you get the same error or a normal full file analysis?

marcbraulio
User
Posts: 11
Joined: Thu Oct 18, 2012 7:15 pm
Are you a spambot?: no

Re: Getting Metadata from MP4 and MOV (h.264 Codec) video fi

Post by marcbraulio » Fri Oct 19, 2012 7:42 pm

Hmm, this is very strange, the demo works perfectly with the same files that I am uploading. What do you think could be the issue?

James Heinrich
getID3() v1 developer
Posts: 1457
Joined: Fri May 04, 2001 4:00 pm
Are you a spambot?: no
Location: Northern Ontario, Canada
Contact:

Re: Getting Metadata from MP4 and MOV (h.264 Codec) video fi

Post by James Heinrich » Fri Oct 19, 2012 8:27 pm

A few guesses:

* getID3 / PHP doesn't have access to the file you're attempting to read
* the temp file is being deleted before getID3 reads it
* the filename contains unescaped special characters or something which is preventing the correct filename from being passed to getID3.

If you want to post your relevant code snippet where you call getID3 perhaps the problem will reveal itself.

marcbraulio
User
Posts: 11
Joined: Thu Oct 18, 2012 7:15 pm
Are you a spambot?: no

Re: Getting Metadata from MP4 and MOV (h.264 Codec) video fi

Post by marcbraulio » Tue Oct 23, 2012 1:23 pm

Hmm, I don't think what you have listed is the issue because otherwise image files would not work.

For a regular MP4 file I get the following error:

Code: Select all

Array ( [GETID3_VERSION] => 1.9.4b1-20121005 [filesize] => 159483 [filename] => php2427.tmp [filepath] => C:/wamp/tmp [filenamepath] => C:/wamp/tmp/php2427.tmp [encoding] => UTF-8 [error] => Array ( [0] => unable to determine file format ) )
In my set up the getID3 library is sitting on top of Zend Framework 2 and I am using namespaces. The demo is working without being part of Zend and without using namespaces. I remember that I also originally had issues with images, I was getting a ''Format not supported, module module.graphic.jpg is corrupt." error. So I tracked the down where the error was being shown in the PHP file and it turns out that I had to add the proper namespace to "$classname", like so:

Code: Select all

// getid3.php line 362
$class_name = 'Portal\Model\getid3\getid3_'.$determined_format['module'];
if (!class_exists($class_name)) {
     return $this->error('Format not supported, module "'.$determined_format['include'].'" is corrupt.');
}
And in order to make the whole system work I had to add "namespace Portal\Model\getid3;" to the top of every getID3 page so that all classes get instantiated inside the proper namespace, but I guess that dynamically instantiate classes don't obey the namespace rule, causing the image error above. However for the MP4 files, it seems to me that it is not a class instantiation problem as it simply cannot determine the format before any dependencies are called. As far as I can see, getID3 determines the format inside getid3.php using the GetFileFormat() and GetFileFormatArray() methods. Please correct me if I am wrong and let me know if there are any dependencies so that I can make sure they are all being properly instantiated.

Thank you very much,
Marc

James Heinrich
getID3() v1 developer
Posts: 1457
Joined: Fri May 04, 2001 4:00 pm
Are you a spambot?: no
Location: Northern Ontario, Canada
Contact:

Re: Getting Metadata from MP4 and MOV (h.264 Codec) video fi

Post by James Heinrich » Tue Oct 23, 2012 1:49 pm

marcbraulio wrote:As far as I can see, getID3 determines the format inside getid3.php using the GetFileFormat() and GetFileFormatArray() methods.
Correct. File format is initially determined with a simple regex in getid3.php, and then once the format is determined based on a few bytes from the beginning of the file, the detailed analysis is done from within whichever module is loaded and called. Almost every detected format has its own module, and many of those modules have dependencies, but each module should have dependencies listed at the top of the module file.

marcbraulio
User
Posts: 11
Joined: Thu Oct 18, 2012 7:15 pm
Are you a spambot?: no

Re: Getting Metadata from MP4 and MOV (h.264 Codec) video fi

Post by marcbraulio » Tue Oct 23, 2012 2:23 pm

James Heinrich wrote:
marcbraulio wrote:As far as I can see, getID3 determines the format inside getid3.php using the GetFileFormat() and GetFileFormatArray() methods.
Correct. File format is initially determined with a simple regex in getid3.php, and then once the format is determined based on a few bytes from the beginning of the file, the detailed analysis is done from within whichever module is loaded and called. Almost every detected format has its own module, and many of those modules have dependencies, but each module should have dependencies listed at the top of the module file.
Right, so with that being said, it is just simply failing to recognize the format. Could you tell me the exact line that the script checks for MP4/MOV/Quicktime file formats?

James Heinrich
getID3() v1 developer
Posts: 1457
Joined: Fri May 04, 2001 4:00 pm
Are you a spambot?: no
Location: Northern Ontario, Canada
Contact:

Re: Getting Metadata from MP4 and MOV (h.264 Codec) video fi

Post by James Heinrich » Tue Oct 23, 2012 2:40 pm

Line numbers may vary slightly by version, assuming v1.9.4b1:
http://www.getid3.org/source/getid3.phps

Around line 866 of GetFileFormatArray()

Code: Select all

// QT   - audio/video - Quicktime
'quicktime' => array(
            'pattern'   => '^.{4}(cmov|free|ftyp|mdat|moov|pnot|skip|wide)',
            'group'     => 'audio-video',
            'module'    => 'quicktime',
            'mime_type' => 'video/quicktime',
        ),
Line 1117 (in GetFileFormat()) actually matches the pattern:

Code: Select all

// Identify file format - loop through $format_info and detect with reg expr
foreach ($this->GetFileFormatArray() as $format_name => $info) {
    // The /s switch on preg_match() forces preg_match() NOT to treat
    // newline (0x0A) characters as special chars but do a binary match
    if (!empty($info['pattern']) && preg_match('#'.$info['pattern'].'#s', $filedata)) {
        $info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php';
        return $info;
    }
}

marcbraulio
User
Posts: 11
Joined: Thu Oct 18, 2012 7:15 pm
Are you a spambot?: no

Re: Getting Metadata from MP4 and MOV (h.264 Codec) video fi

Post by marcbraulio » Tue Oct 23, 2012 4:53 pm

Got it working, the problem was a combination of issues with my HTML5 uploader and file size restrictions. Thank you for all the help and you were marginally right in your suggestions, the reason why getID3 was throwing an error was because "getID3 / PHP doesn't have access to the file you're attempting to read", in theory it only had access to chuck of the file, which is useless.

Have a good one and thanks for the awesome library, you sir are a genius :)

Locked