Page 1 of 1

how to get audio info by remote files

PostPosted: Thu Feb 21, 2008 9:52 pm
by rassen
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

PostPosted: Fri Feb 22, 2008 6:04 am
by James Heinrich
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.

PostPosted: Mon Feb 25, 2008 5:01 am
by rassen
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?

PostPosted: Mon Feb 25, 2008 5:06 am
by Allan Hansen
$fp = fopen('http://myserver/myfile.flac');
$first32kb = fread($fp, 32*1024*1024);
fclose($fp);

PostPosted: Mon Feb 25, 2008 6:07 am
by James Heinrich
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);

PostPosted: Mon Feb 25, 2008 8:41 am
by rassen
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 :|

PostPosted: Mon Feb 25, 2008 6:06 pm
by rassen
i have a small question.
so, how to get bitrate with mms protocol?

PostPosted: Tue Feb 26, 2008 10:06 pm
by rassen
one more question, that's i can't get right playtime and filesize util download full file to my desktop :| ??!

PostPosted: Wed Feb 27, 2008 6:00 am
by James Heinrich
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)).

Re: how to get audio info by remote files

PostPosted: Tue Jul 14, 2009 7:17 am
by sojic
Can I use this method for analyzing .flv/.swf files??

How much Kb should "read" from remote file?

Re: how to get audio info by remote files

PostPosted: Mon Jul 20, 2009 6:44 am
by James Heinrich
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.

Re: how to get audio info by remote files

PostPosted: Thu Sep 17, 2009 1:57 pm
by dshaner
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?

Re: how to get audio info by remote files

PostPosted: Tue Jul 06, 2010 8:53 pm
by jasonzhong
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?