%PDF- %PDF-
Direktori : /home/nailstv/public_html/at.nails.tv/ |
Current File : /home/nailstv/public_html/at.nails.tv/_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('f',$video['id']); $sql = "UPDATE video SET hossz = '".$hossz."', konvertalas = ? 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']; $destFile = $base_path . 'mp4/'. $n_filename . '.mp4'; // OLD $convert_cmd = 'ffmpeg -y -i '.$srcFile.' -strict -2 -threads 8 -qscale 100 '.$destFile.' 2> /dev/null &'; $convert_cmd = 'ffmpeg -y -i '.$srcFile.' -vcodec libx264 -qmin 10 -qmax 42 -maxrate 1500k -bufsize 3000k -vprofile high -preset slower -b:v 1500k -cpu-used 4 -threads 8 -acodec libfaac -ab 128k '.$destFile.' > /dev/null 2>&1 &'; file_put_contents('debug_convert.txt',date('Y.m.d H:i:s').' '.$convert_cmd."\n",FILE_APPEND); // ~> False $bind = array(basename($destFile),'f',$video['id']); $sql = "UPDATE video SET file_mp4 = ?, konvertalas = ? WHERE id = ?"; $db->query($sql, $bind); // ******************** $c = exec($convert_cmd); //echo $srcFile . ' | ' . $destFile . '|| CMD: ' . $convert_cmd . "<br />\n"; /* 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'; // OLD $convert_cmd = 'ffmpeg -y -i '.$srcFile.' -strict -2 -threads 8 -b:v 1M '.$destFile.' 2> /dev/null &'; $convert_cmd = 'ffmpeg -y -i '.$srcFile.' -vcodec libx264 -qmin 10 -qmax 42 -maxrate 1500k -bufsize 3000k -vprofile high -preset slower -b:v 1500k -cpu-used 4 -threads 8 -acodec libfaac -ab 128k '.$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'; // OLD $convert_cmd = 'ffmpeg -y -i '.$srcFile.' -strict -2 -threads 8 -qscale 100 '.$destFile.' 2> /dev/null &'; $convert_cmd = 'ffmpeg -y -i '.$srcFile.' -vcodec libx264 -qmin 10 -qmax 42 -maxrate 1500k -bufsize 3000k -vprofile high -preset slower -b:v 1500k -cpu-used 4 -threads 8 -acodec libfaac -ab 128k '.$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_mp4 = ?, 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 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 = array(); $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'); // file_put_contents('debug_convert.txt',date('Y.m.d H:i:s').' '.$videolength."\n",FILE_APPEND); if ( $videolength > 0 ) { $retval = 0; // 10db thumbnailt szeretn�nk $leptek = intval( $videolength / 10 ); $frames = array( 1 ); for ( $i = 1; $i < 10; $i ++ ) { $frametime = $leptek * $i; $frames[] = $frametime; } // file_put_contents('debug_convert.txt',date('Y.m.d H:i:s').' FRAMES: ||'.print_r($frames,true)."\n",FILE_APPEND); 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 file = ? AND tipus = 'video'"; $db->query( $sql, array($video['id'],$filename) ); 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->Execute( $sql ); } else { $sql = "INSERT INTO `kep`(`galeria_id`, `tipus`, `file`, `sorrend`, `def`) VALUES ('" . $video['id'] . "', 'video', '" . $filename . "', '" . $sorrend . "', 'f');"; $db->Execute( $sql ); } // file_put_contents('debug_convert.txt',date('Y.m.d H:i:s').' SQL: ||'.$sql."\n",FILE_APPEND); } $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 > /dev/null 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"; } } */ } } }