Example #1
4
 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');
 }
Example #2
1
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');
}
Example #3
0
<?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');
Example #4
0
<?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);
}
Example #6
0
 /**
  * Converts a video into .webm and .mp4 formats for HTML5 video
  * 
  * @return void
  */
 public function webvideo()
 {
     try {
         set_time_limit(0);
         ini_set('memory_limit', '256M');
     } catch (\Exception $e) {
         // Nothing!
     }
     // Get params:
     $video_path = \Cli::option('file', null);
     if ($video_path === null) {
         return;
     }
     // We need the log package loaded for Monolog
     $doc_root = realpath(APPPATH . '../../public') . '/';
     $config = \Config::get('cmf.ffmpeg');
     $logger = new \Monolog\Logger('WebVideoConverter');
     $logger->pushHandler(new \Monolog\Handler\RotatingFileHandler(APPPATH . 'logs/ffmpeg.log'));
     // Get path info about the video
     $video_path = $doc_root . $video_path;
     $video_id = md5($video_path);
     $path_info = pathinfo($video_path);
     $converted_dir = $path_info['dirname'] . '/converted';
     $progress_file = $video_path . '.progress';
     touch($progress_file);
     if (!is_dir($converted_dir)) {
         $made_dir = @mkdir($converted_dir, 0775, true);
     }
     // Set up the FFMpeg instances
     $ffprobe = new \FFMpeg\FFProbe($config['ffprobe_binary'], $logger);
     $ffmpeg = new \FFMpeg\FFMpeg($config['ffmpeg_binary'], $logger);
     $ffmpeg->setProber($ffprobe);
     // Probe the video for info
     $format_info = json_decode($ffprobe->probeFormat($video_path));
     $video_streams = json_decode($ffprobe->probeStreams($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) {
         return;
     }
     // Determine the frame rate
     if (isset($video_info->r_frame_rate)) {
         $video_framerate = strval($video_info->r_frame_rate);
         $parts = explode('/', $video_framerate);
         $video_framerate = round(intval($parts[0]) / intval($parts[1]));
     } else {
         $video_framerate = intval($config['default_framerate']);
     }
     // Get the size
     $video_width = intval(isset($video_info->width) ? $video_info->width : $config['default_size']['width']);
     $video_height = intval(isset($video_info->height) ? $video_info->height : $config['default_size']['height']);
     $video_kilobitrate = round($video_width * $video_height * 0.0019);
     $video_duration = floatval($format_info->duration);
     $still_frame_pos = $video_duration * 0.1;
     if (isset($format_info->bit_rate) && round($format_info->bit_rate / 1024) < $video_kilobitrate) {
         $video_kilobitrate = round($format_info->bit_rate / 1024);
     }
     // Set up the helper that outputs conversion progress
     $progressHelper = new \FFMpeg\Helper\VideoProgressHelper(function ($percent, $remaining, $rate) use($progress_file) {
         $data = array('percent' => $percent, 'remaining' => $remaining, 'rate' => $rate);
         file_put_contents($progress_file, json_encode($data));
     });
     // Finally, convert to each format:
     $webMFormat = new \FFMpeg\Format\Video\WebM();
     $webMFormat->setDimensions($video_width, $video_height)->setFrameRate($video_framerate)->setKiloBitrate($video_kilobitrate)->setGopSize(25);
     $x264Format = new \FFMpeg\Format\Video\X264();
     $x264Format->setDimensions($video_width, $video_height)->setFrameRate($video_framerate)->setKiloBitrate($video_kilobitrate)->setGopSize(25);
     $ffmpeg->open($video_path)->attachHelper($progressHelper)->encode($webMFormat, $converted_dir . '/' . $path_info['filename'] . '.webm')->encode($x264Format, $converted_dir . '/' . $path_info['filename'] . '.mp4')->extractImage($still_frame_pos, $path_info['dirname'] . '/' . $path_info['basename'] . '.jpg')->close();
     // Delete the progress file to show that the process is complete
     unlink($progress_file);
 }
 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);
 }