public function generate_preview(&$upload_data, $filename, $ext)
 {
     $upload_data['duration'] = file_exists($filename) ? ffmpeg::get_mpeg_length($filename) : null;
     $upload_data['is_audio'] = 1;
     $icon = $this->generate_icon($ext);
     ffmpeg::audio_mp3($filename);
     $upload_data['preview'] = $this->save_preview($upload_data, $icon);
 }
 public function generate_preview(&$upload_data, $filename, $ext)
 {
     $upload_data['duration'] = file_exists($filename) ? ffmpeg::get_mpeg_length($filename) : null;
     $upload_data['is_video'] = 1;
     $dimensions = file_exists($filename) ? ffmpeg::get_video_dimensions($filename) : array('height' => null, 'width' => null);
     $upload_data['image_width'] = $dimensions['width'];
     $upload_data['image_height'] = $dimensions['height'];
     $upload_data['image_size_str'] = 'width="' . $dimensions['width'] . '" height="' . $dimensions['height'] . '"';
     //create thumbnail
     $s = ffmpeg::duration_to_seconds($upload_data['duration']);
     $s = $s / 2;
     $d = ffmpeg::seconds_to_duration($s) . ".1";
     //create thumbnail
     ffmpeg::extract_frame($filename, $d);
     $fn = substr($filename, 0, strrpos($filename, '.')) . '.jpg';
     $upload_data['preview'] = $this->save_preview($upload_data, $fn);
 }
 /**
  * undocumented function
  *
  * @return void
  * @author Andy Bennett
  */
 public function video_get()
 {
     $v = Input::instance()->get('video', false);
     $p = Input::instance()->get('picture', false);
     $path = DOCROOT . 'staticfiles/video/';
     if ($v === false or !file_exists($path . $v)) {
         Kohana::show_404($v, 'common/error_404');
     }
     $data['path'] = url::base() . 'staticfiles/video/';
     $data['name'] = $v;
     if ($p !== false) {
         $data['picture'] = '/staticfiles/img/' . $p;
     }
     $data['dimensions'] = ffmpeg::get_video_dimensions($path . $v);
     Assets::instance()->add_css('/cache/css/ffmpeg');
     $c = View::factory('videoplayer', $data)->render();
     Display::instance()->display($c);
 }
 /**
  * convert video to mp4
  *
  * @param string $file 
  * @return void
  * @author Andy Bennett
  */
 public static function video_mp4($file = null)
 {
     if (is_null($file)) {
         throw new Exception("No filepath supplied", 1);
     }
     if (!file_exists($file)) {
         throw new Exception("Invalid filepath supplied", 1);
     }
     // get the filename parts
     $path = pathinfo($file, PATHINFO_DIRNAME);
     $filename = pathinfo($file, PATHINFO_FILENAME);
     $tmp_dir = Kohana::config('ffmpeg.tmp_path');
     // set the output details
     $output = $path . '/' . $filename . '-c.mp4';
     $infile = $file;
     $options = "-vcodec libx264 -b 512k -flags +loop+mv4 -cmp 256 \\\n\t\t\t\t\t-partitions +parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 \\\n\t\t\t   \t\t-me_method hex -subq 7 -trellis 1 -refs 5 -bf 3 \\\n\t\t\t   \t\t-flags2 +bpyramid+wpred+mixed_refs+dct8x8 -coder 1 -me_range 16 \\\n\t\t\t\t\t-r 25 -g 5 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qmin 10 \\\n\t\t\t\t\t-qmax 51 -qdiff 4";
     $str = 'cd ' . $tmp_dir . '; ' . Kohana::config('ffmpeg.binaries_path') . " -y -i {$infile} -an -pass 1 -threads 2 {$options} {$output}";
     // echo( $str );
     exec($str . ' 2>&1', $buffer1);
     $has_audio = ffmpeg::has_audio($file);
     $audio = $has_audio ? "-acodec libfaac -ar 44100 -ab 96k" : "-an";
     $str = 'cd ' . $tmp_dir . '; ' . Kohana::config('ffmpeg.binaries_path') . " -y -i {$infile} {$audio} -pass 2 -threads 2 {$options} {$output}; /usr/bin/MP4Box -hint {$output}";
     // echo( $str );
     exec($str . ' 2>&1', $buffer2);
     // qt-faststart $tmpfile $outfile
     if (!file_exists($output) or !filesize($output)) {
         Kohana::log('error', 'Video encoding error');
         Kohana::log('error', Kohana::debug($buffer1));
         Kohana::log('error', Kohana::debug($buffer2));
         // var_dump( $buffer );
         throw new Exception('Video conversion error');
     }
     return $output;
 }
