Reading encoding info for videos >2GB

The place for "I can't figure out how to..." questions.
Post Reply
derkyjadex
User
Posts: 2
Joined: Tue Mar 21, 2006 10:25 pm

Reading encoding info for videos >2GB

Post by derkyjadex » Tue Mar 21, 2006 10:37 pm

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.

Allan Hansen
getID3() v2 developer
Posts: 445
Joined: Sun May 04, 2003 2:22 pm
Location: Holmegaard, Denmark

Post by Allan Hansen » Wed Mar 22, 2006 7:34 am

It should work.

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

derkyjadex
User
Posts: 2
Joined: Tue Mar 21, 2006 10:25 pm

Post by derkyjadex » Wed Mar 22, 2006 11:18 am

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?

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

Post by James Heinrich » Wed Mar 22, 2006 1:38 pm

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

tony98
User
Posts: 23
Joined: Mon Feb 13, 2006 5:47 am

Post by tony98 » Fri Apr 28, 2006 11:54 am

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

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

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

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.

tony98
User
Posts: 23
Joined: Mon Feb 13, 2006 5:47 am

Post by tony98 » Fri Apr 28, 2006 1:06 pm

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


?>

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

Post by James Heinrich » Sat Apr 29, 2006 1:01 am

Sorry, missed a ) and a ' in the code. See above for corrected version.

tony98
User
Posts: 23
Joined: Mon Feb 13, 2006 5:47 am

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



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

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

Post by James Heinrich » Sat Apr 29, 2006 1:48 am

Probably your server doesn't allow opening URLs with PHP, in which case there's not much you can do.

tony98
User
Posts: 23
Joined: Mon Feb 13, 2006 5:47 am

Post by tony98 » Sat Apr 29, 2006 1:56 am

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

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

Post by James Heinrich » Sat Apr 29, 2006 10:50 pm

The problem is on your own server. Edit php.ini and set

Code: Select all

allow_url_fopen = On

tony98
User
Posts: 23
Joined: Mon Feb 13, 2006 5:47 am

Post by tony98 » Wed May 03, 2006 6:17 pm

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!!

Allan Hansen
getID3() v2 developer
Posts: 445
Joined: Sun May 04, 2003 2:22 pm
Location: Holmegaard, Denmark

Post by Allan Hansen » Wed May 03, 2006 8:22 pm

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.

tony98
User
Posts: 23
Joined: Mon Feb 13, 2006 5:47 am

Post by tony98 » Wed May 03, 2006 8:28 pm

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

Allan Hansen
getID3() v2 developer
Posts: 445
Joined: Sun May 04, 2003 2:22 pm
Location: Holmegaard, Denmark

Post by Allan Hansen » Mon May 08, 2006 9:39 am

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.

Post Reply