$resolution = $video->resolution;
}
// See if a source with the same format and resolution already exists
$existing = elgg_get_entities_from_metadata(array('type' => 'object', 'subtype' => 'video_source', 'container_guid' => $video->getGUID(), 'metadata_name_value_pairs' => array('format' => $format, 'resolution' => $resolution)));
if (!empty($existing)) {
    // Reconvert an existing source
    $source = $existing[0];
    $outputfile = $source->getFilenameOnFilestore();
} else {
    $basename = $video->getFilenameWithoutExtension();
    $filename = "video/{$video->getGUID()}/{$basename}_{$resolution}.{$format}";
    // Create a new entity that represents the physical file
    $source = new VideoSource();
    $source->format = $format;
    $source->setFilename($filename);
    $source->setMimeType("video/{$format}");
    $source->resolution = $resolution;
    $source->bitrate = $bitrate;
    $source->owner_guid = $video->getOwnerGUID();
    $source->container_guid = $video->getGUID();
    $source->access_id = $video->access_id;
    $source->save();
}
try {
    $converter = new VideoConverter();
    $converter->setInputfile($video->getFilenameOnFilestore());
    $converter->setOutputfile($source->getFilenameOnFilestore());
    $converter->setResolution($resolution);
    $converter->setBitrate($bitrate);
    $converter->convert();
    $source->conversion_done = true;
Exemple #2
0
 /**
  * Create different video sources based on plugin configuration
  */
 public function setSources()
 {
     $flavors = video_get_flavor_settings();
     foreach ($flavors as $flavor) {
         $source = new VideoSource();
         $source->container_guid = $this->getGUID();
         $source->owner_guid = $this->getOwnerGUID();
         $source->access_id = $this->access_id;
         $source->conversion_done = false;
         if (empty($flavor['resolution'])) {
             $source->resolution = null;
             // Use resolution of the parent in the filename
             $resolution = $this->resolution;
         } else {
             $source->resolution = $flavor['resolution'];
             $resolution = $source->resolution;
         }
         if (empty($flavor['bitrate'])) {
             $source->bitrate = null;
         } else {
             $source->bitrate = $flavor['bitrate'];
         }
         $source->format = $flavor['format'];
         $basename = $this->getFilenameWithoutExtension();
         $filename = "video/{$this->getGUID()}/{$basename}_{$resolution}.{$source->format}";
         $source->setFilename($filename);
         $source->setMimeType("video/{$source->format}");
         $source->save();
     }
 }