function ffmpeg_compute_video_duration($fileName)
 {
     $ffprobe = FFMpeg\FFProbe::create();
     return $ffprobe->streams($fileName)->videos()->first()->get('duration');
 }
 public function process($LogFile = false, $runAfterProcess = true)
 {
     if (!$LogFile) {
         $LogFile = TEMP_FOLDER . '/AudioFileProcessing-ID-' . $this->ID . '-' . md5($this->getRelativePath()) . '.log';
     }
     if ($this->ProcessingStatus == 'new') {
         $this->ProcessingStatus = 'processing';
         $this->write();
         $Message = "[LOGTIME: " . date("Y-m-d H:i:s") . "]\nProcessing for File " . $this->getRelativePath() . " started\n\n";
         // Write the contents to the logfile,
         // using the FILE_APPEND flag to append the content to the end of the file
         // and the LOCK_EX flag to prevent anyone else writing to the file at the same time
         file_put_contents($LogFile, $Message, FILE_APPEND | LOCK_EX);
         // Audio Object
         $ffprobe = FFMpeg\FFProbe::create();
         $audio = $ffprobe->format($this->getFullPath());
         // read data
         $return = $this->processAudioInformation($audio, $LogFile);
         if ($return && $runAfterProcess && ($this->ProcessingStatus = 'finished')) {
             $this->onAfterProcess();
         }
         return $return;
     } else {
         $Message = "[LOGTIME: " . date("Y-m-d H:i:s") . "]\nFile allready processed\n";
         file_put_contents($LogFile, $Message, FILE_APPEND | LOCK_EX);
         return false;
     }
 }
예제 #3
0
 public function probeAudioFile($input)
 {
     print_r($input);
     $ffprobe = FFMpeg\FFProbe::create();
     $output = array();
     $format = $ffprobe->format($input)->get('format_name');
     $channels = $ffprobe->streams($input)->audios()->first()->get('channels');
     $bits = $ffprobe->streams($input)->audios()->first()->get('bits_per_sample');
     $sample_rate = $ffprobe->streams($input)->audios()->first()->get('sample_rate');
     array_push($output, $format, $channels, $bits, $sample_rate);
     return $output;
 }
예제 #4
0
function probeAudioFile($input)
{
    $file_path = dirname(__FILE__) . "/audio_files/" . $input;
    // print_r($file_path);
    $ffprobe = FFMpeg\FFProbe::create();
    $output = array();
    $format = $ffprobe->format($file_path)->get('format_name');
    $channels = $ffprobe->streams($file_path)->audios()->first()->get('channels');
    $bits = $ffprobe->streams($file_path)->audios()->first()->get('bits_per_sample');
    $sample_rate = $ffprobe->streams($file_path)->audios()->first()->get('sample_rate');
    array_push($output, $format, $channels, $bits, $sample_rate);
    return $output;
}
 public function process($LogFile = false, $runAfterProcess = true)
 {
     if (!$LogFile) {
         $LogFile = $this->getLogFile();
     }
     if ($this->ProcessingStatus == 'new') {
         $this->ProcessingStatus = 'processing';
         $this->write();
         $this->appendLog($LogFile, "Processing for File " . $this->getRelativePath() . " started");
         try {
             // Movie Object
             $ffprobe = FFMpeg\FFProbe::create();
             $mov = $ffprobe->format($this->getFullPath());
             //$ffmpeg = FFMpeg\FFMpeg::create();
             //$video = $ffmpeg->open($this->getFullPath());
             //$video->frame(FFMpeg\Coordinate\TimeCode::fromSeconds(10))->save($this->getFullPath().'.jpg');
         } catch (Exception $ex) {
             $Message = "ERROR ON - FFProbe:";
             $this->appendLog($LogFile, $Message, $e->getMessage());
             $this->ProcessingStatus = 'error';
             $this->write();
             return false;
         }
         // read data
         if ($this->processVideoInformation($mov, $LogFile)) {
             // private Information returned no error
             $result = $this->extractTimelineImages($mov, $LogFile);
             if ($result && $runAfterProcess && $this->ProcessingStatus == 'finished') {
                 $this->onAfterProcess();
             }
             return $result;
         } else {
             return false;
         }
     } else {
         $this->appendLog($LogFile, "File allready processed");
         return false;
     }
 }
