Exemplo n.º 1
2
 /**
  * @param string        $filename
  * @param Output        $output
  * @param callable|null $callback
  *
  * @return Media
  */
 public function save(string $filename, Output $output, callable $callback = null) : Media
 {
     $commandBuilder = new CommandBuilder($this, $output);
     $tmpDir = sys_get_temp_dir() . '/' . sha1(uniqid()) . '/';
     $this->fs->mkdir($tmpDir);
     $passes = $output->getPasses();
     $this->setCallbackProperty($callback, 'totalPasses', $passes);
     for ($i = 0, $l = $passes; $i < $l; ++$i) {
         if (null !== $callback) {
             $this->setCallbackProperty($callback, 'currentPass', $i + 1)->setCallbackProperty($callback, 'currentFrame', 0)->setCallbackProperty($callback, 'totalFrames', $this->getFrameCount($output));
         }
         $this->ffmpeg->run(sprintf('%s %s %s %s "%s" -y', $commandBuilder->computeInputs(), $commandBuilder->computePasses($i, $passes, $tmpDir), $commandBuilder->computeFormatFilters(), $commandBuilder->computeParams(), $filename), get_class($callback) == 'Closure' || null === $callback ? $callback : array($callback, 'callback'));
     }
     $this->fs->remove($tmpDir);
     return $this;
 }
Exemplo n.º 2
0
<?php

/**
*	include FFmpeg class
**/
include DIRNAME(DIRNAME(__FILE__)) . '/src/ffmpeg.class.php';
/**
*	get options from database
**/
$options = array('duration' => 99, 'position' => 0, 'itsoffset' => 2);
/**
*	Create command
*/
$FFmpeg = new FFmpeg('/usr/local/bin/ffmpeg');
$FFmpeg->input('/var/media/original.avi');
$FFmpeg->transpose(0)->vflip()->grayScale()->vcodec('h264')->frameRate('30000/1001');
$FFmpeg->acodec('aac')->audioBitrate('192k');
foreach ($options as $option => $values) {
    $FFmpeg->call($option, $values);
}
$FFmpeg->output('/var/media/new.mp4', 'mp4');
print $FFmpeg->command;
Exemplo n.º 3
0
 function index()
 {
     // TODO: require auth for this controller
     // director-core will need some reworking
     // if (!$this->auth)
     // {
     // 	$this->error('401', 'The action requires an authentication token.');
     // return;
     // }
     list($params, ) = $this->parse_params(func_get_args());
     include FCPATH . 'app' . DIRECTORY_SEPARATOR . 'koken' . DIRECTORY_SEPARATOR . 'ffmpeg.php';
     $ffmpeg = new FFmpeg();
     function max_upload_to_bytes($val)
     {
         $val = strtolower($val);
         if (preg_match('/(k|m|g)/', $val, $match)) {
             $val = (int) str_replace($match[1], '', $val);
             switch ($match[1]) {
                 case 'k':
                     $val *= 1024;
                     break;
                 case 'm':
                     $val *= 1048576;
                     break;
                 case 'g':
                     $val *= 1073741824;
                     break;
             }
             return $val;
         } else {
             return (int) $val;
         }
     }
     $max_upload = max_upload_to_bytes(ini_get('upload_max_filesize'));
     $post_max = max_upload_to_bytes(ini_get('post_max_size'));
     $max = min($max_upload, $post_max);
     if ($max >= 1024) {
         $max_clean = $max / 1024 . 'KB';
     }
     if ($max >= 1048576) {
         $max_clean = $max / 1048576 . 'MB';
     }
     if ($max >= 1073741824) {
         $max_clean = $max / 1073741824 . 'GB';
     }
     $c = new Content();
     $c->select_max('modified_on')->get();
     $a = new Album();
     $a->select_max('modified_on')->get();
     $t = new Text();
     $t->select_max('modified_on')->get();
     $this->load->library('webhostwhois');
     $webhost = new WebhostWhois(array('useDns' => false));
     if (!defined('MAX_PARALLEL_REQUESTS')) {
         // Hosts we know do not limit parallel requests
         $power_hosts = array('dreamhost', 'media-temple-grid', 'go-daddy', 'in-motion', 'rackspace-cloud');
         $parallel = in_array($webhost->key, $power_hosts) ? 8 : 3;
     } else {
         $parallel = MAX_PARALLEL_REQUESTS;
     }
     // TODO: Some of this info should be limited to authenticated sessions
     $data = array('version' => KOKEN_VERSION, 'operating_system' => PHP_OS, 'memory_limit' => ini_get('memory_limit'), 'auto_updates' => AUTO_UPDATE, 'php_version' => PHP_VERSION, 'exif_support' => is_really_callable('exif_read_data'), 'iptc_support' => is_really_callable('iptcparse'), 'ffmpeg_support' => is_really_callable('exec') ? $ffmpeg->version() : false, 'upload_limit' => $max, 'upload_limit_clean' => $max_clean, 'timestamp' => (int) max($c->modified_on, $a->modified_on, $t->modified_on), 'rewrite_enabled' => $this->check_for_rewrite(), 'mysql_version' => $this->db->call_function('get_server_info', $this->db->conn_id), 'max_parallel_requests' => $parallel, 'webhost' => $webhost->key, 'store' => KOKEN_STORE_URL, 'server_software' => isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : 'Unknown');
     $this->set_response_data($data);
 }
