how to get audio info by remote files

PHP5 required. No ID3v2 tag writing support yet.

how to get audio info by remote files

Postby rassen » Thu Feb 21, 2008 9:52 pm

i want get audio info by remote files method,
however don't need to download audio file to my PC?

i'm using one simple class, to get mp3 bitrate , don't need download audio file, by remote files
rassen
User
 
Posts: 5
Joined: Thu Feb 21, 2008 1:26 pm

Postby James Heinrich » Fri Feb 22, 2008 6:04 am

Depending on the file format you may need anywhere from a few bytes to the entire file to get accurate results. If you download (at least) the first 32kB of the file you should be OK for most MP3 files (although you will be missing all tags data from the end, like ID3v1, Lyrics3, APE) but if you only need bitrate for MP3s then that should be enough.

If you need code examples, search these forums for "remote" and you'll find plenty of threads with example code.
James Heinrich
getID3() v1 developer
 
Posts: 702
Joined: Fri May 04, 2001 11:00 am
Location: Kingston, ON, Canada

Postby rassen » Mon Feb 25, 2008 5:01 am

how to get 32KB only?
i just test every script with remote file.
i can download full file only, how to download 32KB of file only?
rassen
User
 
Posts: 5
Joined: Thu Feb 21, 2008 1:26 pm

Postby Allan Hansen » Mon Feb 25, 2008 5:06 am

$fp = fopen('http://myserver/myfile.flac');
$first32kb = fread($fp, 32*1024*1024);
fclose($fp);
Allan Hansen
getID3() v2 developer
 
Posts: 447
Joined: Sun May 04, 2003 9:22 am
Location: Holmegaard, Denmark

Postby James Heinrich » Mon Feb 25, 2008 6:07 am

Allan Hansen wrote:$fp = fopen('http://myserver/myfile.flac');
$first32kb = fread($fp, 32*1024*1024);
fclose($fp);
Sorry Allan, but that would give 32MiB ;)
Code: Select all
$fp = fopen('http://myserver/myfile.flac');
$first32kb = fread($fp, 32*1024);
fclose($fp);
James Heinrich
getID3() v1 developer
 
Posts: 702
Joined: Fri May 04, 2001 11:00 am
Location: Kingston, ON, Canada

Postby rassen » Mon Feb 25, 2008 8:41 am

sorry, here's my code

Code: Select all
$remotefilename = 'mylink,example';
$fp = fopen($remotefilename,'rb');
if ($fp2 = fopen('boo', 'wb')) {
   $first32kb = fread($fp, 32*1024);
   fwrite($fp2,$first32kb);
}
fclose($fp);

$ThisFileInfo = $getID3->analyze('boo');


and it's create one 6kb file :|
rassen
User
 
Posts: 5
Joined: Thu Feb 21, 2008 1:26 pm

Postby rassen » Mon Feb 25, 2008 6:06 pm

i have a small question.
so, how to get bitrate with mms protocol?
rassen
User
 
Posts: 5
Joined: Thu Feb 21, 2008 1:26 pm

Postby rassen » Tue Feb 26, 2008 10:06 pm

one more question, that's i can't get right playtime and filesize util download full file to my desktop :| ??!
rassen
User
 
Posts: 5
Joined: Thu Feb 21, 2008 1:26 pm

Postby James Heinrich » Wed Feb 27, 2008 6:00 am

rassen wrote:one more question, that's i can't get right playtime and filesize util download full file to my desktop :| ??!
Filesize, obviously not. You can get the remote filesize with a function like this:
Code: Select all
function filesize_remote($remotefile, $timeout=10) {
   $size = false;
   $url = parse_url($remotefile);
   if ($fp = @fsockopen($url['host'], ($url['port'] ? $url['port'] : 80), $errno, $errstr, $timeout)) {
      fwrite($fp, 'HEAD '.@$url['path'].@$url['query'].' HTTP/1.0'."\r\n".'Host: '.@$url['host']."\r\n\r\n");
      while (!feof($fp)) {
         $headerline = fgets($fp, 4096);
         if (eregi('^Content-Length: (.*)', $headerline, $matches)) {
            $size = intval($matches[1]);
            break;
         }
      }
      fclose ($fp);
   }
   return $size;
}
Playtime may be accurate (or not) depending on the file format. For MP3s, if there's a VBR header then playtime should be accurate without having the full file. For CBR or VBR files without the VBR header, then you can calculate actual playtime with (actual_filesize / (average_bitrate * 8)).
James Heinrich
getID3() v1 developer
 
Posts: 702
Joined: Fri May 04, 2001 11:00 am
Location: Kingston, ON, Canada

Re: how to get audio info by remote files

Postby sojic » Tue Jul 14, 2009 7:17 am

Can I use this method for analyzing .flv/.swf files??

How much Kb should "read" from remote file?
sojic
User
 
Posts: 2
Joined: Mon Jul 13, 2009 6:46 pm

Re: how to get audio info by remote files

Postby James Heinrich » Mon Jul 20, 2009 6:44 am

Yes, this method should work for pretty much any file format (with the caution that the file may be flagged as corrupt and/or incorrect playtime/bitrate type values may be returned for those format that don't store this information in a header). For FLV/SWF you probably don't need much data, anywhere from 1kB to 32kB is probably fine, depending on the file. More is always better (in terms of returning accurate results) but you can probably be pretty safe with ~4kB most of the time.
James Heinrich
getID3() v1 developer
 
Posts: 702
Joined: Fri May 04, 2001 11:00 am
Location: Kingston, ON, Canada

Re: how to get audio info by remote files

Postby dshaner » Thu Sep 17, 2009 1:57 pm

Can anyone tell me how to get the width and height of a remote flv file using an array instead of creating a file on the web server?
dshaner
User
 
Posts: 1
Joined: Thu Sep 17, 2009 1:53 pm

Re: how to get audio info by remote files

Postby jasonzhong » Tue Jul 06, 2010 8:53 pm

I have some vedio file on remote box in format: mp4/H.264/FFAC.
In order to get the following info :
resolution: 1280 x 720
time: 9701.695 sec time_string: 161:42
1310784729+4351741=1315136470 total bytes
bitrates: 1084Kbps
File parsed in 9.986 seconds.


Code: Select all
   $tmpfname = tempnam("./", "mp4");
   $buf = file_get_contents( $_REQUEST['filename'], false, null, 0, GETID3_FREAD_BUFFER_SIZE * 300);
   file_put_contents( $tmpfname, $buf);
   $info = $getID3->analyze( $tmpfname);
   getid3_lib::CopyTagsToComments($info);
   
   //echo table_var_dump($info);
   //print_r( $info['quicktime']['vedio']);
   echo $info['video']['resolution_x']." x ";
   echo $info['video']['resolution_y']."<br>";
   echo $info['playtime_seconds']." ";
   echo $info['playtime_string']."<br>";
   $filesize = $info['quicktime']['mdat']['size'] + $info['quicktime']['mdat']['offset'];
   echo $info['quicktime']['mdat']['size']."+";
   echo $info['quicktime']['mdat']['offset']."={$filesize}<br>";
   echo round( $filesize * 8 / $info['playtime_seconds'] / 1000)."Kbps<br>";


Note that I have to obtain "GETID3_FREAD_BUFFER_SIZE * 300" of the file.

Is there any better way to fetch less bytes from remote url for MP4 VEDIO?
jasonzhong
User
 
Posts: 1
Joined: Tue Jul 06, 2010 8:37 pm


Return to Support 2.0.x

Who is online

Users browsing this forum: No registered users and 2 guests

cron