Remote Files Curl Headersize

Locked
togo
User
Posts: 8
Joined: Sun Mar 20, 2011 11:03 am
Are you a spambot?: no
Location: Waltrop, NRW, Germany

Remote Files Curl Headersize

Post by togo » Mon Mar 21, 2011 8:37 pm

Hi @ all,

i'm coding a function read the header information of remote video files.

Code: Select all

<?php

require_once('./getid3/getid3.php');

$remotefilename = 'http://ex.anolis-film.de/V2/images/stories/media/video/big_buck_bunny.jpg';

$localtempfilename = getcwd().'/tmp/'.'tmp_remote_'.basename($remotefilename);
$out = fopen($localtempfilename,'wb');
$n = GETID3_FREAD_BUFFER_SIZE;

$header = "$n"; //32768 size of read buffer, 32kB is default
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $remotefilename);
curl_setopt($ch, CURLOPT_RANGE, '0'.'-'."32767");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);


$data = curl_exec($ch);

file_put_contents( $localtempfilename, $data);
if($ch == false) { 
	echo "Error is : ".curl_error ( $ch); 
}
curl_close($ch);
 $getID3 = new getID3;
		if(!file_exists($localtempfilename)){
			echo '<br /><strong>Error read '.$localtempfilename.'</strong><br />';
		}
      	$ThisFileInfo = $getID3->analyze($localtempfilename);
		// output desired information in whatever format you want
		echo 'version: '.$getID3->info['GETID3_VERSION'].'<br />';
		echo 'File: '.$ThisFileInfo['filenamepath'].'<br />';
		echo 'FileSize: '.$ThisFileInfo['filesize'].'<br />';
		echo 'FileSizeOfTempFile: '.filesize($localtempfilename).'<br />';
		echo 'MimeType: '.$ThisFileInfo['mime_type'].'<br />';
		echo 'Artist: '.(!empty($ThisFileInfo['comments_html']['artist']) ? implode('<br />', $ThisFileInfo['comments_html']['artist']) : '&nbsp;').'<br />';
		echo 'Title: '.(!empty($ThisFileInfo['comments_html']['title'])  ? implode('<br />', $ThisFileInfo['comments_html']['title'])  : '&nbsp;').'<br />';
		echo 'BitRate: '.(!empty($ThisFileInfo['audio']['bitrate'])        ? round($ThisFileInfo['audio']['bitrate'] / 1000).' kbps'   : '&nbsp;').'<br />';
		echo 'Playtime: '.(!empty($ThisFileInfo['playtime_string'])         ? $ThisFileInfo['playtime_string']                          : '&nbsp;').'<br />';
		
		if(!empty($ThisFileInfo['video']['resolution_x']) || !empty($ThisFileInfo['video']['resolution_y'])){
			$res_x=$ThisFileInfo['video']['resolution_x'];
			$res_y=$ThisFileInfo['video']['resolution_y']; 
		} else{
			$res_x='undefined';
			$res_y='undefined'; 
		}

		echo 'Resolution: '.$res_x.' x '.$res_y.'<br />';
		echo '<pre>';
		print_r($ThisFileInfo['video']);
		echo '</pre>';
		echo '<hr />';
        // Delete temporary file
        //unlink($localtempfilename);


?>
This work well with flv|f4v|jpg files.

For mp4|webm|mov files the 32768 bit are not enough. Does anyone knows the right file (header) size of the temp file?

THX
Tom

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: Remote Files Curl Headersize

Post by James Heinrich » Mon Mar 21, 2011 8:55 pm

Depending on the file format, and how much stuff is stuffed into the headers, you may need anywhere from a few tens of bytes to several MB. Unfortunately there's few easy, definite answers where I could say (for example) "640kB is enough for any example of this file type". Trial and error will guide you in the right direction. Sorry I can't be more specifically helpful.

togo
User
Posts: 8
Joined: Sun Mar 20, 2011 11:03 am
Are you a spambot?: no
Location: Waltrop, NRW, Germany

Re: Remote Files Curl Headersize

Post by togo » Tue Mar 22, 2011 1:25 pm

Hallo James,

thx for your answer.

Regards
Tom

togo
User
Posts: 8
Joined: Sun Mar 20, 2011 11:03 am
Are you a spambot?: no
Location: Waltrop, NRW, Germany

Re: Remote Files Curl Headersize

Post by togo » Tue Mar 22, 2011 2:09 pm

OK,
i have changed my script.

Code: Select all

<?php

require_once('./getid3/getid3.php');