/**
 * Decomposition method for {@link segmentVideo}; 
 * <strong>Will EXIT on error!</strong>
 * @return an array with $ffmpeg at index 0 and $ffprobe at index 1
 */
function segmentVideo_getFfProbeAndFfMpeg($queueID)
{
    $ffprobe = null;
    $ffmpeg = null;
    try {
        $ffmpegBinariesPath = get(CONFIG_FFMPEG_PATH);
        $ffprobeBinariesPath = get(CONFIG_FFPROBE_PATH);
        $createArray = array();
        if ($ffmpegBinariesPath != null && strlen($ffmpegBinariesPath) > 0) {
            $createArray["ffmpeg.binaries"] = $ffmpegBinariesPath;
        }
        if ($ffprobeBinariesPath != null && strlen($ffprobeBinariesPath) > 0) {
            $createArray["ffprobe.binaries"] = $ffprobeBinariesPath;
        }
        $ffmpeg = FFMpeg\FFMpeg::create($createArray);
        $ffprobe = FFMpeg\FFProbe::create($createArray);
    } catch (Exception $e) {
        $conn->query("UPDATE queue SET status=\"" . STATUS_SEGMENTING_ERROR . "\" WHERE id={$queueID}");
        $conn->close();
        error_log("Error initializing ffmpeg and/or ffprobe.");
        exit("Error creating ffmpeg and/or ffprobe.");
    }
    return array($ffprobe, $ffmpeg);
}
예제 #7
0
 /**
  * A special endpoint for video uploads. This starts the process of conversion into web formats
  */
 function action_video()
 {
     try {
         set_time_limit(0);
         ini_set('memory_limit', '256M');
     } catch (\Exception $e) {
         // Nothing!
     }
     \Package::load(array('log'));
     // Get the size limit as defined by PHP
     $this->sizeLimit = min($this->toBytes(ini_get('upload_max_filesize')), $this->toBytes(ini_get('post_max_size')));
     // If you want to use resume feature for uploader, specify the folder to save parts.
     $this->chunksFolder = APPPATH . 'tmp/chunks';
     // Call handleUpload() with the name of the folder
     $path = \Input::get('path', urldecode(\Input::post('path', 'uploads')));
     $path = trim($path, '/') . '/';
     $result = $this->handleUpload(DOCROOT . $path);
     // We may have been passed details about the owner of this video field
     $model_class = \Input::get('model', urldecode(\Input::post('model', null)));
     $item_id = \Input::get('item_id', urldecode(\Input::post('item_id', null)));
     $field_name = \Input::get('fieldName', urldecode(\Input::post('fieldName', null)));
     // Set the data for the response
     $result['uploadName'] = $this->getUploadName();
     $result['originalName'] = $this->getOriginalName();
     $result['path'] = $path . $result['uploadName'];
     $result['fieldName'] = $field_name;
     // We need to work out where the PID file for this conversion will sit...
     $video_path = $result['path'];
     $video_pid = 'videoconvert_' . md5(DOCROOT . $video_path);
     $result['pid'] = $video_pid;
     $pid_dir = APPPATH . 'run';
     if (!is_dir($pid_dir)) {
         $dir_result = @mkdir($pid_dir, 0775, true);
     }
     // Get the dimensions. These are important...
     $config = \Config::get('cmf.ffmpeg');
     $logger = new Logger('WebVideoConverter');
     $logger->pushHandler(new NullHandler());
     $full_video_path = DOCROOT . $video_path;
     // Set up the FFMpeg instances
     $ffprobe = new \FFMpeg\FFProbe($config['ffprobe_binary'], $logger);
     // Probe the video for info
     $format_info = json_decode($ffprobe->probeFormat($full_video_path));
     $video_streams = json_decode($ffprobe->probeStreams($full_video_path));
     $video_info = null;
     foreach ($video_streams as $num => $stream) {
         if ($stream->codec_type == 'video') {
             $video_info = $stream;
             break;
         }
     }
     // Serve up an error if we can't find a video stream
     if ($video_info === null) {
         $this->headers = array("Content-Type: text/plain");
         return \Response::forge(json_encode(array('error' => 'This is not a supported video type')), $this->status, $this->headers);
     }
     // Now add some useful video stats to the result
     $result['width'] = intval(isset($video_info->width) ? $video_info->width : $config['default_size']['width']);
     $result['height'] = intval(isset($video_info->height) ? $video_info->height : $config['default_size']['height']);
     $result['duration'] = $format_info->duration;
     // Execute the oil conversion process as a separate 'thread'
     $oil_path = realpath(APPPATH . '../../oil');
     exec("php {$oil_path} r ffmpeg:webvideo -file='{$video_path}' > /dev/null 2>&1 & echo \$! >> /dev/null");
     $this->headers = array("Content-Type: text/plain");
     return \Response::forge(json_encode($result), $this->status, $this->headers);
 }
 public function store()
 {
     $execStart = microtime(true);
     if (!Input::has('url')) {
         // return error: no URL
         return Response::json(array('message' => Lang::get('videoConverter::message.error.noUrl')), 500);
     }
     $validator = Validator::make(Input::all(), Config::get('videoConverter::VideoSettings.rules'));
     if ($validator->fails()) {
         // return error: invalid URL
         return Response::json(array('message' => Lang::get('videoConverter::message.error.invalidUrl')), 500);
     }
     $fileInfo = pathinfo(Input::get('url'));
     if (sizeof($fileInfo) == 0) {
         // return error: parsing URL
         return Response::json(array('message' => Lang::get('videoConverter::message.error.parsingUrl')), 500);
     }
     // If the video exist we rename the filename
     if (file_exists(Config::get('videoConverter::VideoSettings.videoPath') . $fileInfo['filename'] . '.' . Config::get('videoConverter::VideoSettings.convertTo'))) {
         $filename = str_random(5) . '-' . $fileInfo['filename'];
     } else {
         $filename = $fileInfo['filename'];
     }
     $ffmpeg = FFMpeg\FFMpeg::create(array('ffmpeg.binaries' => Config::get('videoConverter::VideoSettings.ffmpegPath'), 'ffprobe.binaries' => Config::get('videoConverter::VideoSettings.ffprobePath'), 'timeout' => 0));
     // example: https://archive.org/download/Tg.flv_865/Tg.flv
     // https://archive.org/download/11Wmv/Produce_1.wmv
     // try : https://archive.org/download/avi/avicompleet.mov
     // https://archive.org/download/22avi/22Avi.avi
     $video = $ffmpeg->open(Input::get('url'));
     $videoStream = FFMpeg\FFProbe::create();
     /*$videoStream
     		->streams(Input::get('url'))
     		->videos() 
     		->first();*/
     $duration = $videoStream->format(Input::get('url'))->get('duration');
     $nbThumbs = Config::get('videoConverter::VideoSettings.nbThumbnails');
     $frameTime = 0;
     $timeByThumb = floor($duration) / $nbThumbs;
     for ($i = 0; $i < $nbThumbs; $i++) {
         if ($i == 0) {
             // 5 seconds in more for the first frame
             $frameTime = 5;
         } else {
             if ($i == $nbThumbs - 1) {
                 // 10 seconds in less for the last frame
                 $frameTime = $frameTime + $timeByThumb - 10;
             } else {
                 $frameTime = $frameTime + $timeByThumb;
             }
         }
         $frameNumber = $i + 1;
         // Generate frame
         $video->frame(FFMpeg\Coordinate\TimeCode::fromSeconds($frameTime))->save(Config::get('videoConverter::VideoSettings.thumbnailPath') . $filename . '_' . $frameNumber . '.' . Config::get('videoConverter::VideoSettings.thumbnailType'));
     }
     // Generate video
     $video->save(new FFMpeg\Format\Video\X264(), Config::get('videoConverter::VideoSettings.videoPath') . $filename . '.' . Config::get('videoConverter::VideoSettings.convertTo'));
     $execEnd = microtime(true);
     // Time in minutes
     $timeExec = round(($execEnd - $execStart) / 60);
     return Response::json(array('success' => true, 'data' => Input::get('url'), 'fileName' => $filename, 'duration' => $duration, 'nbThumbs' => $nbThumbs, 'time' => $timeExec), 200);
 }