public function convertAudioFile($input) { $ffmpeg = FFMpeg\FFMpeg::create(); $audio = $ffmpeg->open($input); $format = new FFMpeg\Format\Audio\Wav(); $format->on('progress', function ($audio, $format, $percentage) { echo "{$percentage} % transcoded"; }); $format->setAudioChannels(2); $audio->filters()->resample(96000); $audio->save($format, 'output/Output_file.wav'); }
function convertAudioFile($input) { $file_path = dirname(__FILE__) . "/audio_files/" . $input; $ffmpeg = FFMpeg\FFMpeg::create(); $audio = $ffmpeg->open($file_path); $format = new FFMpeg\Format\Audio\Wav(); $format->on('progress', function ($audio, $format, $percentage) { echo "{$percentage} % transcoded"; }); $format->setAudioChannels(2); $audio->filters()->resample(96000); $audio->save($format, 'Output_file2.wav'); }
<?php require_once 'GlobalMas.php'; require Import::$uber_src_path . '/server/composer/vendor/autoload.php'; //exec("ffmpeg -i video.mov output.avi 2>&1", $output); //krumo($output); //$ffmpeg = \FFMpeg\FFMpeg::create(array( //'ffmpeg.binaries' => exec('/usr/local/bin/ffmpeg_b/ffmpeg'), //'ffprobe.binaries' => exec('/usr/local/bin/ffmpeg_b/ffprobe') //)); $ffmpeg = FFMpeg\FFMpeg::create(); $video = $ffmpeg->open('video.mov'); $video->filters()->resize(new FFMpeg\Coordinate\Dimension(320, 240))->synchronize(); $video->frame(FFMpeg\Coordinate\TimeCode::fromSeconds(10))->save('frame.jpg'); $video->save(new FFMpeg\Format\Video\X264(), 'export-x264.mp4')->save(new FFMpeg\Format\Video\WMV(), 'export-wmv.wmv')->save(new FFMpeg\Format\Video\WebM(), 'export-webm.webm');
<?php #namespace FlotCMS; #require __DIR__.'/bootstrap/autoload.php'; require __DIR__ . '../vendor/autoload.php'; $ffmpeg = FFMpeg\FFMpeg::create(array('ffmpeg.binaries' => 'C:/ffmpeg/bin/ffmpeg.exe', 'ffprobe.binaries' => 'C:/ffmpeg/bin/ffprobe.exe', 'timeout' => 0)); $video = $ffmpeg->open('test-files/DSCN0003.AVI'); $video->filters()->rotate(FFMpeg\Filters\Video\RotateFilter::ROTATE_270); $format = new FFMpeg\Format\Video\X264(); $format->setAudioCodec("aac"); $video->save($format, 'test-files/video.avi');
/** * 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); }