/**
  * Enter description here...
  *
  * @param unknown_type $original_file
  * @param unknown_type $new_file
  * @param unknown_type $c  : config oblject
  * @return unknown
  */
 public function movieToMp4H264($path_original, $path_new, $c)
 {
     ini_set("max_execution_time", 300000);
     $ffmpegpath = $c->ffmpeg_path;
     // Define standard video ratios, as used within the television and motion picture industries
     // To be consistent, round everything to 2-decimal places so all numbers are in the same format
     $broadcastTV = round(4 / 3, 2);
     // the aspect ratio is 4:3, which is 640/480; rounded to two decimals, this is 1.33
     $widescreeenTV = round(16 / 9, 2);
     //the aspect ratio is 16:9, which is 640/360; rounded to two decimals, this is 1.78
     $cinemaScope = 2.35;
     //the aspect ratio is 2.35:1, which is roughly 640/272 rounded to two decimal places
     // Let's set our absolute dimensions, as dicated by IPod and other external media players
     $maxWidth = 640;
     // per IPod specs (and other similar players), 640 is maximum width, period
     $wideMaxHeight = 360;
     //this number keeps the proper Widescreen aspect ratio when coupled with IPod's absolute maximum width of 640
     $cinemaMaxHeight = 272;
     // this is the proper number for proper CinemaScope ratio coupled with IPod's absolute maximum width of 640
     $standardMaxHeight = 480;
     // this is the standard height for broadcast ratio, and the largest video height Ipod can handle.
     $movie = new ffmpeg_movie($path_original);
     $fcodec = $movie->getVideoCodec();
     // Now, check to see the size of the original video to make sure we're not enlarging something smaller than the max dimensions...
     $vidWith = $movie->getFrameWidth();
     $vidHeight = $movie->getFrameHeight();
     // Set up the encode variables that will actually be passed to the encoder.
     // Remember, our absolute maximum width is 640, no matter what the aspect ratio is
     if ($vidWidth >= $maxWidth) {
         $encodeWidth = $maxWidth;
     } else {
         $encodeWidth = $vidWidth;
     }
     //						if ($encodeWidth == '')
     //							$encodeWidth = $maxWidth;
     // Because video height is what determines the ratio, we have to compare actual video height to each of the three standard types
     // First, get the aspect ratio for the current movie - remember to round it so it's in two-decimal format like the other values
     $vidRatio = round($vidWidth / $vidHeight, 2);
     // Check to see if the video has a Widescreen or Cinematic ratio. If the video for some reason is neither Widescreen nor Cinematic,
     // then let's just use Standard ratio.
     $encodeHeight = $vidHeight;
     // Unless of course we have to adjust the height; see code below
     switch ($vidRatio) {
         case $vidRatio == $widescreenTV:
             if ($encodeHeight >= $wideMaxHeight) {
                 $encodeHeight = $wideMaxHeight;
             }
             break;
         case $vidRatio == $cinemaScope:
             if ($encodeHeight >= $cinemaMaxHeight) {
                 $encodeHeight = $cinemaMaxHeight;
             }
             break;
         default:
             // This is Broadcast TV, which is standard 640x480 ratio
             if ($encodeHeight >= $standardMaxHeight) {
                 $encodeHeight = $standardMaxHeight;
             }
     }
     // Now, we can build the correct WxH (width x Height) ratio variable and pass this to the encode instructions.
     $encodeRatio = $encodeWidth . "x" . $encodeHeight;
     //echo $encodeRatio; exit();
     if ($c->h264_quality == 'highest') {
         $cmd_mencoder = "{$ffmpegpath} -y -chromaoffset 0 -i {$path_original} -acodec libfaac -ab 150k -pass 2 -s 640x352 -vcodec libx264 -b 1.5M -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -me umh -subq 5 -trellis 1 -refs 1 -coder 0 -me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 1.5M -maxrate 1.5M -bufsize 10M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 16:9 {$path_new}";
         //$cmd_mencoder = "$ffmpegpath -y -chromaoffset 0 -i $path_original -an -pass 2 -s 640x480 -vcodec libx264 -b 1.5M -flags +loop -cmp +chroma -partitions 0 -me epzs -subq 1 -trellis 0 -refs 1 -coder 0 -me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 1.5M -maxrate 1.5M -bufsize 10M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 1:1 $path_new";
         //$cmd_mencoder = "$ffmpegpath -y -chromaoffset 0 -i $path_original -an -pass 1 -s ".$encodeRatio." -vcodec libx264 -b 1.5M -flags +loop -cmp +chroma -partitions 0 -me epzs -subq 1 -trellis 0 -refs 1 -coder 0 -me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 1.5M -maxrate 1.5M -bufsize 10M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 1:1 $path_new";
         //$cmd_mencoder2 = "$ffmpegpath -y -chromaoffset 0 -i $path_original -acodec libfaac -ab 128k -pass 2 -s ".$encodeRatio." -vcodec libx264 -b 1.5M -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -me umh -subq 5 -trellis 1 -refs 1 -coder 0 -me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 1.5M -maxrate 1.5M -bufsize 10M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 16:9 $path_new";
         //$cmd_mencoder3 = "/usr/local/bin/AtomicParsley $path_new --DeepScan --iPod-uuid 1200 --overWrite";
     }
     if ($mp4_quality == 'default') {
         $cmd_mencoder = "{$ffmpegpath} -y -chromaoffset 0 -i {$path_original} -acodec libfaac -ab 128k -pass 2 -s 640x352 -vcodec libx264 -b 786K -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -me umh -subq 5 -trellis 1 -refs 1 -coder 0 -me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 786K -maxrate 1.5M -bufsize 10M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 16:9 {$path_new}";
         //$cmd_mencoder = "$ffmpegpath -y -chromaoffset 0 -i $path_original -an -pass 2 -s 640x480 -vcodec libx264 -b 786K -flags +loop -cmp +chroma -partitions 0 -me epzs -subq 1 -trellis 0 -refs 1 -coder 0 -me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 786K -maxrate 1.5M -bufsize 10M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 1:1 $path_new";
         //$cmd_mencoder ="$ffmpegpath -y -chromaoffset 0 -i $path_original -an -pass 1 -s ".$encodeRatio." -vcodec libx264 -b 768K -flags +loop -cmp +chroma -partitions 0 -me epzs -subq 1 -trellis 0 -refs 1 -coder 0 -me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 768K -maxrate 1.5M -bufsize 10M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 1:1 $path_new";
         //$cmd_mencoder2 ="$ffmpegpath -y -chromaoffset 0 -i $path_original -acodec libfaac -ab 128k -pass 2 -s ".$encodeRatio." -vcodec libx264 -b 768K -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -me umh -subq 5 -trellis 1 -refs 1 -coder 0 -me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 768K -maxrate 1.5M -bufsize 10M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 16:9 $path_new";
         //$cmd_mencoder3 ="/usr/local/bin/AtomicParsley $path_new --DeepScan --iPod-uuid 1200 --overWrite";
     }
     if ($mp4_quality == 'lowest') {
         $cmd_mencoder = "{$ffmpegpath} -y -chromaoffset 0 -i {$path_original} -acodec libfaac -ab 128k -pass 1 -s 640x352 -vcodec libx264 -b 786K -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -me umh -subq 5 -trellis 1 -refs 1 -coder 0 -me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 786K -maxrate 1.5M -bufsize 10M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 16:9 {$path_new}";
         //$cmd_mencoder = "$ffmpegpath -y -chromaoffset 0 -i $path_original -an -pass 1 -s 640x480 -vcodec libx264 -b 786K -flags +loop -cmp +chroma -partitions 0 -me epzs -subq 1 -trellis 0 -refs 1 -coder 0 -me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 786K -maxrate 1.5M -bufsize 10M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 1:1 $path_new";
         //$cmd_mencoder ="$ffmpegpath -y -chromaoffset 0 -i $path_original -an -pass 1 -s ".$encodeRatio." -vcodec libx264 -b 768K -flags +loop -cmp +chroma -partitions 0 -me epzs -subq 1 -trellis 0 -refs 1 -coder 0 -me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 768K -maxrate 1.5M -bufsize 10M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 1:1 $path_new";
         //$cmd_mencoder2 ="$ffmpegpath -y -chromaoffset 0 -i $path_original -acodec libfaac -ab 128k -pass 2 -s ".$encodeRatio." -vcodec libx264 -b 768K -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -me umh -subq 5 -trellis 1 -refs 1 -coder 0 -me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 768K -maxrate 1.5M -bufsize 10M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 16:9 $path_new";
         //$cmd_mencoder3 ="/usr/local/bin/AtomicParsley $path_new --DeepScan --iPod-uuid 1200 --overWrite";
     }
     return exec("{$cmd_mencoder} 2>&1");
 }
