<?php


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

function custom_video_to_frame($video,$vWt)
{
	global $config;
	$duration = get_duration($config['mplayer'],$video);	
	$x = array_reverse(explode(".",$video)); 
	$y = explode("/",$x[1]); 
	$videoid = end($y); 
	$fc = 0;
	exec("mkdir ".$config[tmpimgpath]."/$videoid");
        for($i=1;$i<=4;$i++)
        {
			$dur = rand(0,$duration);
			$keep = strpos($vWt, $i."");
			if($keep === false)
			{
				exec($config[ffmpeg]." -i ".$config[videodir]."/$videoid.flv -an -ss $dur -an -r 2 -vframes 1 -y ".$config[tmpimgpath]."/".$videoid."/$i-0000000%d.jpg");
			}
			 
			$myvideoimgnew = $config[thumbdir]."/".$videoid."-".$i.".jpg";

			$myconvertimg = $config[tmpimgpath]."/".$videoid."/$i-00000001.jpg";
			
			if(!file_exists($myconvertimg))
			{
				$myconvertimg = $config[imagedir]."/videoconvert.gif";
			}
			generatevideothumbs($myconvertimg,$myvideoimgnew,$config[max_thumb_width],$config[max_thumb_height]);
       }
}
function get_duration($mplayer, $vsource)
{
	
	exec("$mplayer -vo null -ao null -frames 0 -identify $vsource", $p);
	while(list($k,$v)=each($p))
	{
		if($length=strstr($v,'ID_LENGTH='))	break;
	}
	$lx = explode("=",$length);
	$duration = $lx[1];
	return $duration;
}

$vWt = htmlentities(strip_tags($_POST['vWt']));
$VIDEOID = htmlentities(strip_tags($_POST['VIDEOID']));
$thumbgen =  $config['videodir'].'/'.$VIDEOID.".flv";
custom_video_to_frame($thumbgen,$vWt);
echo $file;
?>
