%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/nailstv/public_html/ua.nails.tv/admin_back/
Upload File :
Create Path :
Current File : /home/nailstv/public_html/ua.nails.tv/admin_back/_converter.php

<?php

require_once '../config/config.php';
error_reporting(E_ALL);

$db = Db::getInstance();
Registry::set('db', $db);

$_id = (int) $argv[1];

$sql = "SELECT * FROM video WHERE id = " . $_id;
$row = $db->GetRow($sql);
if(!empty($row['file']))
{
	$file = dirname(__FILE__).'/../video/' . $row['file'];
}


file_put_contents('debug.txt',date('Y.m.d H:i:s').' [~] Converter[C]:  ['.$_id.']['.$file.']'."\n",FILE_APPEND);

updateHossz($row);
convertMediaContent($row);
kepekMentese($row);

function updateHossz($video)
{
	$db = Registry::get('db');

	$file = dirname(__FILE__).'/../video/' . $video['file'];

	$ffmpegInstance = new ffmpeg_movie($file);
	$hossz = $ffmpegInstance->getDuration();

	//$hossz = '187.99200439453';
	$perc = intval($hossz / 60);
	$sec = intval($hossz - ($perc * 60));

	if($sec < 10){
		$sec = '0' . $sec;
	}

	if($perc < 10){
		$perc = '0' . $perc;
	}

	$time = array($perc, $sec);

	$hossz = implode(':', $time);

	$hossz .= ':00';

	$bind = array($video['id']);

	$sql = "UPDATE video SET hossz = '".$hossz."' WHERE id = ?";
	$db->query($sql,$bind);

}

function konvertVideoToMP4($video, $ext)
{
	$db = Registry::get('db');

	$filename = $ext[0] . '.mp4';
	// Set our source file
	$srcFile = dirname(__FILE__).'/../video/' . $video['file'];
	$destFile = dirname(__FILE__).'/../video/' . $ext[0] . '.mp4';
	$ffmpegPath = "/usr/bin/ffmpeg";
	$flvtool2Path = " /usr/bin/flvtool2";
	// Create our FFMPEG-PHP class
	$ffmpegObj = new ffmpeg_movie($srcFile);

	// Save our needed variables
	$srcWidth = makeMultipleTwo($ffmpegObj->getFrameWidth());
	$srcHeight = makeMultipleTwo($ffmpegObj->getFrameHeight());
	$srcFPS = $ffmpegObj->getFrameRate();
	$srcAB = intval($ffmpegObj->getAudioBitRate()/1000);
	$srcAR = $ffmpegObj->getAudioSampleRate();
	// Call our convert using exec()
	//exec($ffmpegPath . " -i " . $srcFile . " -ar " . $srcAR . " -ab " . $srcAB . " -f flv -s " . $srcWidth . "x" . $srcHeight . " " . $destFile . " | " . $flvtool2Path . " -U stdin " . $destFile);
	//exec($ffmpegPath . " -i " . $srcFile . " -vcodec libx264 -sameq" . $destFile);
	//die('asd');
	//ffmpeg.exe -i INPUT.wmv -vcodec libx264  -sameq OUTPUT.mp4

	exec($ffmpegPath . " -y -i " . $srcFile . " -acodec libfaac -sameq -ar 44100 -ab 96k -coder ac -me_range 16 -subq 5 -sc_threshold 40 -b 1600k -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -i_qfactor 0.71 -keyint_min 25 -b_strategy 1 -g 250 -r 20 " . $destFile);
	// Make multiples function

	$bind = array($filename, $video['id']);
	$sql = "UPDATE video SET file_mp4 = ? WHERE id = ?";
	$db->query($sql, $bind);
}

function makeMultipleTwo ($value)
{
	$sType = gettype($value/2);
	if($sType == "integer"){
		return $value;
	} else {
		return ($value-1);
	}
}

