<?php


include("include/config.php");
include("include/functions/import.php");

$original = $_SERVER['argv'][1]; 
$videoid = $_SERVER['argv'][2]; 
$videor = $_SERVER['argv'][3]; 

if (($original != "") && ($videoid != "") && ($videor != ""))
{
	if($config[resize_video] == 1)
	{
		$runinbg = "$config[mencoder] $config[originalvdir]/$original -o $config[videodir]/".$videoid."x.flv -of lavf -oac mp3lame -lameopts abr:br=56 -ovc lavc -lavcopts vcodec=flv:vbitrate=$config[vbitrate]:mbd=2:mv0:trell:v4mv:cbp:last_pred=3 -lavfopts i_certify_that_my_video_stream_does_not_use_b_frames -vop scale=$config[vresize_x]:$config[vresize_y] -srate $config[sbitrate]";
	}
	else
	{
		$runinbg = "$config[mencoder] $config[originalvdir]/$original -o $config[videodir]/".$videoid."x.flv -of lavf -oac mp3lame -lameopts abr:br=56 -ovc lavc -lavcopts vcodec=flv:vbitrate=$config[vbitrate]:mbd=2:mv0:trell:v4mv:cbp:last_pred=3 -lavfopts i_certify_that_my_video_stream_does_not_use_b_frames -srate $config[sbitrate]";
	}

	if (substr($original, -4) != ".flv")
	{
		$runconvert = exec("$runinbg");
	}
	else
	{
		copy ($config[originalvdir].'/'.$original , $config[videodir].'/'.$videoid.'x.flv');
		$runconvert=true;
	}

	if ($runconvert)
	{
		exec("$config[metainject] -Uv $config[videodir]/".$videoid."x.flv $config[videodir]/".$videoid.".flv");
		@unlink("$config[videodir]/".$videoid."x.flv");

		generate_videos_thumbs($videor, $videoid);


    	if ($config['keep_original_video'] == "0") 
    	{ 
    		if (filesize($config[videodir]."/".$videoid.".flv") > 0 && file_exists($config[videodir]."/".$videoid.".flv")) 
      		{ 
        		$deletetempvideo = $config[originalvdir]."/".$original; 
        		@chmod($deletetempvideo, 0777); 
        		@unlink($deletetempvideo); 
      		} 

			for($tt=1;$tt<5;$tt++)
    		{
				$tempthumb = $config['tmpimgpath']."/".$videoid."/0000000".$tt.".jpg";
    			if(file_exists($tempthumb)) 
				{
					@unlink($tempthumb);
				}
			}
    	
			@rmdir($config['tmpimgpath']."/".$videoid);
    	} 
	}
}

?>  