function generateThumb()
 {
     global $tikilib;
     if (!class_exists('ffmpeg_movie')) {
         return;
     }
     $movie = new ffmpeg_movie($this->fullPath(), 0);
     if (!is_object($movie)) {
         return;
     }
     $width = $movie->getFrameWidth();
     if (!$width) {
         $width = 100;
     }
     $height = $movie->getFrameHeight();
     if (!$height) {
         $height = 100;
     }
     $frameTotal = $movie->getFrameCount();
     if (!$frameTotal) {
         return;
     }
     $thumbSide = $tikilib->get_preference('el_thumb_side', 100);
     $thumbVideoSize = $tikilib->get_preference('el_thumb_video_size', 10);
     $rate = (int) ($frameTotal / $thumbVideoSize);
     $percent = $width > $height ? $thumbSide / $width : $thumbSide / $height;
     $width = (int) ($percent * $width);
     $height = (int) ($percent * $height);
     if ($width % 2 != 0) {
         $width++;
     }
     if ($height % 2 != 0) {
         $height++;
     }
     $thumbName = 'thumb_' . preg_replace("/^.*\\//", "", $this->fileName);
     $thumbName = preg_replace('/\\.(.+?)$/', '.gif', $thumbName);
     $gif = new ffmpeg_animated_gif($this->baseDir . $thumbName, $width, $height, 1, 0);
     for ($i = 1; $i <= $frameTotal; $i += $rate) {
         $gif->addFrame($movie->getFrame($i));
     }
     return $this->update(array('thumbnail' => $thumbName));
 }
Beispiel #2
0
 function create_thumb_video($path)
 {
     if (!class_exists('ffmpeg_movie')) {
         return false;
     }
     //first, get movie and gif info
     $movie = new ffmpeg_movie($path, 0);
     //if error, return false
     if (!is_object($movie)) {
         return false;
     }
     $width = $movie->getFrameWidth();
     $height = $movie->getFrameHeight();
     $frameTotal = $movie->getFrameCount();
     $thumbSide = $this->get_preference('el_thumb_side', 100);
     $thumbVideoSize = $this->get_preference('el_thumb_video_size', 10);
     $rate = (int) ($frameTotal / $thumbVideoSize);
     $percent = $width > $height ? $thumbSide / $width : $thumbSide / $height;
     $width = (int) ($percent * $width);
     $height = (int) ($percent * $height);
     if ($width % 2 != 0) {
         $width++;
     }
     if ($height % 2 != 0) {
         $height++;
     }
     $gif = new ffmpeg_animated_gif("/tmp/el-thumb.gif", $width, $height, 1, 0);
     for ($i = 1; $i <= $frameTotal; $i += $rate) {
         $gif->addFrame($movie->getFrame($i));
     }
     $fp = fopen("/tmp/el-thumb.gif", 'rb');
     $data = '';
     while (!feof($fp)) {
         $data .= fread($fp, 8192 * 16);
     }
     global $tikilib;
     $tikilib->blob_encode($data);
     fclose($fp);
     return $data;
 }
Beispiel #3
0
echo 'This is a frame grab that has been cropped.<br />';
echo '<img src="processed/thumbnails/' . $file_info['filename'] . '-cropped.jpg" alt="" width="' . $frame->getWidth() . '" height="' . $frame->getHeight() . '" border="0" /><br /><br />';
// 	resize the thumbnail
$frame->resize(50, 50);
$gd_resource = $frame->toGDImage();
imagejpeg($gd_resource, PHPVIDEOTOOLKIT_EXAMPLE_ABSOLUTE_BATH . 'processed/thumbnails/' . $file_info['filename'] . '-resized.jpg', 80);
$small_width = $frame->getWidth();
$small_height = $frame->getHeight();
echo '<strong>Cropped and Resized Frame Grab of Movie</strong>.<br />';
echo 'This is a frame grab that has been cropped then resized.<br />';
echo '<img src="processed/thumbnails/' . $file_info['filename'] . '-resized.jpg" alt="" width="' . $small_width . '" height="' . $small_height . '" border="0" /><br /><br />';
// 	create 2 animated gifs, one normal size, one small
// 	create the normal one
$ffmpeg_gif = new ffmpeg_animated_gif(PHPVIDEOTOOLKIT_EXAMPLE_ABSOLUTE_BATH . 'processed/thumbnails/' . $file_info['filename'] . '-animated.gif', $orig_width, $orig_height, 5, 0);
// 	create the small one
$ffmpeg_gif_small = new ffmpeg_animated_gif(PHPVIDEOTOOLKIT_EXAMPLE_ABSOLUTE_BATH . 'processed/thumbnails/' . $file_info['filename'] . '-animated-small.gif', $small_width, $small_height, 5, 0);
for ($i = 1, $a = $ffmpeg_movie->getFrameCount(), $inc = $ffmpeg_movie->getFrameRate() / 2; $i < $a; $i += $inc) {
    // 		get the required frame
    $ffmpeg_frame = $ffmpeg_movie->getFrame($i);
    if ($ffmpeg_frame !== false) {
        // 			add the frame to the gif
        $result = $ffmpeg_gif->addFrame($ffmpeg_frame);
        if (!$result) {
            'There was an error adding frame ' . $i . ' to the gif.<br />';
        }
    }
    // 		get the required frame
    $ffmpeg_frame_small = $ffmpeg_movie->getFrame($i);
    if ($ffmpeg_frame_small !== false) {
        // 			crop and resize the frame
        $ffmpeg_frame_small->resize(50, 50, 20, 20, 20, 20);