function convertMediaContent($video)
{
	$base_path = dirname(__FILE__).'/../video/';

	//$filename = basename($video['file']);

	$db = Registry::get('db');

	$filename   = substr($video['file'], 0, strrpos($video['file'], '.'));
	$n_filename = str_replace('.flv','',$filename);
	$extension  = substr($video['file'], strrpos($video['file'], '.') + 1);

	$srcFile = $base_path . $video['file'];


	// DEV: ffmpeg -i video/348_summer_royalgel_collection-_ok.flv -strict -2 -threads 8 -qscale 75 video/webm/__348_summer.webm
	// LIVE: ffmpeg -i 350_mehesz_szandi_kari-.flv -strict -2 -threads 8 -b:v 6M webm/__350_mehesz_szandi_k1.webm

	/*

	 ffmpeg -y -i /var/www/development/www.mukorom.tv/video/352_347_party_on_4festivals-ok.flv -c:v libx264 -strict 2 -profile:v baseline -movflags faststart /var/www/development/www.mukorom.tv/video/mp4/352_347_party_on_4festivals-ok.mp4
	 */
	switch ($extension)
	{
		case 'mp4':

			// ~ Convert to WEBM
			$destFile = $base_path . 'webm/'. $n_filename . '.webm';

			$convert_cmd = 'ffmpeg -y -i '.$srcFile.' -strict -2 -threads 8 -b:v 1M '.$destFile.' 2> /dev/null &';
			file_put_contents('debug_convert.txt',date('Y.m.d H:i:s').' '.$convert_cmd."\n",FILE_APPEND);

			$c = exec($convert_cmd);
			//echo $srcFile . ' | ' . $destFile . '|| CMD: ' . $convert_cmd . "<br />\n";
			$bind = array(basename($destFile),$video['file'],'t',$video['id']);
			$sql = "UPDATE video SET file_webm = ?, file_mp4 = ?, konvertalas = ? WHERE id = ?";
			$db->query($sql, $bind);

			break;

		case 'webm':

			// ~ Convert to MP4
			$destFile = $base_path . 'mp4/'.  $n_filename . '.mp4';

			$convert_cmd = 'ffmpeg -y -i '.$srcFile.' -strict -2 -threads 8 -qscale 100 '.$destFile.' 2> /dev/null &';
			file_put_contents('debug_convert.txt',date('Y.m.d H:i:s').' '.$convert_cmd."\n",FILE_APPEND);

			$c = exec($convert_cmd);
			//echo $srcFile . ' | ' . $destFile . '|| CMD: ' . $convert_cmd . "<br />\n";
			$bind = array(basename($destFile),$video['file'],'t',$video['id']);
			$sql = "UPDATE video SET file_mp4 = ?, file_webm = ?, konvertalas = ? WHERE id = ?";
			$db->query($sql, $bind);

			break;

		default:

			// ~ Convert to WEBM & MP4
			$destFile = $base_path . 'mp4/'. $n_filename . '.mp4';

			$convert_cmd = 'ffmpeg -y -i '.$srcFile.' -strict -2 -threads 8 -qscale 255 '.$destFile.' 2> /dev/null &';
			file_put_contents('debug_convert.txt',date('Y.m.d H:i:s').' '.$convert_cmd."\n",FILE_APPEND);

			$c = exec($convert_cmd);
			//echo $srcFile . ' | ' . $destFile . '|| CMD: ' . $convert_cmd . "<br />\n";
			$bind = array(basename($destFile), $video['id']);
			$sql = "UPDATE video SET file_mp4 = ? WHERE id = ?";
			$db->query($sql, $bind);

			// Webm
			$destFile = $base_path .'webm/'.  $n_filename . '.webm';

			$convert_cmd = 'ffmpeg -y -i '.$srcFile.' -strict -2 -threads 8 -b:v 1M '.$destFile.' 2> /dev/null &';
			file_put_contents('debug_convert.txt',date('Y.m.d H:i:s').' '.$convert_cmd."\n",FILE_APPEND);

			$c = exec($convert_cmd);
			//echo $srcFile . ' | ' . $destFile . '|| CMD: ' . $convert_cmd . "<br />\n";
			$bind = array(basename($destFile),'t', $video['id']);
			$sql = "UPDATE video SET file_webm = ?, konvertalas = ? WHERE id = ?";
			//$db->query($sql, $bind);

			break;
	}



}