Exemplo n.º 4
0
/**
 * Serve a converted web compatible video
 * URL structure: projekktor/<guid>/<format>/
 *
 * @param array $page Page segments array
 */
function elgg_file_viewer_projekktor_video($page)
{
    $enable_ffmpeg = elgg_get_plugin_setting('enable_ffmpeg', 'elgg_file_viewer');
    if ($enable_ffmpeg != 'yes') {
        return false;
    }
    $guid = elgg_extract(0, $page, null);
    $file = get_entity($guid);
    if (!elgg_instanceof($file, 'object', 'file')) {
        return false;
    }
    $info = pathinfo($file->getFilenameOnFilestore());
    $filename = $info['filename'];
    $format = elgg_extract(1, $page);
    $output = new ElggFile();
    $output->owner_guid = $file->owner_guid;
    $output->setFilename("projekktor/{$file->guid}/{$filename}.{$format}");
    if (!$output->size()) {
        try {
            $filestorename = $output->getFilenameOnFilestore();
            $output->open('write');
            $output->close();
            $ffmpeg_path = elgg_get_plugin_setting('ffmpeg_path', 'elgg_file_viewer');
            $FFmpeg = new FFmpeg($ffmpeg_path);
            $FFmpeg->input($file->getFilenameOnFilestore())->output($filestorename)->ready();
            elgg_log("Converting file {$file->guid} to {$format}: {$FFmpeg->command}", 'NOTICE');
        } catch (Exception $e) {
            elgg_log($e->getMessage(), 'ERROR');
        }
    }
    $mime = elgg_file_viewer_get_mime_type($file);
    $base_type = substr($mime, 0, strpos($mime, '/'));
    header("Pragma: public");
    header("Content-type: {$base_type}/{$format}");
    header("Content-Disposition: attachment; filename=\"{$filename}.{$format}\"");
    ob_clean();
    flush();
    readfile($output->getFilenameOnFilestore());
}
Exemplo n.º 5
0
/**
 * Convert a video/audio file to a web compatible format
 * 
 * @param ElggFile $file   File entity
 * @param string   $format Format to convert to (extension)
 * @return ElggFile|false
 */
