Reading encoding info for videos >2GB
-
- User
- Posts: 2
- Joined: Tue Mar 21, 2006 10:25 pm
Reading encoding info for videos >2GB
I know support for files >2GB is very bad in PHP but I've ended up writing some scripts that need to read information such as MIME-type and video/audio codec/bitrate from various video files, some of which are over 2GB.
My question is, is it possible that if I were able to read the first 100k (say) of any file and feed it to getID3() (mostly likley by copying the data to a new file and opening that), would getID3() be able to correctly get all the information I need from the file, even though the file is technically corrupt.
If this works at all, is it pretty much guaranteed to work every time? The information I'm looking for is encoding settings and not artist/album information which I know is sometimes at the end of the file. The alternative, I suppose, would be to rewrite the whole thing in something other than PHP and find some different libraries, which I'd rather not do.
My question is, is it possible that if I were able to read the first 100k (say) of any file and feed it to getID3() (mostly likley by copying the data to a new file and opening that), would getID3() be able to correctly get all the information I need from the file, even though the file is technically corrupt.
If this works at all, is it pretty much guaranteed to work every time? The information I'm looking for is encoding settings and not artist/album information which I know is sometimes at the end of the file. The alternative, I suppose, would be to rewrite the whole thing in something other than PHP and find some different libraries, which I'd rather not do.
-
- getID3() v2 developer
- Posts: 445
- Joined: Sun May 04, 2003 2:22 pm
- Location: Holmegaard, Denmark
-
- User
- Posts: 2
- Joined: Tue Mar 21, 2006 10:25 pm
-
- getID3() v1 developer
- Posts: 1476
- Joined: Fri May 04, 2001 4:00 pm
- Are you a spambot?: no
- Location: Northern Ontario, Canada
- Contact:
getID3() [and PHP in general] will probably work fine on the file up to the 2GB limit, it's beyond there the problems start. So getID3() should automatically grab the needed info from the beginning of the file, and if it looks at the "end" of the file it will most likely silently fail (since it's not looking in the right place) and assume there is no useful data there. Some bitrate and/or playtime data may be incorrect if PHP reports the wrong filesize, it depends on how it's calculated (whether guessed from the first frame and filesize, or extracted from the metadata).
-
- getID3() v1 developer
- Posts: 1476
- Joined: Fri May 04, 2001 4:00 pm
- Are you a spambot?: no
- Location: Northern Ontario, Canada
- Contact:
Code: Select all
if ($fp1 = fopen('http://example.com/file.mp3', 'rb')) {
$tempname = tempnam('/tmp', 'foo');
if ($fp2 = fopen($tempname, 'wb')) {
fwrite($fp2, fread($fp, 102400));
fclose($fp2);
}
fclose($fp1);
}
$getID3->analyze($tempname);
Last edited by James Heinrich on Sat Apr 29, 2006 1:01 am, edited 2 times in total.
-
- User
- Posts: 23
- Joined: Mon Feb 13, 2006 5:47 am
Many thanks for u reply . I tried to run it from same folder as getid3 but i get the following error:
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in \remote2.php on line 4
Could u tell me how to fix it .Thanks
<?
if ($fp1 = fopen('http://ww.remote.com - Marghalary.mp3', 'rb)) {
$tempname = tempnam('/tmp', 'foo');
if ($fp2 = fopen($tempname, 'wb') {
fwrite($fp2, fread($fp, 102400));
fclose($fp2);
}
fclose($fp1);
}
$getID3->analyze($tempname);
?>
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in \remote2.php on line 4
Could u tell me how to fix it .Thanks
<?
if ($fp1 = fopen('http://ww.remote.com - Marghalary.mp3', 'rb)) {
$tempname = tempnam('/tmp', 'foo');
if ($fp2 = fopen($tempname, 'wb') {
fwrite($fp2, fread($fp, 102400));
fclose($fp2);
}
fclose($fp1);
}
$getID3->analyze($tempname);
?>
-
- getID3() v1 developer
- Posts: 1476
- Joined: Fri May 04, 2001 4:00 pm
- Are you a spambot?: no
- Location: Northern Ontario, Canada
- Contact:
-
- User
- Posts: 23
- Joined: Mon Feb 13, 2006 5:47 am
James Heinrich wrote:Sorry, missed a ) and a ' in the code. See above for corrected version.
Thank u for u reply. I tried it now i get this error :
Warning: fopen(http://www.remotesite.com/song.mp3) [function.fopen]: failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in \getid3\remote3.php on line 5
Fatal error: Call to a member function analyze() on a non-object in \getid3\remote3.php on line 13
Bold parts are line 5 and 11
Code: Select all
<?
[b]if ($fp1 = fopen('http://www.remotesite.com/song.mp3', 'rb')) { [/b]
$tempname = tempnam('/tmp', 'foo');
if ($fp2 = fopen($tempname, 'wb')) {
fwrite($fp2, fread($fp, 102400));
fclose($fp2);
}
fclose($fp1);
}
[b]$getID3->analyze($tempname); [/b] line 13th
?>
-
- getID3() v1 developer
- Posts: 1476
- Joined: Fri May 04, 2001 4:00 pm
- Are you a spambot?: no
- Location: Northern Ontario, Canada
- Contact:
-
- User
- Posts: 23
- Joined: Mon Feb 13, 2006 5:47 am
Thank u for u reply .do u mean the erros are because my own php server that i run the script from or the remote server that i want to read its mp3 file ? i am able to download mp3 songs from that site so it should not be problem with that. If the problem is with my own server that i run the script then could u tell how to change its configuration since i have full permision to it.ThanksJames Heinrich wrote:Probably your server doesn't allow opening URLs with PHP, in which case there's not much you can do.
-
- getID3() v1 developer
- Posts: 1476
- Joined: Fri May 04, 2001 4:00 pm
- Are you a spambot?: no
- Location: Northern Ontario, Canada
- Contact:
The problem is on your own server. Edit php.ini and set
Code: Select all
allow_url_fopen = On
-
- User
- Posts: 23
- Joined: Mon Feb 13, 2006 5:47 am
It is on and still the same problem!!James Heinrich wrote:The problem is on your own server. Edit php.ini and setCode: Select all
allow_url_fopen = On
-
- getID3() v2 developer
- Posts: 445
- Joined: Sun May 04, 2003 2:22 pm
- Location: Holmegaard, Denmark
The web server on remotesite.com returned an error: "HTTP/1.1 400 Bad Request".tony98 wrote: Warning: fopen(http://www.remotesite.com/song.mp3) [function.fopen]: failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in \getid3\remote3.php on line 5
Fix this error first.
-
- User
- Posts: 23
- Joined: Mon Feb 13, 2006 5:47 am
well the remote site is just dammy site but i tested in real site and same error. could u tell me how to fix "HTTP/1.1 400 Bad Request".Allan Hansen wrote:The web server on remotesite.com returned an error: "HTTP/1.1 400 Bad Request".tony98 wrote: Warning: fopen(http://www.remotesite.com/song.mp3) [function.fopen]: failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in \getid3\remote3.php on line 5
Fix this error first.
?thanks
-
- getID3() v2 developer
- Posts: 445
- Joined: Sun May 04, 2003 2:22 pm
- Location: Holmegaard, Denmark
Unfortunately not. The error message comes directly from the webserver hosting the file you requested. It has nothing to do with getID3() nor your PHP script.tony98 wrote:[
could u tell me how to fix "HTTP/1.1 400 Bad Request".
There are some things I can mention that may help you solve the problem.
1. Check the URL in your browser. Does it work properly or do you get the 400 error?
2. Did your browser rewrite the URL? Is the URL valid?
3. Does the webserver know what to do with mp3 files? Correct MIME type set?
4. Are you trying to access files on a network share? If yes, does the webserver has access or is it only your local account that does.
If this does not help, please consult the manual of your webserver.