function konvertVideoToFlv($videom, $ext)
{
	// Set our source file
	$srcFile = dirname(__FILE__).'/../video/' . $video['file'];
	$destFile = dirname(__FILE__).'/../video/' . $ext[0] . '.flv';
	$ffmpegPath = "/usr/bin/ffmpeg";
	$flvtool2Path = " /usr/bin/flvtool2";
	// Create our FFMPEG-PHP class
	$ffmpegObj = new ffmpeg_movie($srcFile);

	// Save our needed variables
	$srcWidth = makeMultipleTwo($ffmpegObj->getFrameWidth());
	$srcHeight = makeMultipleTwo($ffmpegObj->getFrameHeight());
	$srcFPS = $ffmpegObj->getFrameRate();
	$srcAB = intval($ffmpegObj->getAudioBitRate()/1000);
	$srcAR = $ffmpegObj->getAudioSampleRate();
	// Call our convert using exec()
	exec($ffmpegPath . " -i " . $srcFile . " -ar " . $srcAR . " -ab " . $srcAB . " -f flv -s " . $srcWidth . "x" . $srcHeight . " " . $destFile . " | " . $flvtool2Path . " -U stdin " . $destFile);
	// Make multiples function
	function makeMultipleTwo ($value)
	{
		$sType = gettype($value/2);
		if($sType == "integer"){
			return $value;
		} else {
			return ($value-1);
		}
	}
}

function kepekMentese($video)
{
	$dir = "../video/" . $video['id'];
	$thumbdir_kicsi = '150_85';
	$thumbdir = '180_102';
	$thumbdir_nagy = '680_382';
	$subdir=$dir . '/' . $thumbdir;
	$subdir2=$dir . '/' . $thumbdir_nagy;
	$subdir3=$dir . '/' . $thumbdir_kicsi;

	if (!is_dir($dir)) {
		mkdir($dir, 0777);
		mkdir($subdir, 0777);
		mkdir($subdir2, 0777);
		mkdir($subdir3, 0777);
	}

	$in = dirname(__FILE__).'/../video/' . $video['file'];
	$out = dirname(__FILE__).'/../video/' . $video['id'] . '/';
	$out_nagy = "video/" . $video['id'] . '/' . $thumbdir_nagy . '/';
	$out_kicsi = "video/" . $video['id'] . '/' . $thumbdir_kicsi . '/';

	ExtractThumb($in, $out, $out_nagy, $out_kicsi, $video);
}

