Пример #1
0
/**
 * Trigger the video conversion
 */
function video_conversion_cron($hook, $entity_type, $returnvalue, $params)
{
    $ia = elgg_set_ignore_access(true);
    $videos = elgg_get_entities_from_metadata(array('type' => 'object', 'subtype' => 'video', 'limit' => 2, 'metadata_name_value_pairs' => array('name' => 'conversion_done', 'value' => 0)));
    elgg_load_library('elgg:video');
    foreach ($videos as $video) {
        $sources = $video->getSources();
        $success = true;
        foreach ($sources as $source) {
            // Converted sources may exist if previous conversion has been interrupted
            if ($source->conversion_done == true) {
                continue;
            }
            try {
                $filename = $source->getFilenameOnFilestore();
                // Create a new video file to data directory
                $converter = new VideoConverter();
                $converter->setInputFile($video->getFilenameOnFilestore());
                $converter->setOutputFile($filename);
                $converter->setResolution($source->resolution);
                $converter->setBitrate($source->bitrate);
                $result = $converter->convert();
                // Save video details
                $info = new VideoInfo($source);
                $source->resolution = $info->getResolution();
                $source->bitrate = $info->getBitrate();
                $source->conversion_done = true;
                $source->save();
                echo "<p>Successfully created video file {$source->getFilename()}</p>";
            } catch (Exception $e) {
                // Print simple error to screen
                echo "<p>Failed to create video file {$source->getFilename()}</p>";
                $success = false;
                // Print detailed error to error log
                $message = elgg_echo('VideoException:ConversionFailed', array($filename, $e->getMessage(), $converter->getCommand()));
                error_log($message);
                elgg_add_admin_notice('conversion_error', $message);
            }
        }
        if ($success) {
            $video->conversion_done = true;
            add_to_river('river/object/video/create', 'create', $video->getOwnerGUID(), $video->getGUID());
        }
    }
    elgg_set_ignore_access($ia);
    return $returnvalue;
}
Пример #2
0
    $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;
        $video->save();
        $video->setSources();
        video_create_thumbnails($video);
        $message = elgg_echo("video:saved");
        system_message($message);
    } else {
        // failed to save video object - nothing we can do about this
        $error = elgg_echo("video:uploadfailed");
        register_error($error);
    }
    $container = get_entity($container_guid);