$remotefilename = 'http://ex.anolis-film.de/V2/images/stories/media/video/big_buck_bunny.flv';//32768
getFileInfos($remotefilename,32768);
$remotefilename = 'http://ex.anolis-film.de/V2/images/stories/media/video/big_buck_bunny.f4v';//32768
getFileInfos($remotefilename,32768);
$remotefilename = 'http://ex.anolis-film.de/V2/images/stories/media/video/big_buck_bunny.jpg';//32768
getFileInfos($remotefilename);
$remotefilename = 'http://ex.anolis-film.de/V2/images/stories/media/video/big_buck_bunny.mp4';
getFileInfos($remotefilename);
$remotefilename = 'http://ex.anolis-film.de/V2/images/stories/media/video/big_buck_bunny.mov';
getFileInfos($remotefilename);
$remotefilename = 'http://ex.anolis-film.de/V2/images/stories/media/video/big_buck_bunny.webm';
getFileInfos($remotefilename);


function getFileInfos($remotefilename){
	$m_start = microtime(true);
	$localtempfilename = getcwd().'/tmp/'.'tmp_remote_'.basename($remotefilename);
	$out = fopen($localtempfilename,'wb');
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $remotefilename);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_FILE, $out);

	curl_exec($ch);

	//file_put_contents( $localtempfilename, $data);
	if($ch == false) { 
		echo "Error is : ".curl_error ( $ch); 
	}
	curl_close($ch);
 	$getID3 = new getID3;
	if(!file_exists($localtempfilename)){
		echo '<br /><strong>Error read '.$localtempfilename.'</strong><br />';
	}
    $ThisFileInfo = $getID3->analyze($localtempfilename);
	
	echo 'version: '.$getID3->info['GETID3_VERSION'].'<br />';
	echo 'File: '.$ThisFileInfo['filenamepath'].'<br />';
	echo 'FileSize: '.$ThisFileInfo['filesize'].'<br />';
	echo 'FileSizeOfTempFile: '.filesize($localtempfilename).'<br />';
	echo 'MimeType: '.$ThisFileInfo['mime_type'].'<br />';
	echo 'Artist: '.(!empty($ThisFileInfo['comments_html']['artist']) ? implode('<br />', $ThisFileInfo['comments_html']['artist']) : '&nbsp;').'<br />';
	echo 'Title: '.(!empty($ThisFileInfo['comments_html']['title'])  ? implode('<br />', $ThisFileInfo['comments_html']['title'])  : '&nbsp;').'<br />';
	echo 'BitRate: '.(!empty($ThisFileInfo['audio']['bitrate'])        ? round($ThisFileInfo['audio']['bitrate'] / 1000).' kbps'   : '&nbsp;').'<br />';
	echo 'Playtime: '.(!empty($ThisFileInfo['playtime_string'])         ? $ThisFileInfo['playtime_string']                          : '&nbsp;').'<br />';
	
	if(!empty($ThisFileInfo['video']['resolution_x']) || !empty($ThisFileInfo['video']['resolution_y'])){
		$res_x=$ThisFileInfo['video']['resolution_x'];
		$res_y=$ThisFileInfo['video']['resolution_y']; 
	} else{
		$res_x='undefined';
		$res_y='undefined'; 
	}

	echo 'Resolution: '.$res_x.' x '.$res_y.'<br />';
	echo '<pre>';
	print_r($ThisFileInfo['video']);
	echo '</pre>';
	$m_stop = microtime(true);
   	$time = $m_stop - $m_start;
	echo "Load in $time Sekunden\n";
	echo '<hr />';
    // Delete temporary file
   	unlink($localtempfilename);
	  
}



?>
After testing the loading time, i download the file complete.

I thing 4.23723983765 seconds for an over 10 MB videofile, from server to server, are ok.

When anyone has a better code, please let me know.

greez
Tom

gratchen
User
Posts: 3
Joined: Mon Oct 17, 2011 12:20 pm
Are you a spambot?: no

Re: Remote Files Curl Headersize

Post by gratchen » Tue Oct 18, 2011 11:15 am

Many thanks for the code!! unfortunately don't have the better one yet . but when i do, will write!!

togo
User
Posts: 8
Joined: Sun Mar 20, 2011 11:03 am
Are you a spambot?: no
Location: Waltrop, NRW, Germany

Re: Remote Files Curl Headersize

Post by togo » Tue Oct 18, 2011 2:45 pm

Hi gratchen,
gratchen wrote:Many thanks for the code!! unfortunately don't have the better one yet . but when i do, will write!!
i can wait ;-)

Tom