function ExtractThumb($in, $out, $out_nagy, $out_kicsi, $video)
{
	$db = Registry::get( 'db' );

	$thumb_stdout;
	$errors;
	$retval = 0;

	$ffmpegInstance = new ffmpeg_movie( $in );
	$videolength    = $ffmpegInstance->getDuration();

	$video_width  = $ffmpegInstance->getFrameWidth();
	$video_height = $ffmpegInstance->getFrameHeight();

	//print $video_width; print '<br>'; print $video_height; die('www');

	if ( $videolength > 0 )
	{

		$thumb_stdout;
		$errors;
		$retval = 0;

		// 10db thumbnailt szeretn�nk
		$leptek = intval( $videolength / 10 );

		$frames = array( 1 );

		for ( $i = 1; $i < 10; $i ++ )
		{
			$frametime = $leptek * $i;
			$frames[]  = $frametime;
		}

		foreach ( $frames as $key => $val )
		{
			$thumbNum      = $key + 1;
			$kimenet       = $out . $thumbNum . '.jpg';
			$kimenet_kicsi = $out_kicsi . $thumbNum . '.jpg';
			$kimenet_nagy  = $out_nagy . $thumbNum . '.jpg';
			$filename      = $thumbNum . '.jpg';

			//insert to db
			$bind = array( $video['id'] );

			// Delete the file if it already exists
			if ( file_exists( $kimenet ) )
			{
				$sql = "DELETE FROM kep WHERE galeria_id = ? AND tipus = 'video'";
				$db->query( $sql, $bind );

				unlink( $kimenet );
				unlink( $kimenet_kicsi );
				unlink( $kimenet_nagy );
			}

			$sql     = "SELECT MAX(sorrend) as sorrend FROM kep WHERE galeria_id = ? AND tipus = 'video'";
			$sorrend = $db->GetRow( $sql, $bind );

			if ( empty($sorrend['sorrend']) )
			{
				$sorrend = 10;
			}
			else
			{
				$sorrend = $sorrend['sorrend'] + 10;
			}

			if ( $key == 3 )
			{
				$sql = "INSERT INTO `kep`(`galeria_id`, `tipus`, `file`, `sorrend`, `def`) VALUES ('" . $video['id'] . "', 'video', '" . $filename . "', '" . $sorrend . "', 't')";
				$db->query( $sql );
			}
			else
			{
				$sql = "INSERT INTO `kep`(`galeria_id`, `tipus`, `file`, `sorrend`, `def`) VALUES ('" . $video['id'] . "', 'video', '" . $filename . "', '" . $sorrend . "', 'f')";
				$db->query( $sql );
			}
		}

		$sql = "UPDATE video set konvertalas = 't' WHERE id = ?";
		$db->query( $sql, $bind );

		foreach ( $frames as $key => $val )
		{
			$thumbNum        = $key + 1;
			$kimenet         = $out . $thumbNum . '.jpg';
			$kimenet_kicsi   = $out_kicsi . $thumbNum . '.jpg';
			$kimenet_nagy    = $out_nagy . $thumbNum . '.jpg';
			$kimenet_kozepes = $out . '180_102/' . $thumbNum . '.jpg';

			$filename = $thumbNum . '.jpg';

			$thumb       = "video/" . $video['id'] . "/";
			$out_kozepes = $thumb . "180_102/";

			// Use ffmpeg to generate a thumbnail from the movie
			$cmd = "ffmpeg -itsoffset -" . $val . " -i $in -vcodec mjpeg -vframes 1 -an -f rawvideo -s " . $video_width . "x" . $video_height . " $kimenet 2>&1";
			exec( $cmd, $thumb_stdout, $retval );

			//thumb gener�l�s

			Files::thumbNail( $thumb, $out_kicsi, $filename, 150, 85, 1 );
			Files::thumbNail( $thumb, $out_kozepes, $filename, 180, 102, 1 );
			Files::thumbNail( $thumb, $out_nagy, $filename, 680, 382, 1 );

			/*$cmd = "ffmpeg -itsoffset -".$val." -i $in -vcodec mjpeg -vframes 1 -an -f rawvideo -s 150x85 $kimenet_kicsi 2>&1";
			exec($cmd, $thumb_stdout, $retval);

			$cmd = "ffmpeg -itsoffset -".$val." -i $in -vcodec mjpeg -vframes 1 -an -f rawvideo -s 680x382 $kimenet_nagy 2>&1";
			exec($cmd, $thumb_stdout, $retval);*/


			// Queue up the error for processing
			if ( $retval != 0 )
			{
				$errors[] = "FFMPEG thumbnail gener�l�si hiba";
			}
			/*
			if (!empty($thumb_stdout))
			{
				foreach ($thumb_stdout as $line)
				{
					echo $line . "
					\n";
				}
			}

			if (!empty($errors))
			{
				foreach ($errors as $error)
				{
					echo $error . "
					\n";
				}
			}
			*/
		}
	}

}


Zerion Mini Shell 1.0