コード例 #1
0
ファイル: video.php プロジェクト: juho-jaakkola/elgg-videos
/**
 * 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
ファイル: upload.php プロジェクト: juho-jaakkola/elgg-videos
        $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);
    $video->originalvideoname = $_FILES['upload']['name'];
    $video->simpletype = 'video';
    // Open the video to guarantee the directory exists
    $video->open("write");
    $video->close();
    move_uploaded_file($_FILES['upload']['tmp_name'], $video->getFilenameOnFilestore());
    // Change the directory mode
    chmod($video->getFileDirectory(), 0775);
    $guid = $video->save();
}
// video saved so clear sticky form
elgg_clear_sticky_form('video');
// handle results differently for new videos and video updates
if ($new_video) {
    if ($guid) {
        elgg_load_library('elgg:video');
        // Find out file info and save it as metadata
        $info = new VideoInfo($video);
        $video->resolution = $info->getResolution();
        $video->bitrate = $info->getBitrate();
        $video->duration = $info->getDuration();
        // Mark the video as unconverted so conversion script can find it
        $video->conversion_done = false;