how to get audio info by remote files

Locked
rassen
User
Posts: 5
Joined: Thu Feb 21, 2008 6:26 pm

how to get audio info by remote files

Post by rassen » Fri Feb 22, 2008 2:52 am

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

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

Post by James Heinrich » Fri Feb 22, 2008 11: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.

rassen
User
Posts: 5
Joined: Thu Feb 21, 2008 6:26 pm

Post by rassen » Mon Feb 25, 2008 10: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?

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

Post by Allan Hansen » Mon Feb 25, 2008 10:06 am

$fp = fopen('http://myserver/myfile.flac');
$first32kb = fread($fp, 32*1024*1024);
fclose($fp);

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

Post by James Heinrich » Mon Feb 25, 2008 11: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);

rassen
User
Posts: 5
Joined: Thu Feb 21, 2008 6:26 pm

Post by rassen » Mon Feb 25, 2008 1:41 pm

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 6:26 pm

Post by rassen » Mon Feb 25, 2008 11:06 pm

i have a small question.
so, how to get bitrate with mms protocol?

rassen
User
Posts: 5
Joined: Thu Feb 21, 2008 6:26 pm

Post by rassen » Wed Feb 27, 2008 3:06 am

one more question, that's i can't get right playtime and filesize util download full file to my desktop :| ??!

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

Post by James Heinrich » Wed Feb 27, 2008 11: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)).

sojic
User
Posts: 2
Joined: Mon Jul 13, 2009 11:46 pm
Are you a spambot?: no

Re: how to get audio info by remote files

Post by sojic » Tue Jul 14, 2009 12:17 pm

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

How much Kb should "read" from remote file?

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

Re: how to get audio info by remote files

Post by James Heinrich » Mon Jul 20, 2009 11: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.

dshaner
User
Posts: 1
Joined: Thu Sep 17, 2009 6:53 pm
Are you a spambot?: no

Re: how to get audio info by remote files

Post by dshaner » Thu Sep 17, 2009 6: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?

jasonzhong
User
Posts: 1
Joined: Wed Jul 07, 2010 1:37 am
Are you a spambot?: no

Re: how to get audio info by remote files

Post by jasonzhong » Wed Jul 07, 2010 1:53 am

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?

Locked