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)); }
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; }
// 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); // then add it to the small one $result = $ffmpeg_gif_small->addFrame($ffmpeg_frame_small); if (!$result) { 'There was an error adding frame ' . $i . ' to the gif.<br />'; } } } echo '<strong>Animated Gif of Movie</strong>.<br />'; $result = $ffmpeg_gif->saveNow($tmp_dir); if (!$result) { echo 'It was not possible to save the animated gif for some reason.<br />'; } else { echo 'This is an animated gif extracted from the movie.<br />'; echo '<img src="processed/thumbnails/' . $file_info['filename'] . '-animated.gif" alt="" width="' . $orig_width . '" height="' . $orig_height . '" border="0" /><br /><br />'; } echo '<strong>Cropped and Resized Animated Gif of Movie</strong>.<br />'; $result = $ffmpeg_gif_small->saveNow($tmp_dir);