Kumarasen
User
Posts: 2
Joined: Tue Aug 07, 2012 2:57 pm
Are you a spambot?: no

Re: Remote Files Curl Headersize

Post by Kumarasen » Tue Aug 07, 2012 3:30 pm

When i used this script it create a error in main file...

Code: Select all

require_once('./getid3/getid3.php');

$remotefilename = 'http://ex.anolis-film.de/V2/images/stories/media/video/big_buck_bunny.flv';//32768
getFileInfos($remotefilename,32768);
$remotefilename = 'http://ex.anolis-film.de/V2/images/stories/media/video/big_buck_bunny.f4v';//32768
getFileInfos($remotefilename,32768);
$remotefilename = 'http://ex.anolis-film.de/V2/images/stories/media/video/big_buck_bunny.jpg';//32768
getFileInfos($remotefilename);
$remotefilename = 'http://ex.anolis-film.de/V2/images/stories/media/video/big_buck_bunny.mp4';
getFileInfos($remotefilename);
$remotefilename = 'http://ex.anolis-film.de/V2/images/stories/media/video/big_buck_bunny.mov';
getFileInfos($remotefilename);
$remotefilename = 'http://ex.anolis-film.de/V2/images/stories/media/video/big_buck_bunny.webm';
getFileInfos($remotefilename);


function getFileInfos($remotefilename){
   $m_start = microtime(true);
   $localtempfilename = getcwd().'/tmp/'.'tmp_remote_'.basename($remotefilename);
   $out = fopen($localtempfilename,'wb');
   $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, $remotefilename);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLOPT_FILE, $out);

   curl_exec($ch);

   //file_put_contents( $localtempfilename, $data);
   if($ch == false) { 
      echo "Error is : ".curl_error ( $ch); 
   }
   curl_close($ch);
    $getID3 = new getID3;
   if(!file_exists($localtempfilename)){
      echo '<br /><strong>Error read '.$localtempfilename.'</strong><br />';
   }
    $ThisFileInfo = $getID3->analyze($localtempfilename);
   
   echo 'version: '.$getID3->info['GETID3_VERSION'].'<br />';
   echo 'File: '.$ThisFileInfo['filenamepath'].'<br />';
   echo 'FileSize: '.$ThisFileInfo['filesize'].'<br />';
   echo 'FileSizeOfTempFile: '.filesize($localtempfilename).'<br />';
   echo 'MimeType: '.$ThisFileInfo['mime_type'].'<br />';
   echo 'Artist: '.(!empty($ThisFileInfo['comments_html']['artist']) ? implode('<br />', $ThisFileInfo['comments_html']['artist']) : '&nbsp;').'<br />';
   echo 'Title: '.(!empty($ThisFileInfo['comments_html']['title'])  ? implode('<br />', $ThisFileInfo['comments_html']['title'])  : '&nbsp;').'<br />';
   echo 'BitRate: '.(!empty($ThisFileInfo['audio']['bitrate'])        ? round($ThisFileInfo['audio']['bitrate'] / 1000).' kbps'   : '&nbsp;').'<br />';
   echo 'Playtime: '.(!empty($ThisFileInfo['playtime_string'])         ? $ThisFileInfo['playtime_string']                          : '&nbsp;').'<br />';
   
   if(!empty($ThisFileInfo['video']['resolution_x']) || !empty($ThisFileInfo['video']['resolution_y'])){
      $res_x=$ThisFileInfo['video']['resolution_x'];
      $res_y=$ThisFileInfo['video']['resolution_y']; 
   } else{
      $res_x='undefined';
      $res_y='undefined'; 
   }

   echo 'Resolution: '.$res_x.' x '.$res_y.'<br />';
   echo '<pre>';
   print_r($ThisFileInfo['video']);
   echo '</pre>';
   $m_stop = microtime(true);
      $time = $m_stop - $m_start;
   echo "Load in $time Sekunden\n";
   echo '<hr />';
    // Delete temporary file
      unlink($localtempfilename);
     
}
__________________
Kumarasen

togo
User
Posts: 8
Joined: Sun Mar 20, 2011 11:03 am
Are you a spambot?: no
Location: Waltrop, NRW, Germany

Re: Remote Files Curl Headersize

Post by togo » Tue Aug 07, 2012 4:48 pm

Hi Kumarasen,

you dont wrote which error.

I think the files are deleted from the server.

Download the test files from
http://www.bigbuckbunny.org/
upload to your own server and edit the url 'http://ex.anolis-film.de/V2/images/stories/media/video/big_buck_bunny.flv to the url of your domain.
hope it helps.

tom

Locked