Re-encoding existing video.

2 replies [Last post]
Joined: 08/16/2011
Points: 6

Hi, I am running Kaltura CE 4.0 and was wondering if it is possible to batch re-encode existing video into new formats after it has been uploaded. For example if I uploaded several hundred videos for a client then later the client asks for them to be made available at a smaller size than was previously encoded.

Joined: 01/11/2011
Points: 24

If you had tick to save the source (original video) in "setting","Transcoding Settings", tick the transcoding flavor you need and clcik "Save changes".

Then back to "Content","Manage" click on the video you need in "Flavors", press "convert" to do it.

If you have not save the video in Kalutra sorry you cannot do so.

Joined: 05/13/2009
Points: 164

there's something wrong with the following script: it will duplicate your originally uploaded files, I haven't had time to fix that, and in general it works...

The way to use it is to change your default transcoding profile to include the revised flavors in the client's account. Then you run the script, and it'll find out your default transcoding profiles and check to make sure that all videos in the account are transcoded to all the new default transcode flavors--if a video is missin one of the defaults, it'll queue up a transcode for each of the missing flavors.

this script assumes a file called k-settings.php exists in the same directory and contains your credentials:

<?php

//define constants
define("KALTURA_PARTNER_ID", 0000000);
define("KALTURA_PARTNER_USER", "papyromancer");
define("KALTURA_PARTNER_WEB_SERVICE_SECRET", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
define("KALTURA_PARTNER_WEB_SERVICE_ADMIN_SECRET", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
define("KALTURA_SERVICE_URL", "http://www.kaltura.com");

?>

Please keep in mind that this script is highly experimental:

<?php

require_once("kaltura-php5-client/KalturaClient.php");

//define constants
require_once("k-settings.php");

//construct Kaltura objects for session initiation
$config           = new KalturaConfiguration(KALTURA_PARTNER_ID);
$config->serviceUrl = KALTURA_SERVICE_URL;
$client           = new KalturaClient($config);
//print_r($client);
$ks               = $client->session->start(KALTURA_PARTNER_WEB_SERVICE_ADMIN_SECRET, KALTURA_PARTNER_USER, KalturaSessionType::ADMIN, KALTURA_PARTNER_ID);
if (!isset($ks)) {
  die("Could not establish Kaltura session. Please verify that you are using valid Kaltura partner credentials.");
}
$client->setKs($ks);  // set the session in the client

$filter = null; //new KalturaFlavorParamFilter();
$pager = null; //new KalturaFilterPager();

print( "Finding your Default Profile...\n" );
$profiles = $client->conversionProfile->listAction($filter, $pager);
foreach ( $profiles->objects as $profile )
{
        if ( $profile->isDefault == 1 )
        {
                $flavors = explode( ",", $profile->flavorParamsIds);
        }
}
if ( !$flavors )
{
        die( "Could not find default conversion profile" );
}
print( "\nWe will be transcoding your videos into these formats:\n" );
foreach ($flavors as $flavor)
{
        $result = $client->flavorParams->get($flavor);
        print($result->id."\t".$result->format."\t".$result->name."\n");
}
print("\nIs this Acceptable? (y/n)\n");
$confirmation  =  trim( fgets( STDIN ) );
if ( $confirmation !== 'y' )
{
        print("Exiting.");
        exit (0);
}
$filter = new KalturaMediaEntryFilter();
$filter->statusEqual = KalturaEntryStatus::READY;
$filter->mediaTypeEqual = KalturaMediaType::VIDEO;
$pager = new KalturaFilterPager();
$pager->pageSize = 500;
$pager->pageIndex = 1;
$all_videos = $client->media->listAction($filter, $pager); // list all of the media items in the partner
class Transcode {
  public function __set($key, $value) {
    $this->$key = $value;
  }
}
foreach( $all_videos->objects as $video)
{
        $transcode = new Transcode();
        $transcode->entry = $video;
        $has_flavors = explode( ",", $video->flavorParamsIds );
        foreach( $flavors as $flavor )
        {
                if ( in_array($flavor, $has_flavors, true) == false )
                {
                        $transcode->needs_flavor[] = $flavor;
                }
        }
        if ( $transcode->needs_flavor )
        {
                $transcodes[] = $transcode;
        }
}
print( "\n".count($all_videos->objects)."\tTotal Videos\n");
print( count($transcodes)."\tNeed Transcodes\n\n");
foreach( $transcodes as $transcode )
{
        print( $transcode->entry->name."\n" );
        print( "\tSubmitting: ");
        foreach ( $transcode->needs_flavor as $flavor )
        {
                print($flavor." ");
                try {
                        $client->flavorAsset->convert($transcode->entry->id, $flavor);
                }
                catch (Exception $e)
                {
                        echo 'Exception caught: ',  $e->getMessage(), "\n";
                }
        }
        print("\n\n");
}

#echo(json_encode($results->flavorParamsIds));

// $flavors = $client->flavorparams->add($webM);

//echo json_encode($results);

//echo( json_encode($results) );

//$results = $client->session->end();:w
//
?>