function elgg_file_viewer_convert_file($file, $format)
{
    if (!$file instanceof ElggFile || !$format) {
        return false;
    }
    $ffmpeg_path = elgg_get_plugin_setting('ffmpeg_path', 'elgg_file_viewer');
    if (!$ffmpeg_path) {
        return false;
    }
    $info = pathinfo($file->getFilenameOnFilestore());
    $filename = $info['filename'];
    $output = new ElggFile();
    $output->owner_guid = $file->owner_guid;
    $output->setFilename("projekktor/{$file->guid}/{$filename}.{$format}");
    $output->open('write');
    $output->close();
    try {
        $FFmpeg = new FFmpeg($ffmpeg_path);
        if (!$file->icontime) {
            $icon = new ElggFile();
            $icon->owner_guid = $file->owner_guid;
            $icon->setFilename("projekktor/{$file->guid}/{$filename}.jpg");
            $FFmpeg->input($file->getFilenameOnFilestore())->thumb(0, 1)->output($icon->getFilenameOnFilestore())->ready();
            if ($icon->exists()) {
                $file->icontime = time();
                $file->ffmpeg_thumb = $icon->getFilename();
                $prefix = 'file/';
                $filestorename = $file->icontime . $filename . '.jpg';
                $thumbnail = get_resized_image_from_existing_file($icon->getFilenameOnFilestore(), 60, 60, true);
                if ($thumbnail) {
                    $thumb = new ElggFile();
                    $thumb->setMimeType($_FILES['upload']['type']);
                    $thumb->setFilename($prefix . "thumb" . $filestorename);
                    $thumb->open("write");
                    $thumb->write($thumbnail);
                    $thumb->close();
                    $file->thumbnail = $prefix . "thumb" . $filestorename;
                    unset($thumbnail);
                }
                $thumbsmall = get_resized_image_from_existing_file($icon->getFilenameOnFilestore(), 153, 153, true);
                if ($thumbsmall) {
                    $thumb->setFilename($prefix . "smallthumb" . $filestorename);
                    $thumb->open("write");
                    $thumb->write($thumbsmall);
                    $thumb->close();
                    $file->smallthumb = $prefix . "smallthumb" . $filestorename;
                    unset($thumbsmall);
                }
                $thumblarge = get_resized_image_from_existing_file($icon->getFilenameOnFilestore(), 600, 600, false);
                if ($thumblarge) {
                    $thumb->setFilename($prefix . "largethumb" . $filestorename);
                    $thumb->open("write");
                    $thumb->write($thumblarge);
                    $thumb->close();
                    $file->largethumb = $prefix . "largethumb" . $filestorename;
                    unset($thumblarge);
                }
            }
        }
        $FFmpeg->input($file->getFilenameOnFilestore())->output($output->getFilenameOnFilestore())->ready();
        elgg_log("Converting file {$file->guid} to {$format}: {$FFmpeg->command}", 'NOTICE');
    } catch (Exception $ex) {
        elgg_log($ex->getMessage(), 'ERROR');
        return false;
    }
    return $output;
}
Exemplo n.º 6
0
<?php

