Page 1 of 1

Reading encoding info for videos >2GB

Posted: Tue Mar 21, 2006 10:37 pm
by derkyjadex
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.

Posted: Wed Mar 22, 2006 7:34 am
by Allan Hansen
It should work.

32 kb is enough.
Disable parsing of ID3v1, Lyrics3 and APE tags (they are at the end).

Posted: Wed Mar 22, 2006 11:18 am
by derkyjadex
Seems to be working great even without disabling anything. Thanks.

Could this be a feature of getID3(), to automatically grab the first and last parts of a file over 2GB to get whatever information it can?

Posted: Wed Mar 22, 2006 1:38 pm
by James Heinrich
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).

Posted: Fri Apr 28, 2006 11:54 am
by tony98
derkyjadex could u show me how i can download 100 kb of mp3 and stop it and then use id3 to read its tag. I be happy to see a wroking example since i am new php.Thanks

Posted: Fri Apr 28, 2006 12:55 pm
by James Heinrich

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);

Posted: Fri Apr 28, 2006 1:06 pm
by tony98
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);


?>

Posted: Sat Apr 29, 2006 1:01 am
by James Heinrich
Sorry, missed a ) and a ' in the code. See above for corrected version.

Posted: Sat Apr 29, 2006 1:19 am
by tony98
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



?>
I be happy if u let me know how to fix it.thanks

Posted: Sat Apr 29, 2006 1:48 am
by James Heinrich
Probably your server doesn't allow opening URLs with PHP, in which case there's not much you can do.

Posted: Sat Apr 29, 2006 1:56 am
by tony98
James Heinrich wrote:Probably your server doesn't allow opening URLs with PHP, in which case there's not much you can do.
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.Thanks

Posted: Sat Apr 29, 2006 10:50 pm
by James Heinrich
The problem is on your own server. Edit php.ini and set

Code: Select all

allow_url_fopen = On

Posted: Wed May 03, 2006 6:17 pm
by tony98
James Heinrich wrote:The problem is on your own server. Edit php.ini and set

Code: Select all

allow_url_fopen = On
It is on and still the same problem!!

Posted: Wed May 03, 2006 8:22 pm
by Allan Hansen
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
The web server on remotesite.com returned an error: "HTTP/1.1 400 Bad Request".

Fix this error first.

Posted: Wed May 03, 2006 8:28 pm
by tony98
Allan Hansen wrote:
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
The web server on remotesite.com returned an error: "HTTP/1.1 400 Bad Request".

Fix this error first.
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".
?thanks

Posted: Mon May 08, 2006 9:39 am
by Allan Hansen
tony98 wrote:[
could u tell me how to fix "HTTP/1.1 400 Bad Request".
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.

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.