/**
 * !runscript subroutine!
 * <br>
 * Creates images from the frames of a video; one image is taken every .2 seconds.
 * @param $mediaID the video's ID
 * @param $queueID the ID of the item in the queue
 * @param $videoFilePath path to the video file (has only been tested on .mp4)
 * @param $segmentedVideoPath path for a folder that will contain some of the video's frames that are extracted in this method
 */
function segmentVideo($mediaID, $queueID, $videoFilePath, $segmentedVideoPath)
{
    $conn = getDBConnection();
    if (!file_exists($videoFilePath)) {
        $conn->query("UPDATE queue SET status=\"" . STATUS_DOWNLOAD_ERROR . "\" WHERE id={$queueID}");
        exit("Datei wurde nicht gefunden.");
    }
    segementVideo_setupFolder($segmentedVideoPath);
    $conn->query("UPDATE queue SET status=\"" . STATUS_SEGMENTING_VIDEO . "\" WHERE id={$queueID}");
    $ffProbeAndFfMpeg = segmentVideo_getFfProbeAndFfMpeg($queueID);
    if (!is_array($ffProbeAndFfMpeg)) {
        exit("Error creating ffmpeg and/or ffprobe.");
    }
    $ffprobe = $ffProbeAndFfMpeg[0];
    $ffmpeg = $ffProbeAndFfMpeg[1];
    $videoDuration = null;
    try {
        $videoDuration = $ffprobe->format($videoFilePath)->get('duration');
        // returns the duration property
    } 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.");
    }
    $video = $ffmpeg->open($videoFilePath);
    // 0.2: analyze 5 FPS
    for ($i = 0, $counter = 0; $i < $videoDuration; $i += 0.2, $counter++) {
        $video->frame(FFMpeg\Coordinate\TimeCode::fromSeconds($i))->save($segmentedVideoPath . "/frame_{$counter}.jpg");
    }
    $conn->query("UPDATE queue SET status=\"" . STATUS_FINISHED_SEGMENTING_VIDEO . "\" WHERE id={$queueID}");
    $conn->close();
    unlink($_GET["video_file_path"]);
}
Example #2
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');
 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);
 }