/**
*	include FFmpeg class
**/
include DIRNAME(DIRNAME(__FILE__)) . '/src/FFmpeg.php';
$start = 1;
$frames = 10;
$size = '100x100';
$file = '/var/www/file.mp4';
$FFmpeg = new FFmpeg();
$FFmpeg->input($file)->thumb($size, $start, $frames)->ready();
Exemplo n.º 7
0
    $cores = `cat /proc/cpuinfo | grep 'cpu cores'`;
    $threads = trim(end(explode(":", $cores))) - 1;
    return (int) $threads === 0 ? 1 : $threads;
}
$threads = getThreads();
while (true) {
    foreach ($inputdirarray as $inputdir) {
        $re = "/(\\.mov\$)|(\\.mpg\$)|(\\.mpeg\$)|(\\.mkv\$)|(\\.mp4\$)|(\\.avi\$)|(\\.wmv\$)|(\\.ts\$)|(\\.flv\$)|(\\.mjpg\$)/i";
        $outputdir = Conf::CONVERTDIR . "/" . $inputdir;
        foreach (glob(Conf::UPLOADDIR . "/" . $inputdir . "/*.*") as $filename) {
            if (preg_match($re, $filename)) {
                $inputfile = "{$filename} size " . filesize($filename);
                $outfilename = $outputdir . "/" . pathinfo($filename, PATHINFO_FILENAME) . ".mp4";
                FFmpeg::$source = $filename;
                FFmpeg::$dest = $outfilename;
                $cmd = FFmpeg::init();
                sleep(1);
                Logger::getLogger(Conf::CONVERTLOGFILE)->log("Using threads = " . $threads . "\n" . "video file found in " . $dirs[0] . "/" . $inputdir . "\n" . "cmd=" . $cmd);
                $exit_code = 3;
                $ffmpeg_error = 0;
                echo exec($cmd, $ffmpeg_error, $ffmpeg_exit_code);
                if ($ffmpeg_exit_code === 0) {
                    $exit_code = $exit_code - 1;
                    if (in_array(pathinfo($filename, PATHINFO_FILENAME), Conf::ADDS)) {
                        $out = Conf::BASEDIR . "/" . $inputdir . "/adds/" . pathinfo($filename, PATHINFO_FILENAME) . ".mp4";
                    } else {
                        $out = Conf::BASEDIR . "/" . $inputdir . "/" . pathinfo($filename, PATHINFO_FILENAME) . ".mp4";
                    }
                    $in = "" . $outputdir . "/" . pathinfo($filename, PATHINFO_FILENAME) . ".mp4";
                    if (copy($in, $out)) {
                        unlink($in);
Exemplo n.º 8
0
 function _before()
 {
     if (!preg_match('~^https?://~', $this->filename)) {
         $this->file_type = (int) $this->set_type();
         $path = $this->path_to_original();
         $pathinfo = pathinfo($path);
         if ($this->file_type > 0) {
             include_once FCPATH . 'app' . DIRECTORY_SEPARATOR . 'koken' . DIRECTORY_SEPARATOR . 'ffmpeg.php';
             $ffmpeg = new FFmpeg($path);
             if ($ffmpeg->version()) {
                 $this->duration = $ffmpeg->duration();
                 list($this->width, $this->height) = $ffmpeg->dimensions();
                 $this->lg_preview = $ffmpeg->create_thumbs();
             }
         } else {
             list($this->width, $this->height) = getimagesize($path);
             @unlink($path . '.icc');
             $iptc = $this->_get_iptc_data($path);
             $this->has_iptc = !empty($iptc);
             $exif = $this->_get_exif_data($path);
             $this->has_exif = !empty($exif);
             if (isset($iptc['2#005'])) {
                 if (is_array($iptc['2#005'])) {
                     $iptc['2#005'] = $iptc['2#005'][0];
                 }
                 $this->title = $this->_force_utf($iptc['2#005']);
             }
             if (isset($iptc['2#120'])) {
                 if (is_array($iptc['2#120'])) {
                     $iptc['2#120'] = $iptc['2#120'][0];
                 }
                 $this->caption = $this->_force_utf($iptc['2#120']);
             }
             if (isset($iptc['2#025']) && is_array($iptc['2#025'])) {
                 $words = array();
                 if (count($iptc['2#025']) == 1) {
                     $words = array($iptc['2#025'][0]);
                 } else {
                     $words = $iptc['2#025'];
                 }
                 $_POST['tags'] = rtrim($_POST['tags'], ',') . ',' . join(',', $words);
             }
             $captured_on = $this->parse_captured($iptc, $exif);
             if (!is_null($captured_on) && $captured_on > 0) {
                 $this->captured_on = $captured_on;
             }
             $longest = max($this->width, $this->height);
             $midsize = preg_replace('/\\.' . $pathinfo['extension'] . '$/', '.1600.' . $pathinfo['extension'], $path);
             if (file_exists($midsize)) {
                 unlink($midsize);
             }
             if ($longest > 1600) {
                 include_once FCPATH . 'app' . DIRECTORY_SEPARATOR . 'koken' . DIRECTORY_SEPARATOR . 'DarkroomUtils.php';
                 $s = new Setting();
                 $s->where('name', 'image_processing_library')->get();
                 $d = DarkroomUtils::init($s->value);
                 $d->read($path, $this->width, $this->height)->resize(1600)->quality(100)->render($midsize);
                 $external = Shutter::store_original($midsize, $this->path . '/' . basename($midsize));
                 if ($external) {
                     $this->storage_url_midsize = $external;
                     unlink($midsize);
                 }
             }
         }
         $this->filesize = filesize($path);
     }
     if (is_numeric($this->width)) {
         $this->aspect_ratio = $this->width / $this->height;
     }
 }
Exemplo n.º 9
0
<?php

include "init.php";
file_put_contents("job-pid.lock", getmypid());
$pids = array();
while (true) {
    $newJob = new Video();
    $obj = $newJob->get_list(array("isConverted" => 0));
    if (count($obj) > 0) {
        file_put_contents("job.lock", "working");
    } else {
        sleep(1);
        continue;
    }
    foreach ($obj as $video) {
        $ffmpeg = new FFmpeg(Config::get('basedir') . "/public/upload/" . $video->filename);
        $ffmpeg->convertVideo("webm");
        $ffmpeg->convertVideo("mp4");
        if (!is_dir(Config::get('basedir') . "/public/video/" . $video->user_id)) {
            mkdir(Config::get('basedir') . "/public/video/" . $video->user_id);
        }
        if (!is_dir(Config::get('basedir') . "/public/video/" . $video->user_id . "/" . $video->id)) {
            mkdir(Config::get('basedir') . "/public/video/" . $video->user_id . "/" . $video->id);
        }
        rename(Config::get('basedir') . "/public/upload/" . $video->filename . ".mp4", Config::get('basedir') . "/public/video/" . $video->user_id . "/" . $video->id . "/" . $video->id . ".mp4");
        rename(Config::get('basedir') . "/public/upload/" . $video->filename . ".webm", Config::get('basedir') . "/public/video/" . $video->user_id . "/" . $video->id . "/" . $video->id . ".webm");
        rename(Config::get('basedir') . "/public/upload/" . $video->filename, Config::get('basedir') . "/public/video/" . $video->user_id . "/" . $video->id . "/" . $video->id . ".basefile");
        rename(Config::get('basedir') . "/public/upload/" . $video->filename . "_thumbs1/00000001.png", Config::get('basedir') . "/public/video/" . $video->user_id . "/" . $video->id . "/thumb1.png");
        rename(Config::get('basedir') . "/public/upload/" . $video->filename . "_thumbs2/00000001.png", Config::get('basedir') . "/public/video/" . $video->user_id . "/" . $video->id . "/thumb2.png");
        rename(Config::get('basedir') . "/public/upload/" . $video->filename . "_thumbs3/00000001.png", Config::get('basedir') . "/public/video/" . $video->user_id . "/" . $video->id . "/thumb3.png");
        rmdir(Config::get('basedir') . "/public/upload/" . $video->filename . "_thumbs1");
Exemplo n.º 10
-1
 function uploadFile()
 {
     if (isset($_FILES) && isset($_POST) && !empty($_FILES)) {
         // we need a better mime type checks i guess
         // $allowedFileExtension = array("avi", "mov", "mpeg", "flv");
         $tmpVideoName = md5(microtime());
         move_uploaded_file($_FILES['file_upload']['tmp_name'], Config::get('basedir') . "/public/upload/" . $tmpVideoName);
         $ffmpeg = new FFmpeg(Config::get('basedir') . "/public/upload/" . $tmpVideoName);
         $ffmpeg->getFileInformation();
         $ffmpeg->createThumbnail();
         $this->json = array("tmpFile" => $tmpVideoName);
     }
 }