Exemple #5
0
 /**
  * Returns information about the specified file without having to use ffmpeg-php
  * as it consults the ffmpeg binary directly. This idea for this function has been borrowed from
  * a French ffmpeg class located: http://www.phpcs.com/codesource.aspx?ID=45279
  * 
  * @access public
  * @todo Change the search from string explode to a regex based search
  * @author Yaug - Manuel Esteban yaug@caramail.com
  * @param string $file The absolute path of the file that is required to be manipulated.
  * @return mixed false on error encountered, true otherwise
  **/
 public function getFFmpegInfo()
 {
     if (ffmpeg::$ffmpeg_info !== false) {
         return ffmpeg::$ffmpeg_info;
     }
     $format = '';
     $info_file = $this->_tmp_directory . $this->unique('ffinfo') . '.info';
     // 			execute the ffmpeg lookup
     exec(FFMPEG_BINARY . ' -formats &> ' . $info_file);
     $data = false;
     // 			try to open the file
     $handle = fopen($info_file, 'r');
     if ($handle) {
         $data = array();
         $buffer = '';
         // 				loop through the lines of data and collect the buffer
         while (!feof($handle)) {
             $buffer .= fgets($handle, 4096);
         }
         // 				die($buffer);
         $data['compiler'] = array();
         $look_ups = array('configuration' => 'configuration: ', 'formats' => 'File formats:', 'codecs' => 'Codecs:', 'filters' => 'Bitstream filters:', 'protocols' => 'Supported file protocols:', 'abbreviations' => 'Frame size, frame rate abbreviations:', 'Note:');
         $total_lookups = count($look_ups);
         $pregs = array();
         $indexs = array();
         foreach ($look_ups as $key => $reg) {
             if (strpos($buffer, $reg) !== false) {
                 $index = array_push($pregs, $reg);
                 $indexs[$key] = $index;
             }
         }
         preg_match('/' . implode('(.*)', $pregs) . '/s', $buffer, $matches);
         $configuration = trim($matches[$indexs['configuration']]);
         // 				grab the ffmpeg configuration flags
         preg_match_all('/--[a-zA-Z0-9\\-]+/', $configuration, $config_flags);
         $data['compiler']['configuration'] = $config_flags[0];
         // 				grab the versions
         $data['compiler']['versions'] = array();
         preg_match_all('/([a-zA-Z0-9\\-]+) version: ([0-9\\.]+)/', $configuration, $versions);
         for ($i = 0, $a = count($versions[0]); $i < $a; $i++) {
             $data['compiler']['versions'][strtolower(trim($versions[1][$i]))] = $versions[2][$i];
         }
         // 				grab the ffmpeg compile info
         preg_match('/built on (.*), gcc: (.*)/', $configuration, $conf);
         if (count($conf) > 0) {
             $data['compiler']['gcc'] = $conf[2];
             $data['compiler']['build_date'] = $conf[1];
             $data['compiler']['build_date_timestamp'] = strtotime($conf[1]);
         }
         // 				grab the file formats available to ffmpeg
         preg_match_all('/ (DE|D|E) (.*) {1,} (.*)/', trim($matches[$indexs['formats']]), $formats);
         $data['formats'] = array();
         // 				loop and clean
         for ($i = 0, $a = count($formats[0]); $i < $a; $i++) {
             $data['formats'][strtolower(trim($formats[2][$i]))] = array('encode' => $formats[1][$i] == 'DE' || $formats[1][$i] == 'E', 'decode' => $formats[1][$i] == 'DE' || $formats[1][$i] == 'D', 'fullname' => $formats[3][$i]);
         }
         // 				grab the bitstream filters available to ffmpeg
         $filters = trim($matches[$indexs['filters']]);
         $data['filters'] = empty($filters) ? array() : explode(' ', $filters);
         // 				grab the file prototcols available to ffmpeg
         $protocols = trim($matches[$indexs['protocols']]);
         $data['protocols'] = empty($protocols) ? array() : explode(' ', str_replace(':', '', $protocols));
         // 				grab the abbreviations available to ffmpeg
         $abbreviations = trim($matches[$indexs['abbreviations']]);
         $data['abbreviations'] = empty($abbreviations) ? array() : explode(' ', $abbreviations);
         ffmpeg::$ffmpeg_info = $data;
     }
     fclose($handle);
     if (is_file($info_file)) {
         //	 			if the info file exists remove it
         unlink($info_file);
     }
     return $data;
 }
