예제 #1
0
/**
 * Make thumbnails of given video position. Defaults to beginning of video.
 *
 * @param Video $video    The video object
 * @param int   $position Video position
 */
function video_create_thumbnails($video, $position = 0)
{
    $icon_sizes = elgg_get_config('icon_sizes');
    $square = elgg_get_plugin_setting('square_icons', 'video');
    // Default to square thumbnail images
    if (is_null($square)) {
        $square = true;
    }
    $square = $square == 1 ? true : false;
    $dir = $video->getFileDirectory();
    $guid = $video->getGUID();
    // Use default thumbnail as master
    $imagepath = "{$dir}/icon-master.jpg";
    try {
        $thumbnailer = new VideoThumbnailer();
        $thumbnailer->setInputFile($video->getFilenameOnFilestore());
        $thumbnailer->setOutputFile($imagepath);
        $thumbnailer->setPosition($position);
        $thumbnailer->execute();
    } catch (exception $e) {
        $msg = elgg_echo('VideoException:ThumbnailCreationFailed', array($video->getFilenameOnFilestore(), $e->getMessage(), $thumbnailer->getCommand()));
        error_log($msg);
        elgg_add_admin_notice('video_thumbnailing_error', $msg);
        return false;
    }
    $files = array();
    // Create the thumbnails
    foreach ($icon_sizes as $name => $size_info) {
        // We have already created master image
        if ($name == 'master') {
            continue;
        }
        $resized = get_resized_image_from_existing_file($imagepath, $size_info['w'], $size_info['h'], $square);
        if ($resized) {
            $file = new ElggFile();
            $file->owner_guid = $video->owner_guid;
            $file->container_guid = $guid;
            $file->setFilename("video/{$guid}/icon-{$name}.jpg");
            $file->open('write');
            $file->write($resized);
            $file->close();
            $files[] = $file;
        } else {
            error_log("ERROR: Failed to create thumbnail '{$name}' for video {$video->getFilenameOnFilestore()}.");
            // Delete all images if one fails
            foreach ($files as $file) {
                $file->delete();
            }
            return false;
        }
    }
    $video->icontime = time();
    return true;
}
예제 #2
0
        // user blanked title, but we need one
        $title = $video->title;
    }
}
$video->title = $title;
$video->description = $desc;
$video->access_id = $access_id;
$video->container_guid = $container_guid;
$tags = explode(",", $tags);
$video->tags = $tags;
// Save the entity to push attributes to database
// and to get access to guid if adding a new video
$video->save();
// we have a video upload, so process it
if (isset($_FILES['upload']['name']) && !empty($_FILES['upload']['name'])) {
    $prefix = "video/{$video->getGUID()}/";
    // if previous video, delete it
    if ($new_video == false) {
        $videoname = $video->getFilenameOnFilestore();
        if (file_exists($videoname)) {
            unlink($videoname);
        }
        // use same videoname on the disk - ensures thumbnails are overwritten
        $videostorename = $video->getFilename();
        $videostorename = elgg_substr($videostorename, elgg_strlen($prefix));
    } else {
        $videostorename = elgg_strtolower($_FILES['upload']['name']);
    }
    $video->setFilename($prefix . $videostorename);
    $mime_type = ElggFile::detectMimeType($_FILES['upload']['tmp_name'], $_FILES['upload']['type']);
    $video->setMimeType($mime_type);