Location: PHPKode > projects > Multimedia2Multimedia > mm2mm/include/progressbar.php
<?php
date_default_timezone_set('Europe/Berlin');
error_reporting(E_ALL|E_STRICT);

require("progressbar_de_Du.php");
if (isset($_GET['lang']))
	$langfile = $_GET['lang'];
	else
	$langfile = "de_Du";
// $langfile = "en";

if(file_exists("progressbar_".$langfile.".php")) require("progressbar_".$langfile.".php");

sleep(3);
// Herausfinden wann Multimedia-Datei geschrieben wurde BEGIN
{
$tmp_file = "/tmp/mm2mm/job.php";
	$tmp_file_tohandle = fopen($tmp_file,"r");
	$multimediafile = fgets($tmp_file_tohandle);
	$multimediafile = explode('\'',$multimediafile);
	$multimediafile = $multimediafile[3];
	$multimediafile = stat($multimediafile);
	$multimediafile_created = $multimediafile[8];
	$multimediafile_now = time();
// 	echo $multimediafile;
}
// Herausfinden wann Multimedia-Datei geschrieben wurde END

// Herausfinden ob Prozess noch läuft BEGIN
{
$ffmpeg_in_progress = shell_exec("ps aux | grep -v grep | grep ffmpeg | grep www-data -c");
if ( $ffmpeg_in_progress[0] == 0)
	$ffmpeg_in_progress = shell_exec("sleep 5 && ps aux | grep -v grep | grep ffmpeg | grep www-data -c");
$ffmpeg_in_progress = $ffmpeg_in_progress[0];
$ffmpeg_in_progress = (int)$ffmpeg_in_progress;
// Herausfinden ob Prozess noch läuft END
}

// Gesamte Framezahl des Quellvideos herausfinden BEGIN
{
$frame_file = "/tmp/mm2mm/frame.txt";
	$frame_file_tohandle = fopen($frame_file,"r");
	$framenumber_whole = fgets($frame_file_tohandle);
	$framenumber_whole = (int)$framenumber_whole;
	if ( $framenumber_whole <= 0 ) die($lang_pb['nocalcable']);
// 	echo "\"".$framenumber_whole."\"";
// Gesamte Framezahl des Quellvideos herausfinden END
}
// Letzten bearbeiteten Frame herausfinden BEGIN
{
$prozess_file = "/tmp/mm2mm/convertlog.txt";
	$prozess_file_tohandle = fopen($prozess_file,"r");
while(!feof($prozess_file_tohandle)) {
	$prozess_status = fgets($prozess_file_tohandle);
	if  ( ( strlen($prozess_status) > 70 ) AND (preg_match("/frame/",$prozess_status)) )
		$framenumber_last = $prozess_status;
	}
// echo $framenumber_last;
$framenumber_last = explode('frame=',$framenumber_last);
$framenumber_last = str_replace("  ", "",$framenumber_last);
$framenumber_last = str_replace(" ", "",$framenumber_last);
$framenumber_last = $framenumber_last[(count($framenumber_last)-1)];
$framenumber_last = explode(' ',$framenumber_last);
$framenumber_last = $framenumber_last[0];
$framenumber_last = (int)$framenumber_last;
// echo $framenumber_last;
// Letzten bearbeiteten Frame herausfinden END
}
// Zeitberechnungen BEGIN
{
$prozess_in_percent = floor( ( 100 / $framenumber_whole * $framenumber_last ) );
if ( $prozess_in_percent < 1 ) $prozess_in_percent = 0.4;
if ( $prozess_in_percent > 100 ) $prozess_in_percent = 100;
$distance_from_create = ( time() - $multimediafile_created );		// Distance (schon xx Sekunden)
$distance_to_finish = round( $distance_from_create / $prozess_in_percent * ( 100 - $prozess_in_percent ));	// Distance
$distance_to_finish_sec = $distance_to_finish;
$time_finish = ( $distance_to_finish + time() );			// Timestamp
// $distance_to_finish = ( $time_finish - $multimediafile_now );
$date_finish = date($lang_pb['timeformat'],($time_finish));
// Seconds
{
if ( ( $distance_to_finish  > 0 ) AND ( $distance_to_finish  < 60 ) )
	$distance_to_finish = $distance_to_finish." ".$lang_pb['sec'];
}
// Minutes
{
if ( ( $distance_to_finish  >= 60 ) AND ( $distance_to_finish  < 3600 ) )
	$distance_to_finish = floor($distance_to_finish/60)." ".$lang_pb['min'];
}
// Hours
{
if ( $distance_to_finish  >= 3600 ) {
	$distance_to_finish = floor($distance_to_finish/60);
	$distance_to_finish_h = floor($distance_to_finish/60);
	$distance_to_finish_m = ($distance_to_finish-($distance_to_finish_h*60));
	if ( $distance_to_finish_m < 10 )
		$distance_to_finish_m = "0".$distance_to_finish_m;
	$distance_to_finish = $distance_to_finish_h.":".$distance_to_finish_m."&nbsp;".$lang_pb['hour'];
}
}

// Zeitberechnungen BEGIN
}

echo ("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
	\"http://www.w3.org/TR/html4/loose.dtd\">
<html>
	<head>
");

if ( $ffmpeg_in_progress != 0 ) {
	echo ("		<meta http-equiv=\"refresh\" content=\"2; URL=progressbar.php?lang=".$langfile."\">
");
/*	echo ("		<meta http-equiv=\"refresh\" content=\"2; URL=progressbar.php\">
");*/
	}

echo ("		<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">
		<title>mm2mm-progressbar</title>
	</head>
	<body>
");


// echo ("<br><br><br><br>\"Ich codiere ".$framenumber_whole." Frames, bin bei Framenummer: ".$framenumber_last.",<br>das sind ".$prozess_in_percent."%, daf&uuml;r brauche ich noch ".$distance_to_finish_sec." Sekunden,<br>".$distance_from_create." Sekunden bin ich schon dran.\"<br><pre>".$prozess_status."</pre><br><br>");

if ( $ffmpeg_in_progress != 0 ) {
$balkenbreite = 300;
$balkenbreite_l = ( $balkenbreite / 100 * $prozess_in_percent );
$balkenbreite_r = ( $balkenbreite - $balkenbreite_l );

echo ("		<div style=\"width:".($balkenbreite+6)."px;height:26px;position:absolute;background-color:#BEBECC;top:0px;left:0px;\">
			<div style=\"width:".$balkenbreite_l."px;height:20px;background-color:#8B8B95;position:absolute;top:3px;left:3px;\">
			</div>
			<div style=\"width:".$balkenbreite_r."px;height:20px;background-color:#BEBECC;position:absolute;top:3px;right:3px;\">
			</div>
		</div>
		<div style=\"width:".($balkenbreite+6)."px;height:50px;position:absolute;top:27px;left:0px;\">
			<table border=\"0\" width=\"".($balkenbreite+6)."px\">
				<tr valign=\"top\">
					<td align=\"left\">
						".floor($prozess_in_percent)."%
					</td>
					<td align=\"right\">
						".$distance_to_finish."&nbsp;<small>(".date($lang_pb['timeformat'],$time_finish).")</small>
					</td>
				</tr>
			</table>
		</div>
");
	} else {
	echo ($lang_pb['finish']);
	}
// echo ("<br><br><br><br>schon ".$distance_from_create." Sekunden<br>noch ".$distance_to_finish."<br>werde fertig sein um: ".date($lang_pb['timeformat'],$time_finish)." ".$lang_pb['oclock']);

echo ("
	</body>
</html>
");

?>
Return current item: Multimedia2Multimedia