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; } }
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; }
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); }
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); }