Exemple #2
0
 public function actionThumbnail($params)
 {
     $attachment = new Model_Attachment($this->getStorage(), $params['id']);
     if ($attachment->getId()) {
         if ($attachment->isImage()) {
             $file = $attachment->getFilepath();
         } elseif ($attachment->isVideo()) {
             if (class_exists("ffmpeg_movie")) {
                 $film = new ffmpeg_movie($attachment->getFilepath());
                 $frame = ceil($film->getFrameCount() * 0.1);
                 $file = $film->getFrame($frame)->toGDImage();
             } else {
                 $this->imageNotFound();
             }
         } else {
             $this->imageNotFound();
         }
         $view = new View_Image_Gd2($file);
         if ($view) {
             $view->scale($params['scale']);
         } else {
             $this->imageNotFound();
         }
     } else {
         $this->imageNotFound();
     }
     return $view;
 }
 function getVideoMetadata(&$form_values)
 {
     module_load_include('php', 'Fedora_Repository', 'mimetype');
     global $base_url;
     $fileUrl = $form_values["ingest-file-location"];
     $file_size = filesize($fileUrl);
     $file_md5 = md5_file($fileUrl);
     $file_path = $base_url . '/fedora/repository/' . $form_values['pid'] . '/FULL_SIZE';
     $ffmpegInstance = new ffmpeg_movie($fileUrl);
     $form_values['vid_framerate'] = $ffmpegInstance->getFrameRate();
     $form_values['vid_frameheight'] = $ffmpegInstance->getFrameHeight();
     $form_values['vid_framewidth'] = $ffmpegInstance->getFrameWidth();
     $form_values['vid_bitrate'] = $ffmpegInstance->getBitRate();
     $form_values['vid_mime'] = mime_content_type($fileUrl);
     $form_values['vid_size'] = $file_size;
     $form_values['vid_md5'] = $file_md5;
     $form_values['vid_file'] = $file_path;
 }
Exemple #4
0
 /**
  * @overload Canvas::construct();
  *
  * Take a screenshot and return the image
  */
 function __construct($filename, $frame = null)
 {
     if (!extension_loaded('ffmpeg')) {
         throw new BaseException("The FFMPEG extension is not loaded!");
     } else {
         $movie = new ffmpeg_movie($filename);
         if ($frame == null) {
             $frame = floor($movie->getFrameCount());
         }
         $frameimg = $movie->getFrame($frame);
     }
     if ($frameimg) {
         $sc = $frameimg->toGDImage();
         $this->setImage($sc);
     } else {
         throw new GraphicsException("Failed to capture frame!");
     }
 }
 function get_info($file)
 {
     if (!class_exists('ffmpeg_movie') or !($movie = new ffmpeg_movie($file))) {
         //ffmpeg extension required
         return false;
     }
     $duration = $movie->getDuration();
     $width = $movie->getFrameWidth();
     $height = $movie->getFrameHeight();
     $framerate = $movie->getFrameRate();
     $data = '';
     if ($duration) {
         $data .= "Duration: {$duration}\n";
     }
     if ($width and $height) {
         $data .= "Dimensions: {$width} x {$height} px\n";
     }
     if ($framerate) {
         $data .= "Framerate: {$framerate} fps\n";
     }
     return $data;
 }
 /**
  * Create an thumbnail from a video. Returns null if the creation failed.
  *
  * @param string $originalPath    the path of the orignal video
  * @param string $destinationPath the path were the thumbnail will be copied
  * @param int    $newWidth        the width of the thumbnail
  * @param int    $newHeight       the width of the thumbnail
  *
  * @return string
  */
 public function fromVideo($originalPath, $destinationPath, $newWidth, $newHeight)
 {
     if (!$this->isGdLoaded || !$this->isFfmpegLoaded) {
         $message = '';
         if (!$this->isGdLoaded) {
             $message .= 'The GD extension is missing \\n';
         }
         if (!$this->isFfmpegLoaded) {
             $message .= 'The Ffmpeg extension is missing \\n';
         }
         throw new UnloadedExtensionException($message);
     }
     $media = new \ffmpeg_movie($originalPath);
     $frameCount = $media->getFrameCount();
     $frame = $media->getFrame(round($frameCount / 2));
     if ($frame) {
         $image = $frame->toGDImage();
         $this->resize($newWidth, $newHeight, $image, $destinationPath);
         return $destinationPath;
     }
     $exception = new ExtensionNotSupportedException();
     $exception->setExtension(pathinfo($originalPath, PATHINFO_EXTENSION));
     throw $exception;
 }
 public function getVideoSize($fileName)
 {
     $ffmpegInstance = new ffmpeg_movie($fileName);
     $video_size['width'] = $ffmpegInstance->getFrameWidth();
     $video_size['height'] = $ffmpegInstance->getFrameHeight();
     $video_size['duration'] = $ffmpegInstance->getDuration();
     $video_size['frame_rate'] = $ffmpegInstance->getFrameRate();
     $video_size['frame_count'] = $ffmpegInstance->getFrameCount();
     return $video_size;
 }
Exemple #8
0
    echo basename($mediaAccess->srcname);
    ?>
</strong> (Dimple : <?php 
    echo $mediaAccess->getCategorie() . ' / ' . $mediaAccess->getDescription();
    ?>
)
        	<p><?php 
    echo $mediaAccess->getRelatedAvionsListAsString();
    ?>
</strong> (Rank <?php 
    echo $mediaAccess->getRank();
    ?>
) - Technical information :
			<?php 
    $video_source = getFtpMediasRoot() . $mediaAccess->srcname;
    $movie = new ffmpeg_movie($video_source);
    echo round($movie->getDuration());
    ?>
s /
            <?php 
    echo $movie->getFrameWidth();
    ?>
 x <?php 
    echo $movie->getFrameHeight();
    ?>
 px / <?php 
    echo $mediaAccess->getFileSize();
    ?>
</p>
			<?php 
    // Affichage du formulaire d'édition
Exemple #9
0
<?php