Exemple #6
-1
     unlink($testVidsDir . '/output.log');
 }
 $res169 = array();
 $res169['240'] = array('427', '240');
 $res169['360'] = array('640', '360');
 $res169['480'] = array('853', '480');
 $res169['720'] = array('1280', '1280');
 $res169['1080'] = array('1920', '1080');
 $res43 = array();
 $res43['240'] = array('320', '240');
 $res43['360'] = array('480', '360');
 $res43['480'] = array('640', '480');
 $res43['720'] = array('960', '1280');
 $res43['1080'] = array('1440', '1080');
 $configs = array('use_video_rate' => true, 'use_video_bit_rate' => true, 'use_audio_rate' => true, 'use_audio_bit_rate' => true, 'use_audio_codec' => true, 'format' => 'flv', 'video_codec' => config('video_codec'), 'audio_codec' => config('audio_codec'), 'audio_rate' => config("srate"), 'audio_bitrate' => config("sbrate"), 'video_rate' => config("vrate"), 'video_bitrate' => config("vbrate"), 'normal_res' => config('normal_resolution'), 'high_res' => config('high_resolution'), 'max_video_duration' => config('max_video_duration'), 'res169' => $res169, 'res43' => $res43, 'resize' => 'max');
 $ffmpeg = new ffmpeg($victimFile);
 $ffmpeg->configs = $configs;
 $ffmpeg->gen_thumbs = false;
 $ffmpeg->gen_big_thumb = false;
 $ffmpeg->num_of_thumbs = config('num_thumbs');
 $ffmpeg->thumb_dim = config('thumb_width') . "x" . config('thumb_height');
 $ffmpeg->big_thumb_dim = config('big_thumb_width') . "x" . config('big_thumb_height');
 $ffmpeg->tmp_dir = TEMP_DIR;
 $ffmpeg->input_ext = $ext;
 $ffmpeg->output_file = $victimOutput;
 $ffmpeg->hq_output_file = $victimOutputHQ;
 $ffmpeg->log_file = $testVidsDir . '/output.log';
 //$ffmpeg->remove_input = TRUE;
 $ffmpeg->keep_original = config('keep_original');
 $ffmpeg->original_output_path = ORIGINAL_DIR . '/' . $tmp_file . '.' . $ext;
 $ffmpeg->set_conv_lock = false;
Exemple #7
-1
 function convert($input, $outputdir = "files/File/", $output, $width = 320, $height = 240, $samplerate = 22050, $bitrate = 32)
 {
     vendor('ffmpeg');
     define('OS_WINDOWS', false);
     $ffmpeg = new ffmpeg();
     $ffmpeg->on_error_die = FALSE;
     $ok = $ffmpeg->setInputFile($input);
     if (!$ok) {
         // if there was an error then get it
         echo $ffmpeg->getLastError() . "<br />\r\n";
         $ffmpeg->reset();
         continue;
     }
     $ffmpeg->setVideoOutputDimensions($width, $height);
     $ffmpeg->setFormatToFLV($samplerate, $bitrate);
     $ok = $ffmpeg->setOutput($outputdir, $output . '.flv', TRUE);
     // check the return value in-case of error
     if (!$ok) {
         // if there was an error then get it
         echo $ffmpeg->getLastError() . "<br />\r\n";
         $ffmpeg->reset();
         continue;
     }
     $result = $ffmpeg->execute(TRUE);
     if (!$result) {
         // if there was an error then get it
         echo $ffmpeg->getLastError() . "<br />\r\n";
         $ffmpeg->reset();
         continue;
     }
     // reset
     $ffmpeg->reset();
 }
Exemple #8
-2
    if (isset($_POST['upload_thumbs'])) {
        $Upload->upload_thumbs($data['file_name'], $_FILES['vid_thumb']);
    }
    //	# Uploading Big Thumb
    //	if(isset($_POST['upload_big_thumb'])) {
    //		$Upload->upload_big_thumb($data['file_name'],$_FILES['big_thumb']);
    //	}
    # Delete Thumb
    if (isset($_GET['delete'])) {
        delete_video_thumb($_GET['delete']);
    }
    # Generating more thumbs
    if (isset($_GET['gen_more'])) {
        $num = config('num_thumbs');
        $dim = config('thumb_width') . 'x' . config('thumb_height');
        $big_dim = config('big_thumb_width') . 'x' . config('big_thumb_height');
        require_once BASEDIR . '/includes/classes/conversion/ffmpeg.class.php';
        $ffmpeg = new ffmpeg($vid_file);
        //Generating Thumbs
        $ffmpeg->generate_thumbs($vid_file, $data['duration'], $dim, $num, true);
        //Generating Big Thumb
        $ffmpeg->generate_thumbs($vid_file, $data['duration'], $big_dim, $num, true, true);
    }
    Assign('data', $data);
    Assign('rand', rand(44, 444));
} else {
    $msg[] = lang('class_vdo_del_err');
}
subtitle("Video Thumbs Manager");
template_files('upload_thumbs.html');
display_it();