$time = $_GET["time"];
//store the time passed in the URL form start.php
//get the frame object from the movie at time = $time
$movie = new ffmpeg_movie("bunny.webm", false);
$fps = $movie->getFrameRate();
$frameNumber = floor($time * $fps);
$frame = $movie->getFrame($frameNumber);
//convert the frame to an image
$image = $frame->toGDImage();
//save the images sequentially (starting at filename = 1.jpeg) in a directory
$array = glob("*.jpeg");
$maxint = 1;
//find the "maximum" jpeg filename in a directory
//for example, if a directory has file 1.jpeg, 2.jpeg, 3.jpeg, then $maxint will be 3
foreach ($array as $filename) {
    $name = ltrim($filename, "pic");
    $name = rtrim($name, ".jpeg");
    $name = intval($name);
    if ($name > $maxint) {
        $maxint = $name;
    }
}
//increase $maxint by 1 to get the current filename
$name = $maxint + 1;
echo $name;
//save the image as a file in the current directory
imagejpeg($image, "pic" . $name . ".jpeg");
$path = "pic" . $name . ".jpeg";
echo "<img src='{$path}'/>";
Exemple #10
0
 // altalanos dolgok a videokrol + konvertalashoz
 $extension = "ffmpeg";
 $extension_soname = $extension . "." . PHP_SHLIB_SUFFIX;
 $extension_fullname = PHP_EXTENSION_DIR . "/" . $extension_soname;
 // load extension
 if (!extension_loaded($extension)) {
     dl($extension_soname);
 }
 // Set our source file
 $srcFile = $gdir . $filename;
 $destFile = $gdir . "tmp_" . substr($filename, 0, strrpos($filename, ".")) . ".flv";
 $newFile = substr($filename, 0, strrpos($filename, ".")) . ".flv";
 $thumbFile = $gdir . "tn_" . substr($filename, 0, strrpos($filename, ".")) . ".flv.jpg";
 $ffmpegPath = "ffmpeg";
 // Create our FFMPEG-PHP class
 $ffmpegObj = new ffmpeg_movie($srcFile);
 // Save our needed variables
 $srcWidth = $ffmpegObj->getFrameWidth();
 $srcHeight = $ffmpegObj->getFrameHeight();
 $srcFPS = $ffmpegObj->getFrameRate();
 $srcAB = intval($ffmpegObj->getAudioBitRate() / 1000);
 $srcAR = $ffmpegObj->getAudioSampleRate();
 // thumbnail
 $ff_frame = $ffmpegObj->getFrame(30);
 if ($ff_frame) {
     $ff_frame->resize($_SESSION['site_thumbwidth'], $_SESSION['site_thumbheight']);
     $gd_image = $ff_frame->toGDImage();
     if ($gd_image) {
         //ha nincs konvertalas, akkor mas lez a file neve
         if (empty($_SESSION['site_gallery_is_convert'])) {
             $thumbFile = $gdir . $tn_name . ".jpg";
Exemple #11
0
function analyzeMediaFile(&$metaData, $filePath = NULL, $cachePath = NULL)
{
    if (!isset($metaData->fileName) || !isset($metaData->fileType)) {
        throw new Exception("meta data invalid");
    }
    $file = $filePath . DIRECTORY_SEPARATOR . $metaData->fileName;
    if (!is_file($file) || !is_readable($file)) {
        throw new Exception("file does not exist");
    }
    if (!is_dir($cachePath)) {
        throw new Exception("cache dir does not exist");
    }
    switch ($metaData->fileType) {
        case "video/quicktime":
        case "application/ogg":
        case "audio/mpeg":
        case "video/mp4":
        case "video/x-msvideo":
        case "video/ogg":
        case "video/webm":
        case "video/x-ms-asf":
        case "video/x-flv":
        case "audio/x-wav":
        case "application/octet-stream":
            if (isMediaFile($metaData, $filePath)) {
                $media = new ffmpeg_movie($file, FALSE);
                /****************************************************
                 * VIDEO
                 ****************************************************/
                if ($media->hasVideo()) {
                    $metaData->video->codec = $media->getVideoCodec();
                    $metaData->video->width = $media->getFrameWidth();
                    $metaData->video->height = $media->getFrameHeight();
                    $metaData->video->bitrate = $media->getVideoBitRate();
                    $metaData->video->framerate = $media->getFrameRate();
                    $metaData->video->duration = $media->getDuration();
                    /* Video Still */
                    $stillFile = $cachePath . DIRECTORY_SEPARATOR . uniqid("ft_") . ".png";
                    $fc = (int) ($media->getFrameCount() / 32);
                    /* frame count is not necessarily reliable! */
                    foreach (array($fc, 100, 10, 1) as $fno) {
                        if ($fno == 0) {
                            continue;
                        }
                        $f = $media->getFrame($fno);
                        if ($f !== FALSE) {
                            imagepng($f->toGDImage(), $stillFile);
                            $metaData->video->still = basename($stillFile);
                            break;
                        }
                    }
                    /* Video Thumbnails */
                    $thumbSizes = array(90, 180, 360);
                    foreach ($thumbSizes as $tS) {
                        $thumbFile = $cachePath . DIRECTORY_SEPARATOR . uniqid("ft_") . ".png";
                        list($thumb_width, $thumb_height) = generateThumbnail($stillFile, $thumbFile, $tS);
                        $metaData->video->thumbnail->{$tS}->file = basename($thumbFile);
                        $metaData->video->thumbnail->{$tS}->width = $thumb_width;
                        $metaData->video->thumbnail->{$tS}->height = $thumb_height;
                    }
                    /* Schedule for transcoding */
                    $transcodeSizes = array(360);
                    $metaData->transcodeStatus = 'WAITING';
                    $metaData->transcodeProgress = 0;
                    foreach ($transcodeSizes as $tS) {
                        $transcodeFile = $cachePath . DIRECTORY_SEPARATOR . uniqid("ft_") . ".webm";
                        list($width, $height) = scaleVideo($media->getFrameWidth(), $media->getFrameHeight(), $tS);
                        $metaData->video->transcode->{$tS}->file = basename($transcodeFile);
                        $metaData->video->transcode->{$tS}->width = $width;
                        $metaData->video->transcode->{$tS}->height = $height;
                    }
                }
                /****************************************************
                 * AUDIO
                 ****************************************************/
                if ($media->hasAudio()) {
                    $metaData->audio->codec = $media->getAudioCodec();
                    $metaData->audio->bitrate = $media->getAudioBitRate();
                    $metaData->audio->samplerate = $media->getAudioSampleRate();
                    $metaData->audio->duration = $media->getDuration();
                    $metaData->transcodeStatus = 'WAITING';
                    $metaData->transcodeProgress = 0;
                    $transcodeFile = $cachePath . DIRECTORY_SEPARATOR . uniqid("ft_") . ".ogg";
                    $metaData->audio->transcode->file = basename($transcodeFile);
                }
            } else {
                /* No media? */
            }
            break;
        case "image/jpeg":
        case "image/png":
        case "image/gif":
        case "image/bmp":
            list($width, $height) = getimagesize($file);
            $metaData->image->width = $width;
            $metaData->image->height = $height;
            $thumbFile = $cachePath . DIRECTORY_SEPARATOR . uniqid("ft_") . ".png";
            list($thumb_width, $thumb_height) = generateThumbnail($file, $thumbFile, 360);
            $metaData->image->thumbnail->{360}->file = basename($thumbFile);
            $metaData->image->thumbnail->{360}->width = $thumb_width;
            $metaData->image->thumbnail->{360}->height = $thumb_height;
            break;
        default:
            /* no idea about this file, let it go... */
    }
}
Exemple #12
0
 public function convertToFlv($height = null, $width = null)
 {
     if (is_null($width)) {
         $width = 320;
     }
     if (is_null($height)) {
         $height = 240;
     }
     $destFolder = $this->getServerAbsoluteDirUrl() . "flv" . DIRECTORY_SEPARATOR;
     $image_destFolder = $destFolder . "thumbs" . DIRECTORY_SEPARATOR;
     $output_image = $image_destFolder . $this->getId() . ".jpg";
     $output_flv = $destFolder . $this->getId() . ".flv";
     if (!is_dir($destFolder)) {
         mkdir($destFolder, 0777, true);
     }
     if (!is_dir($image_destFolder)) {
         mkdir($image_destFolder, 0777, true);
     }
     if (file_exists($output_image)) {
         unlink($output_image);
     }
     if (file_exists($output_flv)) {
         unlink($output_flv);
     }
     $command = "ffmpeg -i " . $this->getServerAbsoluteUrl() . " -ar 22050 -ab 32 -f flv -s " . $width . "x" . $height . " -qcomp 0.6 -qmax 15 -qdiff 4 -i_qfactor 0.71428572 -b_qfactor 0.76923078 " . $output_flv;
     exec($command);
     if (unlink($this->getServerAbsoluteUrl())) {
         $this->setFiledirpath($this->getFiledirpath() . "flv" . DIRECTORY_SEPARATOR);
         $this->setFiletype("video/x-flv");
         $this->setFilename($this->getId() . ".flv");
         $this->save();
     }
     $mov = new ffmpeg_movie($this->getServerAbsoluteUrl());
     if ($mov) {
         $ff_frame = $mov->getFrame(100);
     }
     if ($ff_frame) {
         $gd_image = $ff_frame->toGDImage();
         if ($gd_image) {
             imagejpeg($gd_image, $output_image);
         }
     }
 }
Exemple #13
0
 function path($param1 = array(), $param2 = array(), $param3 = array())
 {
     if (is_array($param1)) {
         $path = $param1['path'];
         $filename = $param1['filename'];
         $options =& $param2;
     } else {
         $path = $param1;
         $filename = $param2;
         $options = $param3;
     }
     if ($path == '' || $filename == '') {
         return false;
     }
     // Set default values
     if (!isset($options['full'])) {
         $options['full'] = false;
     }
     if (!isset($options['dims'])) {
         $options['dims'] = 'original';
     }
     if (isset($options['size'])) {
         $options['dims'] = $options['size'];
     }
     if ($options['dims'] != 'original' && !isset($options['method'])) {
         $options['method'] = 'crop';
     }
     if (!isset($options['saveas'])) {
         $options['saveas'] = null;
     }
     if (!isset($options['time'])) {
         $options['time'] = null;
     }
     if (!isset($options['watermark'])) {
         $options['watermark'] = null;
     }
     // Path must not begin with slash but must end with slash
     if ($path[0] == '/') {
         $path = substr($path, 1);
     }
     if (substr($path, -1) != '/') {
         $path .= '/';
     }
     // Absolute path to directory
     $absolutePath = WWW_ROOT . $path;
     // Absolute path to file
     $absoluteFilePath = $absolutePath . $filename;
     if (file_exists($absoluteFilePath)) {
         $fileSize = filesize($absoluteFilePath);
         $fileExt = strtolower(strrchr($filename, '.'));
         if ($fileExt == '.jpeg') {
             $fileExt = '.jpg';
         }
         if (!in_array($fileExt, array('.jpg', '.jpeg', '.png', '.gif', '.f4v', '.flv'))) {
             return false;
         }
         $fileNameNoExt = substr($filename, 0, -strlen($fileExt));
         if ($options['saveas'] == null) {
             if ($fileExt == '.flv' || $fileExt == '.f4v') {
                 $options['saveas'] = '.jpg';
             }
             $options['saveas'] = $fileExt;
         } else {
             $options['saveas'] = strtolower($options['saveas']);
             if ($options['saveas'] == '.jpeg') {
                 $options['saveas'] == '.jpg';
             }
             if ($options['saveas'][0] != '.') {
                 $options['saveas'] = '.' . $options['saveas'];
             }
         }
         if ($options['dims'] == 'original' && $options['saveas'] == $fileExt && $fileExt != '.flv' && $fileExt != '.f4v' && $options['watermark'] == null) {
             // original file returned
             return $this->url('/' . $path . $filename, $options['full']);
         } else {
             $cachedFile = $this->_cachePath($path, $fileNameNoExt, $fileExt, $fileSize, $options);
             if ($cachedFile['exists']) {
                 return $this->url($cachedFile['path'] . $cachedFile['filename'], $options['full']);
             } else {
                 // create file
                 if ($fileExt == '.flv' || $fileExt == '.f4v') {
                     // if video, check if a screenshot already exists
                     $optionsOriginal = $options;
                     $optionsOriginal['dims'] = 'original';
                     $optionsOriginal['watermark'] = null;
                     $videoScreenshot = $this->_cachePath($path, $fileNameNoExt, $fileExt, $fileSize, $optionsOriginal);
                     if ($videoScreenshot['exists']) {
                         // Screenshot already exists, use it
                         $img = $this->_loadImage($videoScreenshot['path'], $videoScreenshot['filename']);
                     } else {
                         // No screenshot available, take one
                         if (class_exists('ffmpeg_movie')) {
                             $ffmpegInstance = new ffmpeg_movie($absoluteFilePath);
                             if ($options['time'] != null) {
                                 // take screenshot at specified time
                                 $framerate = $ffmpegInstance->getFrameRate();
                                 $framecount = $ffmpegInstance->getFrameCount();
                                 $frame_number = $framerate * $options['time'];
                                 if ($frame_number > $framecount - 1) {
                                     // invalid time
                                     $frame = $ffmpegInstance->getFrame((int) ($ffmpegInstance->getFrameCount() / 2));
                                 } else {
                                     $frame = $ffmpegInstance->getFrame($frame_number);
                                 }
                             } else {
                                 // take screenshot at middle of video
                                 $frame = $ffmpegInstance->getFrame((int) ($ffmpegInstance->getFrameCount() / 2));
                             }
                             $img = $frame->toGDImage();
                             // Save screenshot for future use
                             $this->_saveImage($img, $videoScreenshot['path'], $videoScreenshot['filename'], $options['saveas']);
                         } else {
                             return false;
                         }
                     }
                 } else {
                     // this is not a video
                     // load image
                     $img = $this->_loadImage($path, $filename, $fileExt);
                 }
                 // Add watermark if needed
                 if ($options['watermark'] != null) {
                     if ($options['watermark'][0] == '/') {
                         $options['watermark'] = substr($options['watermark'], 1);
                     }
                     $absoluteWatermarkFile = WWW_ROOT . $options['watermark'];
                     if (file_exists($absoluteWatermarkFile)) {
                         $watermarkFileName = basename($options['watermark']);
                         $watermark = $this->_loadImage(dirname($options['watermark']) . '/', $watermarkFileName, strtolower(strrchr($watermarkFileName, '.')));
                         //var_dump($watermark);
                         //die();
                         $watermark_width = imagesx($watermark);
                         $watermark_height = imagesy($watermark);
                         $img_height = imagesy($img);
                         $img_width = imagesx($img);
                         for ($i = 0; $i < $img_width; $i = $i + 1.5 * $watermark_width) {
                             for ($j = 0; $j < $img_height; $j = $j + 1.5 * $watermark_height) {
                                 imagecopy($img, $watermark, $i, $j, 0, 0, $watermark_width, $watermark_height);
                             }
                         }
                     }
                 }
                 // crop/resize if needed
                 if ($options['dims'] != 'original') {
                     if ($options['method'] == 'crop') {
                         $img = $this->_crop($img, $options['dims'], $fileExt == '.png' && $options['saveas'] == '.png');
                     } elseif ($options['method'] == 'resize') {
                         $img = $this->_resize($img, $options['dims'], $fileExt == '.png' && $options['saveas'] == '.png');
                     }
                 }
                 // Save image
                 if ($this->_saveImage($img, $cachedFile['path'], $cachedFile['filename'], $options['saveas'])) {
                     imagedestroy($img);
                     return $this->url($cachedFile['path'] . $cachedFile['filename'], $options['full']);
                 }
                 return false;
             }
         }
     }
     return false;
 }
function make_test_thumbnail($frame, $input, $outpath)
{
    $mov = new ffmpeg_movie($input);
    $ff_frame = $mov->getFrame($frame);
    if ($ff_frame) {
        $gd_image = $ff_frame->toGDImage();
        if ($gd_image) {
            imagepng($gd_image, $outpath);
            imagedestroy($gd_image);
        } else {
            return false;
        }
    } else {
        return false;
    }
    return true;
}
Exemple #15
0
 $files3[$i] = str_replace(")", "_", $files2[$i]);
 $files4[$i] = str_replace("(", "_", $files3[$i]);
 $files5[$i] = str_replace("'", "_", $files4[$i]);
 $files5[$i] = str_replace("á", "a", $files5[$i]);
 $files5[$i] = str_replace("é", "e", $files5[$i]);
 $files5[$i] = str_replace("í", "i", $files5[$i]);
 $files5[$i] = str_replace("ó", "o", $files5[$i]);
 $files5[$i] = str_replace("ú", "u", $files5[$i]);
 $files5[$i] = str_replace("ü", "u", $files5[$i]);
 $files5[$i] = str_replace("ć", "c", $files5[$i]);
 $files5[$i] = str_replace("ë", "e", $files5[$i]);
 if (move_uploaded_file($_FILES['archivo']['tmp_name'][$i], $peltmp . $files5[$i])) {
     echo "<div id='rs'>Ya subio, ahora espera un rato para que este disponible!!!</div>";
     //Duracion del video
     $peldur = "{$peltmp}{$files5[$i]}";
     $movie = new ffmpeg_movie($peldur);
     $seg = $movie->getDuration();
     $horas = floor($seg / 3600);
     $minutos = floor(($seg - $horas * 3600) / 60);
     if ($minutos < 10) {
         $min = "0{$minutos}";
     } else {
         $min = "{$minutos}";
     }
     $segundos = number_format($seg - $horas * 3600 - $minutos * 60);
     $dura = $horas . ':' . $min . ':' . $segundos;
     if ($sd == '0') {
         //Insertar base de datos de Peliculas
         $sql1 = "INSERT INTO lista (titulo, fecha, titucom, direccion, bueno, malo, dura) VALUES ('{$pelnom}', '{$ap}', '{$pelnomf}', '{$dp}', '0', '0', '{$dura}' )";
         mysql_query($sql1, $connect);
     } elseif ($sd == '1') {
 /**
  * Completes track information from a given path using ffmpeg.
  * @param Track $track
  */
 public function autocompleteTrack(Track $track)
 {
     if (!$track->getPath()) {
         throw new \BadMethodCallException('Input track has no path defined');
     }
     $file = $track->getPath();
     $movie = new \ffmpeg_movie($file, false);
     $finfo = new \finfo();
     if (!$this->fileHasMediaContent($finfo, $file)) {
         throw new \InvalidArgumentException("This file has no video nor audio tracks");
     }
     $only_audio = true;
     // General
     $track->setMimetype($finfo->file($file, FILEINFO_MIME_TYPE));
     $track->setBitrate($movie->getBitRate());
     $track->setDuration(ceil($movie->getDuration()));
     $track->setSize(filesize($file));
     if ($movie->hasVideo()) {
         $only_audio = false;
         $track->setVcodec($movie->getVideoCodec());
         $track->setFramerate($movie->getFrameRate());
         $track->setWidth($movie->getFrameWidth());
         $track->setHeight($movie->getFrameHeight());
     }
     if ($movie->hasAudio()) {
         $track->setAcodec($movie->getAudioCodec());
         $track->setChannels($movie->getAudioChannels());
     }
     $track->setOnlyAudio($only_audio);
 }
Exemple #17
0
<!-- attempts to play webpage video and desktop video synchronously and capturing snapshot -->
<!DOCTYPE html>
<html>
	<link type = "text/css" rel = "stylesheet" href = "stylesheet.css" />
	<body>

	<h1>billboard.com</h1>

	<button id="button" onclick="getCurTime()" type="button">Snapshot</button>
	<?php 
$video = new ffmpeg_movie("bunny.webm", false);
$duration = $video->getDuration();
$time_start = strtotime("06/01/2015 14:53:00");
$time_end = time();
$lapse = $time_end - $time_start;
//find time lapse between current time and start of desktop video
global $play_vid;
$play_vid = floor($lapse % $duration);
//finds the time at which webpage video should play
echo $play_vid;
?>
	
	<!-- plays the video automatically at the right point -->
	<video id="myVideo" width = "500" height = "500" autoplay loop onplay="seek()">
		<source src="bunny.webm" type="video/webm" onseeked="play()">	<!-- once start position is seeked, the video should play -->
	Not supported
	</video>
	
	<script>
	
	var vid = document.getElementById("myVideo"); 
 function genLocalStreamImage($stream_id, $req_time, $req_size)
 {
     global $mvLocalVideoPath, $mvStreamImageTable;
     //zsh edit
     return false;
     if (!$stream_id) {
         return false;
     }
     if (!$req_time) {
         $req_time = 0;
     }
     if (!$req_size) {
         $req_size = '320x240';
     }
     list($im_width, $im_height, $ext) = MV_StreamImage::getSizeType($req_size);
     if ($req_size == null) {
         $s = '';
     } else {
         $s = '_' . $im_width . 'x' . $im_height;
     }
     $img_dir = MV_StreamImage::getLocalImageDir($stream_id);
     $img_file = $img_dir . "/" . $req_time . $s . "." . $ext;
     $streampath = $mvLocalVideoPath . MV_StreamImage::getLocalStreamPath($stream_id);
     if (is_file($streampath)) {
         //check if the ffmpeg extension is installed:
         $extension = "ffmpeg";
         $extension_soname = $extension . "." . PHP_SHLIB_SUFFIX;
         $extension_fullname = PHP_EXTENSION_DIR . "/" . $extension_soname;
         // load extension
         if (!extension_loaded($extension)) {
             if (!dl($extension_soname)) {
                 return false;
             }
         }
         $mov = new ffmpeg_movie($streampath);
         $fps = $mov->getFrameRate();
         if ($req_time == 0) {
             $ff_frame = $mov->getFrame(1);
         } else {
             $ff_frame = $mov->getFrame($req_time * $fps);
         }
         if ($ff_frame) {
             $ff_frame->resize($im_width, $im_height);
             $gd_image = $ff_frame->toGDImage();
             if ($gd_image) {
                 if ($ext == 'png') {
                     imagepng($gd_image, $img_file);
                     imagedestroy($gd_image);
                 } else {
                     imagejpeg($gd_image, $img_file);
                     imagedestroy($gd_image);
                 }
             }
         }
         if (is_file($img_file) && ($req_size == '320x240' || $req_size == '')) {
             $insAry = array();
             $insAry[stream_id] = $stream_id;
             $insAry[time] = $req_time;
             $db =& wfGetDB(DB_WRITE);
             if ($db->insert($mvStreamImageTable, $insAry)) {
                 return $img_file;
             } else {
                 //probably error out before we get here
                 return false;
             }
         }
     }
     return $img_file;
 }
Exemple #19
0
 public function generateFFMPEG()
 {
     $ff = new ffmpeg_movie($this->pathname . $this->filename);
     if (!$ff) {
         $this->unknown = true;
         return false;
     }
     $this->info = array('width' => $ff->getFrameWidth(), 'height' => $ff->getFrameHeight(), 'duration' => $ff->getDuration(), 'mime' => $this->mime, 'size' => filesize($this->pathname . $this->filename));
     if ($ff->getFrameCount() > 20) {
         $frame = $frame = $ff->getFrame(20);
     } else {
         $frame = $frame = $ff->getFrame($ff->getFrameCount() - 1);
     }
     $gd = $frame->toGDImage();
     imagejpeg($gd, $this->pathcache . $this->getBaseName());
     $this->mime = 'image/jpeg';
     $this->type = array('video', 'jpeg');
     $this->pathname = $this->pathcache;
     $this->filename = $this->getBaseName();
 }
Exemple #20
0
echo basename($mediaAccess->basename, '.flv');
?>
<br /></strong>
            </h2>
			<p>Technical information</strong> :  <strong><?php 
echo round($mediaAccess->getFFMEPGObject()->getDuration());
?>
 s</strong> duration / <strong>
            <?php 
$video_source = getFtpMediasRoot() . $mediaAccess->srcname;
$movie = new ffmpeg_movie($video_source);
echo $movie->getFrameWidth();
?>
 x 
			<?php 
$video_source = getFtpMediasRoot() . $mediaAccess->srcname;
$movie = new ffmpeg_movie($video_source);
echo $movie->getFrameHeight();
?>
             px</strong> source size / <strong>
			<?php 
echo strtolower(substr($mediaAccess->srcname, -3));
?>
</strong> file format</p>
        	<div class="lineclear"><p class="hide">&nbsp;</p></div>
        <p>&nbsp;</p>
        </div>
        <div id="footer"><p> </p></div>
</div>
</body>
</html>
Exemple #21
0
    dl($extension_soname) or die("Can't load extension {$extension_fullname}\n");
}
if (php_sapi_name() != 'cli') {
    echo '<pre>';
}
printf("ffmpeg-php version string: %s\n", FFMPEG_PHP_VERSION_STRING);
printf("ffmpeg-php build date string: %s\n", FFMPEG_PHP_BUILD_DATE_STRING);
printf("libavcodec build number: %d\n", LIBAVCODEC_BUILD_NUMBER);
printf("libavcodec version number: %d\n", LIBAVCODEC_VERSION_NUMBER);
print_class_methods("ffmpeg_movie");
print_class_methods("ffmpeg_frame");
// get an array for movies from the test media directory
$movies = getDirFiles(dirname(__FILE__) . '/tests/test_media');
echo "--------------------\n\n";
foreach ($movies as $movie) {
    $mov = new ffmpeg_movie($movie);
    printf("file name = %s\n", $mov->getFileName());
    printf("duration = %s seconds\n", $mov->getDuration());
    printf("frame count = %s\n", $mov->getFrameCount());
    printf("frame rate = %0.3f fps\n", $mov->getFrameRate());
    printf("comment = %s\n", $mov->getComment());
    printf("title = %s\n", $mov->getTitle());
    printf("author = %s\n", $mov->getAuthor());
    printf("copyright = %s\n", $mov->getCopyright());
    printf("get bit rate = %d\n", $mov->getBitRate());
    printf("has audio = %s\n", $mov->hasAudio() == 0 ? 'No' : 'Yes');
    if ($mov->hasAudio()) {
        printf("get audio stream id= %s\n", $mov->getAudioStreamId());
        printf("get audio codec = %s\n", $mov->getAudioCodec());
        printf("get audio bit rate = %d\n", $mov->getAudioBitRate());
        printf("get audio sample rate = %d \n", $mov->getAudioSampleRate());
Exemple #22
0
//Tests out timer functions of PHP in order to 
//sync video playing on webpage (webpage video) with video playing on desktop (desktop video)

<?php 
//play the video on the desktop
exec("cd /opt/lampp/htdocs/WEB/");
exec("xdg-open bunny.webm");
//get the start time of playing the desktop video
$time_start = microtime();
//get the duration of the video
$movie = new ffmpeg_movie("bunny.mpeg");
$duration = $movie->getDuration();
while (null) {
    //find the time difference between desktop ($time_start) and webpage ($time_end) video
    $time_end = microtime();
    $lapse = $time_end - $time_start;
    //determine at which point the webpage video needs to start by
    //finding remainder from time elapsed divided by video duration
    $play = $lapse % $duration;
}
Exemple #23
0
    require_once '../adapters/ffmpeg-php/ffmpeg_animated_gif.php';
} else {
    echo '<strong>You currently have ffmpeg-php installed on your server, and the module is loaded, therefore this example will not use the PHPVideoToolkit ffmpeg-php adapter. It will use the actual ffmpeg-php module.</strong><br /><br />';
}
// 	temp directory
$tmp_dir = PHPVIDEOTOOLKIT_EXAMPLE_ABSOLUTE_BATH . 'tmp/';
// 	the frame number to retrieve
$frame_number = 15;
//	input movie files
// 	$file = PHPVIDEOTOOLKIT_EXAMPLE_ABSOLUTE_BATH.'to-be-processed/mp3.mp3';
$file = PHPVIDEOTOOLKIT_EXAMPLE_ABSOLUTE_BATH . 'to-be-processed/MOV00007.3gp';
$file_info = pathinfo($file);
//	output files dirname has to exist
$thumbnail_output_dir = PHPVIDEOTOOLKIT_EXAMPLE_ABSOLUTE_BATH . 'processed/thumbnails/';
// 	load the movie
$ffmpeg_movie = new ffmpeg_movie($file, false, $tmp_dir);
// 	get the 20th frame from the movie
$frame = $ffmpeg_movie->getFrame($frame_number);
// 	check the frame has been returned
if ($frame === false) {
    die('The frame, ' . $frame_number . ' does not exist.');
}
// 	print_R($frame);
// 	create the same size thumbnail
$gd_resource = $frame->toGDImage();
$orig_width = $frame->getWidth();
$orig_height = $frame->getHeight();
// 	echo $gd_resource;
imagejpeg($gd_resource, PHPVIDEOTOOLKIT_EXAMPLE_ABSOLUTE_BATH . 'processed/thumbnails/' . $file_info['filename'] . '-samesize.jpg', 80);
echo '<strong>Plain Frame Grab of Movie</strong>.<br />';
echo 'This is a frame grab at the same resolution as the video.<br />';
Exemple #24
0
 function GetPicture($framepos = 1, $where = false)
 {
     //return $path of picture or false; $frame=frame number; $where=path to file to create, if false will be in cache;
     if (!$this->Streams['picturable']) {
         if (!$this->Picturable()) {
             return false;
         } else {
             $this->Streams['picturable'] = true;
         }
     }
     if (isset($this->Streams['theora']['pictures'])) {
         if (isset($this->Streams['theora']['pictures'][$framepos])) {
             if (file_exists($this->realpath($this->Streams['theora']['pictures'][$framepos]))) {
                 return $this->Streams['theora']['pictures'][$framepos];
             }
         }
     }
     if (!$this->cache && !$where) {
         return $this->creturn("If the CACHING is disabled, you got to provide a path to your picture...");
     }
     $file = $where ? $where : substr($this->Streams['cachefile'], 0, -6) . ".f{$framepos}.jpg";
     if (file_exists($this->realpath($file))) {
         // picture seem to have previously alread been computed, but is not in cache: either cache was relaculated and information was lost, or caching is disabled
         // we use the picture we found, avoiding wasting server time to recalculate
         if (!isset($this->Streams['theora']['pictures'])) {
             $this->Streams['theora']['pictures'] = array();
         }
         $this->Streams['theora']['pictures'][$framepos] = $file;
         if ($this->cache) {
             $this->CacheUpdate();
         }
         $this->creturn(true);
         return $file;
     }
     $errorreport = error_reporting(0);
     $movie = new ffmpeg_movie($this->Streams['oggfile'], false);
     if (!$movie) {
         error_reporting($errorreport);
         return $this->creturn("Unable to extract a picture from " . $this->Streams['oggfile']);
     }
     $frame = $movie->getFrame($framepos);
     if (!$frame) {
         error_reporting($errorreport);
         return $this->creturn("Unable to extract the frame #" . $framepos . " from " . $this->Streams['oggfile']);
     }
     $image = $frame->toGDImage();
     if (!$image) {
         error_reporting($errorreport);
         return $this->creturn("Unable to extract an image in frame #" . $framepos . " from " . $this->Streams['oggfile']);
     }
     if (!imagejpeg($image, $this->realpath($file))) {
         error_reporting($errorreport);
         return $this->creturn("Unable to save a jpeg image from frame #" . $framepos . " from " . $this->Streams['oggfile']);
     }
     if (!isset($this->Streams['theora']['pictures'])) {
         $this->Streams['theora']['pictures'] = array();
     }
     $this->Streams['theora']['pictures'][$framepos] = $file;
     if ($this->cache) {
         $this->CacheUpdate();
     }
     error_reporting($errorreport);
     $this->creturn(true);
     return $file;
 }
Exemple #25
0
 /**
  * Returns the information we could find on the file
  * @return Array
  */
 public function getFileinfo()
 {
     if ($this->fileinfos == null) {
         $toret = parent::getFileinfo();
         // get the exif data
         try {
             /*
             $cls=new ReflectionClass('ffmpeg_movie');
             print '<xmp>';
             foreach($cls->getMethods() as $n) print '$toret[\'video.'.$n->name.'\'] = $movie->'.$n->name."();\n";
             print '</xmp>';
             */
             $movie = new ffmpeg_movie($this->fullpath, false);
             $toret['video.duration'] = $movie->getduration();
             $toret['video.framecount'] = $movie->getframecount();
             $toret['video.framerate'] = $movie->getframerate();
             $toret['video.filename'] = $movie->getfilename();
             $toret['video.comment'] = $movie->getcomment();
             $toret['video.title'] = $movie->gettitle();
             $toret['video.author'] = $movie->getauthor();
             $toret['video.artist'] = $movie->getartist();
             $toret['video.copyright'] = $movie->getcopyright();
             $toret['video.album'] = $movie->getalbum();
             $toret['video.genre'] = $movie->getgenre();
             $toret['video.year'] = $movie->getyear();
             $toret['video.tracknumber'] = $movie->gettracknumber();
             $toret['video.framewidth'] = $movie->getframewidth();
             $toret['video.frameheight'] = $movie->getframeheight();
             $toret['video.framenumber'] = $movie->getframenumber();
             $toret['video.pixelformat'] = $movie->getpixelformat();
             $toret['video.bitrate'] = $movie->getbitrate();
             $toret['video.hasaudio'] = $movie->hasaudio();
             $toret['video.hasvideo'] = $movie->hasvideo();
             $toret['video.videocodec'] = $movie->getvideocodec();
             $toret['video.audiocodec'] = $movie->getaudiocodec();
             $toret['video.videostreamid'] = $movie->getvideostreamid();
             $toret['video.audiostreamid'] = $movie->getaudiostreamid();
             $toret['video.audiochannels'] = $movie->getaudiochannels();
             $toret['video.audiosamplerate'] = $movie->getaudiosamplerate();
             $toret['video.audiobitrate'] = $movie->getaudiobitrate();
             $toret['video.videobitrate'] = $movie->getvideobitrate();
             $toret['video.pixelaspectratio'] = $movie->getpixelaspectratio();
             foreach ($toret as $k => $v) {
                 if ($v == '') {
                     unset($toret[$k]);
                 }
             }
             //$frm = $movie->getFrame(1);
         } catch (Exception $e) {
         }
         $this->fileinfos = $toret;
         return $this->fileinfos;
     } else {
         return $this->fileinfos;
     }
 }
Exemple #26
0
 public function getDetails()
 {
     $path = Yii::getPathOfAlias('application');
     $file = $path . '/files/' . uid() . DS . $this->file;
     /*
             $command = '/usr/bin/ffmpeg -i ' . escapeshellarg($file) . ' 2>&1';
             $dimensions = array('width'=>0,'height'=>0);
             exec($command, $output, $status);
     	if(preg_match("/Duration: (?P<hour>[0-9]{2})\:(?P<minute>[0-9]{2})\:(?P<seconds>[0-9]{2})\.[0-9]{2}/",implode("\n",$output),$arr))
     		$dimensions['duration'] = $arr['hour']*3600 + $arr['minute']*60 + $arr['seconds'];
     	else
     		$dimensions['duration'] = 0;
             if (!preg_match('/Stream #(?:[0-9\.]+)(?:.*)\: Video: (?P<videocodec>.*) (?P<width>[0-9]*)x(?P<height>[0-9]*)/', implode('\n', $output), $matches)) {
                 preg_match('/Could not find codec parameters \(Video: (?P<videocodec>.*) (?P<width>[0-9]*)x(?P<height>[0-9]*)\)/', implode('\n', $output), $matches);
             }
     */
     if (class_exists('ffmpeg_movie')) {
         $movie = new ffmpeg_movie($file, false);
         if ($movie == NULL) {
             return NULL;
         }
         $dimensions['duration'] = $movie->getDuration();
         $dimensions['width'] = $movie->getFrameWidth();
         $dimensions['height'] = $movie->getFrameHeight();
     } else {
         $dimensions['duration'] = 0;
         $dimensions['width'] = 640;
         $dimensions['height'] = 360;
     }
     /* if (!empty($matches['width']) && !empty($matches['height'])) {
                 $dimensions['width'] = $matches['width'];
                 $dimensions['height'] = $matches['height'];
             }
     	*/
     return $dimensions;
 }
Exemple #27
0
    /**
     * Add a post
     */
    public function iframe_add()
    {
        $this->setView('iframe_add.php');
        @set_time_limit(0);
        $uploaded_files = array();
        try {
            if (!isset(User_Model::$auth_data)) {
                throw new Exception(__('POST_ADD_ERROR_SESSION_EXPIRED'));
            }
            $is_student = isset(User_Model::$auth_data['student_number']);
            // Message
            $message = isset($_POST['message']) ? trim($_POST['message']) : '';
            if ($message == '' || $message == __('PUBLISH_DEFAULT_MESSAGE')) {
                throw new Exception(__('POST_ADD_ERROR_NO_MESSAGE'));
            }
            $message = preg_replace('#\\n{2,}#', "\n\n", $message);
            // Category
            if (!isset($_POST['category']) || !ctype_digit($_POST['category'])) {
                throw new Exception(__('POST_ADD_ERROR_NO_CATEGORY'));
            }
            $category = (int) $_POST['category'];
            // Official post (in a group)
            $official = isset($_POST['official']);
            // Group
            $group = isset($_POST['group']) && ctype_digit($_POST['group']) ? (int) $_POST['group'] : 0;
            if ($group == 0) {
                $group = null;
                $official = false;
            } else {
                $groups_auth = Group_Model::getAuth();
                if (isset($groups_auth[$group])) {
                    if ($official && !$groups_auth[$group]['admin']) {
                        throw new Exception(__('POST_ADD_ERROR_OFFICIAL'));
                    }
                } else {
                    throw new Exception(__('POST_ADD_ERROR_GROUP_NOT_FOUND'));
                }
            }
            // Private message
            $private = isset($_POST['private']);
            if ($private && !$is_student) {
                throw new Exception(__('POST_ADD_ERROR_PRIVATE'));
            }
            $attachments = array();
            // Photos
            if (isset($_FILES['attachment_photo']) && is_array($_FILES['attachment_photo']['name'])) {
                foreach ($_FILES['attachment_photo']['size'] as $size) {
                    if ($size > Config::UPLOAD_MAX_SIZE_PHOTO) {
                        throw new Exception(__('POST_ADD_ERROR_PHOTO_SIZE', array('size' => File::humanReadableSize(Config::UPLOAD_MAX_SIZE_PHOTO))));
                    }
                }
                if ($filepaths = File::upload('attachment_photo')) {
                    foreach ($filepaths as $filepath) {
                        $uploaded_files[] = $filepath;
                    }
                    foreach ($filepaths as $i => $filepath) {
                        $name = isset($_FILES['attachment_photo']['name'][$i]) ? $_FILES['attachment_photo']['name'][$i] : '';
                        try {
                            $img = new Image();
                            $img->load($filepath);
                            $type = $img->getType();
                            if ($type == IMAGETYPE_JPEG) {
                                $ext = 'jpg';
                            } else {
                                if ($type == IMAGETYPE_GIF) {
                                    $ext = 'gif';
                                } else {
                                    if ($type == IMAGETYPE_PNG) {
                                        $ext = 'png';
                                    } else {
                                        throw new Exception();
                                    }
                                }
                            }
                            if ($img->getWidth() > 800) {
                                $img->setWidth(800, true);
                            }
                            $img->save($filepath);
                            // Thumb
                            $thumbpath = $filepath . '.thumb';
                            $img->thumb(Config::$THUMBS_SIZES[0], Config::$THUMBS_SIZES[1]);
                            $img->setType(IMAGETYPE_JPEG);
                            $img->save($thumbpath);
                            unset($img);
                            $attachments[] = array($filepath, $name, $thumbpath);
                            $uploaded_files[] = $thumbpath;
                        } catch (Exception $e) {
                            throw new Exception(__('POST_ADD_ERROR_PHOTO_FORMAT'));
                        }
                    }
                }
            }
            // Vidéos
            /* @uses PHPVideoToolkit : http://code.google.com/p/phpvideotoolkit/
             * @requires ffmpeg, php5-ffmpeg
             */
            if (isset($_FILES['attachment_video']) && is_array($_FILES['attachment_video']['name'])) {
                foreach ($_FILES['attachment_video']['size'] as $size) {
                    if ($size > Config::UPLOAD_MAX_SIZE_VIDEO) {
                        throw new Exception(__('POST_ADD_ERROR_VIDEO_SIZE', array('size' => File::humanReadableSize(Config::UPLOAD_MAX_SIZE_VIDEO))));
                    }
                }
                if ($filepaths = File::upload('attachment_video')) {
                    foreach ($filepaths as $filepath) {
                        $uploaded_files[] = $filepath;
                    }
                    foreach ($filepaths as $i => $filepath) {
                        $name = isset($_FILES['attachment_video']['name'][$i]) ? $_FILES['attachment_video']['name'][$i] : '';
                        try {
                            $video = new ffmpeg_movie($filepath, false);
                            if (!$video->hasVideo()) {
                                throw new Exception('No video stream found in the file');
                            }
                            if (!$video->hasAudio()) {
                                throw new Exception('No audio stream found in the file');
                            }
                        } catch (Exception $e) {
                            throw new Exception(__('POST_ADD_ERROR_VIDEO_FORMAT'));
                        }
                        // Video conversion
                        try {
                            $video_current_width = $video->getFrameWidth();
                            $video_width = min($video_current_width, Config::VIDEO_MAX_WIDTH);
                            if ($video_width % 2 == 1) {
                                // Even number required
                                $video_width--;
                            }
                            $video_height = $video_width * $video->getFrameHeight() / $video_current_width;
                            if ($video_height % 2 == 1) {
                                // Even number required
                                $video_height--;
                            }
                            // Extract thumb
                            $video_thumb = $video->getFrame(round($video->getFrameCount() * 0.2));
                            unset($video);
                            $video_thumb = $video_thumb->toGDImage();
                            $thumbpath = DATA_DIR . Config::DIR_DATA_TMP . File::getName($filepath) . '.thumb';
                            imagejpeg($video_thumb, $thumbpath, 95);
                            unset($video_thumb);
                            $img = new Image();
                            $img->load($thumbpath);
                            $img->setWidth($video_width, true);
                            $img->setType(IMAGETYPE_JPEG);
                            $img->save($thumbpath);
                            $uploaded_files[] = $thumbpath;
                            unset($img);
                            // Convert to FLV
                            if (!preg_match('#\\.flv$#i', $filepath)) {
                                $toolkit = new PHPVideoToolkit();
                                $toolkit->on_error_die = true;
                                // Will throw exception on error
                                $toolkit->setInputFile($filepath);
                                $toolkit->setVideoOutputDimensions($video_width, $video_height);
                                $toolkit->setFormatToFLV(Config::VIDEO_SAMPLING_RATE, Config::VIDEO_AUDIO_BIT_RATE);
                                $toolkit->setOutput(DATA_DIR . Config::DIR_DATA_TMP, File::getName($filepath) . '.flv', PHPVideoToolkit::OVERWRITE_EXISTING);
                                $toolkit->execute(false, false);
                                // Multipass: false, Log: false
                                File::delete($filepath);
                                $filepath = $toolkit->getLastOutput();
                                $filepath = $filepath[0];
                                unset($toolkit);
                            }
                            $attachments[] = array($filepath, $name, $thumbpath);
                            $uploaded_files[] = $filepath;
                        } catch (Exception $e) {
                            throw new Exception(__('POST_ADD_ERROR_VIDEO_CONVERT') . $e->getMessage());
                        }
                    }
                }
            }
            // Audios
            if (isset($_FILES['attachment_audio']) && is_array($_FILES['attachment_audio']['name'])) {
                foreach ($_FILES['attachment_audio']['size'] as $size) {
                    if ($size > Config::UPLOAD_MAX_SIZE_AUDIO) {
                        throw new Exception(__('POST_ADD_ERROR_AUDIO_SIZE', array('size' => File::humanReadableSize(Config::UPLOAD_MAX_SIZE_AUDIO))));
                    }
                }
                if ($filepaths = File::upload('attachment_audio')) {
                    foreach ($filepaths as $filepath) {
                        $uploaded_files[] = $filepath;
                    }
                    foreach ($filepaths as $i => $filepath) {
                        if (!preg_match('#\\.mp3$#', $filepath)) {
                            throw new Exception(__('POST_ADD_ERROR_AUDIO_FORMAT'));
                        }
                        $name = isset($_FILES['attachment_audio']['name'][$i]) ? $_FILES['attachment_audio']['name'][$i] : '';
                        $attachments[] = array($filepath, $name);
                    }
                }
            }
            // Files
            if (isset($_FILES['attachment_file']) && is_array($_FILES['attachment_file']['name'])) {
                foreach ($_FILES['attachment_file']['size'] as $size) {
                    if ($size > Config::UPLOAD_MAX_SIZE_FILE) {
                        throw new Exception(__('POST_ADD_ERROR_FILE_SIZE', array('size' => File::humanReadableSize(Config::UPLOAD_MAX_SIZE_FILE))));
                    }
                }
                if ($filepaths = File::upload('attachment_file')) {
                    foreach ($filepaths as $filepath) {
                        $uploaded_files[] = $filepath;
                    }
                    foreach ($filepaths as $i => $filepath) {
                        if (!preg_match('#\\.[a-z0-9]{2,4}$#i', $filepath)) {
                            throw new Exception(__('POST_ADD_ERROR_FILE_FORMAT'));
                        }
                        if (preg_match('#\\.(jpg|png|gif|mp3|flv)$#i', $filepath)) {
                            throw new Exception(__('POST_ADD_ERROR_FILE_FORMAT2'));
                        }
                        $name = isset($_FILES['attachment_file']['name'][$i]) ? $_FILES['attachment_file']['name'][$i] : '';
                        $attachments[] = array($filepath, $name);
                    }
                }
            }
            // Event
            if (isset($_POST['event_title']) && isset($_POST['event_start']) && isset($_POST['event_end'])) {
                // Title
                $event_title = trim($_POST['event_title']);
                if ($event_title == '') {
                    throw new Exception(__('POST_ADD_ERROR_EVENT_NO_TITLE'));
                }
                // Dates
                if (!($event_start = strptime($_POST['event_start'], __('PUBLISH_EVENT_DATE_FORMAT')))) {
                    throw new Exception(__('POST_ADD_ERROR_EVENT_DATE'));
                }
                if (!($event_end = strptime($_POST['event_end'], __('PUBLISH_EVENT_DATE_FORMAT')))) {
                    throw new Exception(__('POST_ADD_ERROR_EVENT_DATE'));
                }
                $event_start = mktime($event_start['tm_hour'], $event_start['tm_min'], 0, $event_start['tm_mon'] + 1, $event_start['tm_mday'], $event_start['tm_year'] + 1900);
                $event_end = mktime($event_end['tm_hour'], $event_end['tm_min'], 0, $event_end['tm_mon'] + 1, $event_end['tm_mday'], $event_end['tm_year'] + 1900);
                if ($event_start > $event_end) {
                    throw new Exception(__('POST_ADD_ERROR_EVENT_DATE_ORDER'));
                }
                $event = array($event_title, $event_start, $event_end);
            } else {
                $event = null;
            }
            // Survey
            if (isset($_POST['survey_question']) && isset($_POST['survey_end']) && isset($_POST['survey_answer']) && is_array($_POST['survey_answer'])) {
                // Question
                $survey_question = trim($_POST['survey_question']);
                if ($survey_question == '') {
                    throw new Exception(__('POST_ADD_ERROR_SURVEY_NO_QUESTION'));
                }
                // Date
                if (!($survey_end = strptime($_POST['survey_end'], __('PUBLISH_EVENT_DATE_FORMAT')))) {
                    throw new Exception(__('POST_ADD_ERROR_SURVEY_DATE'));
                }
                $survey_end = mktime($survey_end['tm_hour'], $survey_end['tm_min'], 0, $survey_end['tm_mon'] + 1, $survey_end['tm_mday'], $survey_end['tm_year'] + 1900);
                // Multiple answers
                $survey_multiple = isset($_POST['survey_multiple']);
                // Answers
                $survey_answers = array();
                foreach ($_POST['survey_answer'] as $survey_answer) {
                    $survey_answer = trim($survey_answer);
                    if ($survey_answer != '') {
                        $survey_answers[] = $survey_answer;
                    }
                }
                if (count($survey_answers) < 2) {
                    throw new Exception(__('POST_ADD_ERROR_SURVEY_ANSWERS'));
                }
                $survey = array($survey_question, $survey_end, $survey_multiple, $survey_answers);
            } else {
                $survey = null;
            }
            // Creation of the post
            $id = $this->model->addPost((int) User_Model::$auth_data['id'], $message, $category, $group, $official, $private);
            // Attach files
            foreach ($attachments as $attachment) {
                $this->model->attachFile($id, $attachment[0], $attachment[1], isset($attachment[2]) ? $attachment[2] : null);
            }
            // Event
            if (isset($event)) {
                $this->model->attachEvent($id, $event[0], $event[1], $event[2]);
            }
            // Survey
            if (isset($survey)) {
                $this->model->attachSurvey($id, $survey[0], $survey[1], $survey[2], $survey[3]);
            }
            $this->addJSCode('
				parent.location = "' . Config::URL_ROOT . Routes::getPage('home') . '";
			');
        } catch (Exception $e) {
            // Delete all uploading files in tmp
            foreach ($uploaded_files as $uploaded_file) {
                File::delete($uploaded_file);
            }
            $this->addJSCode('
				with(parent){
					Post.errorForm(' . json_encode($e->getMessage()) . ');
				}
			');
        }
    }
Exemple #28
0
 public function generateFFMPEG()
 {
     $ff = new ffmpeg_movie($this->path . $this->data['path'] . '/' . $this->data['name']);
     if (!$ff) {
         $this->unknown = true;
         return false;
     }
     $this->info = array('width' => $ff->getFrameWidth(), 'height' => $ff->getFrameHeight(), 'duration' => $ff->getDuration(), 'mime' => $this->mime, 'size' => filesize($this->path . $this->data['path'] . '/' . $this->data['name']));
     if ($ff->getFrameCount() > 20) {
         $frame = $frame = $ff->getFrame(20);
     } else {
         $frame = $frame = $ff->getFrame($ff->getFrameCount() - 1);
     }
     $gd = $frame->toGDImage();
     $this->generateGDimage($gd, 'video');
     $this->updateDB();
 }
Exemple #29
-1
<?php

// Set our source file
$srcFile = "/path/to/clock.avi";
$destFile = "/path/to/clock.flv";
$ffmpegPath = "/path/to/ffmpeg";
$flvtool2Path = "/path/to/flvtool2";
// Create our FFMPEG-PHP class
$ffmpegObj = new ffmpeg_movie($srcFile);
// Save our needed variables
$srcWidth = makeMultipleTwo($ffmpegObj->getFrameWidth());
$srcHeight = makeMultipleTwo($ffmpegObj->getFrameHeight());
$srcFPS = $ffmpegObj->getFrameRate();
$srcAB = intval($ffmpegObj->getAudioBitRate() / 1000);
$srcAR = $ffmpegObj->getAudioSampleRate();
// Call our convert using exec()
exec($ffmpegPath . " -i " . $srcFile . " -ar " . $srcAR . " -ab " . $srcAB . " -f flv -s " . $srcWidth . "x" . $srcHeight . " " . $destFile . " | " . $flvtool2Path . " -U stdin " . $destFile);
// Make multiples function
function makeMultipleTwo($value)
{
    $sType = gettype($value / 2);
    if ($sType == "integer") {
        return $value;
    } else {
        return $value - 1;
    }
}
?>

Exemple #30
-23
function captureVideoPosterImg($movie_file = '')
{
    extension_loaded('ffmpeg');
    $movie_file = 'http://upload.freelabel.net/server/php/files/JXL%20%23CrunkDUpTour%20Promo.mp4';
    // Instantiates the class ffmpeg_movie so we can get the information you want the video
    $movie = new ffmpeg_movie($movie_file);
    // Get The duration of the video in seconds
    echo $Duration = round($movie->getDuration(), 0);
    // Get the number of frames of the video
    $TotalFrames = $movie->getFrameCount();
    // Get the height in pixels Video
    $height = $movie->getFrameHeight();
    // Get the width of the video in pixels
    $width = $movie->getFrameWidth();
    //Receiving the frame from the video and saving
    // Need to create a GD image ffmpeg-php to work on it
    $image = imagecreatetruecolor($width, $height);
    // Create an instance of the frame with the class ffmpeg_frame
    $Frame = new ffmpeg_frame($image);
    // Choose the frame you want to save as jpeg
    $thumbnailOf = (int) round($movie->getFrameCount() / 2.5);
    // Receives the frame
    $frame = $movie->GetFrame($thumbnailOf);
    // Convert to a GD image
    $image = $frame->toGDImage();
    // Save to disk.
    //echo $movie_file.'.jpg';
    imagejpeg($image, $movie_file . '.jpg', 100);
    return $movie_file . '.jpg';
}