Example #1
0
 /**
  * will fetch the best set of conversion params that fit this profile
  * the link is done using 2 fields -  conv_profile->profileType &  conv_profile->profileTypeSuffix
  *  matched agains conv_params->profileType 
  * 'parnter_id' - the partner of the profile
  * search for the params 
  * 1 - for this partner_id by conv_profile->profileType . conv_profile->profileTypeSuffix ( a simple concatenation with no separator )
  * if none found
  * 2 - for this partner_id by conv_profile->profileType 
  * if none found 
  * 3 - for global partner by conv_profile->profileType . conv_profile->profileTypeSuffix
  * if none found
  * 4 - for global partner by conv_profile->profileType 
  * if none found 
  * 5- default of the system - always exists
  *
  * fallback_mode will hold the number of the method chosen 
  * 
  * TODO - optimize the fetchng of the params to 1 call for all of the 4 first options - fetch once and sort in the application
  * for now it's good enough 
  * @param ConversionProfile $conv_profile
  * @return unknown
  */
 public static function retrieveByConversionProfile(ConversionProfile $conv_profile, &$fallback_mode = null, $display_disabled = false)
 {
     // ASSUME - $conv_profile is not null
     $partner_id = $conv_profile->getPartnerId();
     // #1
     list($conversion_params_list, $fallback_mode) = self::retrieveByPartnerAndPrifileTypeImpl(1, $partner_id, $conv_profile->getProfileType() . $conv_profile->getProfileTypeSuffix(), $display_disabled);
     if (count($conversion_params_list)) {
         return $conversion_params_list;
     }
     // #2 - ignore the  getProfileTypeSuffix . if it does not exist , ignoring it is the same as #1
     if ($conv_profile->getProfileTypeSuffix()) {
         list($conversion_params_list, $fallback_mode) = self::retrieveByPartnerAndPrifileTypeImpl(2, $partner_id, $conv_profile->getProfileType(), $display_disabled);
         if (count($conversion_params_list)) {
             return $conversion_params_list;
         }
     }
     // nothing for the partner - go for ConversionProfile::GLOBAL_PARTNER_PROFILE
     // #3
     list($conversion_params_list, $fallback_mode) = self::retrieveByPartnerAndPrifileTypeImpl(3, ConversionProfile::GLOBAL_PARTNER_PROFILE, $conv_profile->getProfileType() . $conv_profile->getProfileTypeSuffix(), $display_disabled);
     if (count($conversion_params_list)) {
         return $conversion_params_list;
     }
     // #4 - ignore the  getProfileTypeSuffix . if it does not exist , ignoring it is the same as #1
     if ($conv_profile->getProfileTypeSuffix()) {
         list($conversion_params_list, $fallback_mode) = self::retrieveByPartnerAndPrifileTypeImpl(4, ConversionProfile::GLOBAL_PARTNER_PROFILE, $conv_profile->getProfileType(), $display_disabled);
         if (count($conversion_params_list)) {
             return $conversion_params_list;
         }
     }
     // #5 - the  system default - MUST always exist in the system
     list($conversion_params_list, $fallback_mode) = self::retrieveByPartnerAndPrifileTypeImpl(5, ConversionProfile::GLOBAL_PARTNER_PROFILE, ConversionProfile::DEFAULT_COVERSION_PROFILE_TYPE, $display_disabled);
     return $conversion_params_list;
 }
 /**
  * Will return for each OLD ConversionProfile a new one, IF NEEDED.
  * The old conversionProfile will hold a reference to the new one, so if already created a new one, it will be re-used.
  * All the necessary flavorParams will be added too to fit the old conversion params.
  *  
  * @param ConversionProfile $conversion_profile
  * @return conversionProfile2
  */
 public static function createConversionProfile2FromConversionProfile(ConversionProfile $old_conversion_profile)
 {
     if (!$old_conversion_profile) {
         throw new Exception("Cannot create new conversionProfile2 for null");
     }
     if ($old_conversion_profile->getConversionProfile2Id()) {
         $new_profile = conversionProfile2Peer::retrieveByPK($old_conversion_profile->getConversionProfile2Id());
         if ($new_profile) {
             // found a valid new profile - return it
             return $new_profile;
         }
     }
     // whether there was no id or no profile - create on now and set it to be the conversionProfile2Id
     $new_profile = new conversionProfile2();
     $new_profile->setPartnerId($old_conversion_profile->getPartnerId());
     $new_name = $old_conversion_profile->getName();
     $new_name = $new_name ? $new_name : "From [{$old_conversion_profile->getId()}]";
     $new_profile->setName($new_name . " " . $old_conversion_profile->getProfileType());
     if ($old_conversion_profile->getBypassFlv()) {
         $new_profile->setCreationMode(conversionProfile2::CONVERSION_PROFILE_2_CREATION_MODE_AUTOMATIC_BYPASS_FLV);
         $map = flavorParams::TAG_WEB . "," . flavorParams::TAG_MBR;
     } else {
         $new_profile->setCreationMode(conversionProfile2::CONVERSION_PROFILE_2_CREATION_MODE_AUTOMATIC);
         $map = flavorParams::TAG_WEB;
     }
     $new_profile->setInputTagsMap($map);
     // use the OLD code to simulate what was performed on the old_conversion_profile to retrieve the old_conversion_params list
     $conv_client = new kConversionClientBase("", "", "", "");
     $old_conversion_command = $conv_client->createConversionCommandFromConverionProfile("src", "target", $old_conversion_profile);
     $description = '';
     foreach ($old_conversion_command->conversion_params_list as $old_conversion_params) {
         // use the helper utility to fill the gaps
         $desc = '';
         self::fixDimensionsByAspectRatio($old_conversion_params, $desc);
         $description .= $desc;
     }
     $new_profile->setDescription($description);
     $new_profile->save();
     // at this point - the all $old_conversion_params are filled with the values used by the old conversion servers
     // transform from old to new ...
     // create the flavorParams and the flavorParamsConversionParams table
     foreach ($old_conversion_command->conversion_params_list as $old_conversion_params) {
         $new_flavor_params = new flavorParams();
         // set all the properties for the new flavor_params
         $new_flavor_params->setPartnerId($old_conversion_profile->getPartnerId());
         $new_flavor_params->setCreationMode(flavorParams::FLAVOR_PARAMS_CREATION_MODE_AUTOMATIC);
         $audio_bitrate = $old_conversion_params->audio_bitrate;
         if (!$audio_bitrate) {
             $audio_bitrate = 96;
         }
         // if empty - hard-code 96
         $new_flavor_params->setAudioBitrate($audio_bitrate);
         // default
         $new_flavor_params->setAudioChannels(0);
         // default
         $new_flavor_params->setAudioResolution(0);
         $new_flavor_params->setAudioSampleRate(0);
         if ($old_conversion_profile->getCommercialTranscoder()) {
             // first comes ON2...
             $new_flavor_params->setConversionEngines(conversionEngineType::ON2 . "," . conversionEngineType::ENCODING_COM . "," . conversionEngineType::FFMPEG . "," . conversionEngineType::FFMPEG_AUX . "," . conversionEngineType::MENCODER);
             //
             $new_flavor_params->setConversionEnginesExtraParams($old_conversion_params->flix_params . "|" . $old_conversion_params->flix_params . "|" . $old_conversion_params->ffmpeg_params . "|" . $old_conversion_params->ffmpeg_params . "|" . $old_conversion_params->mencoder_params);
         } else {
             // first comes ffmpeg ...
             $new_flavor_params->setConversionEngines(conversionEngineType::FFMPEG . "," . conversionEngineType::FFMPEG_AUX . "," . conversionEngineType::MENCODER . "," . conversionEngineType::ON2 . "," . conversionEngineType::ENCODING_COM, ",");
             //
             $new_flavor_params->setConversionEnginesExtraParams($old_conversion_params->ffmpeg_params . "|" . $old_conversion_params->ffmpeg_params . "|" . $old_conversion_params->mencoder_params . "|" . $old_conversion_params->flix_params . "|" . $old_conversion_params->flix_params);
         }
         $target_format = "flv";
         // this code will always be called for flv files
         // the format can be flv | mp4 | mov | avi | mp3
         // IMPORTANT:
         // except for the FLV videos, none of the formats should be assumed WEB - they are not supposed to be played using our player at first stage.
         switch ($target_format) {
             case "mp3":
                 $new_flavor_params->setFormat("flv");
                 $new_flavor_params->setAudioCodec(flavorParams::AUDIO_CODEC_MP3);
                 // set default mp3
                 $new_flavor_params->setVideoCodec(flavorParams::VIDEO_CODEC_VP6);
                 /* $new_flavor_params->setTags ( flavorParams::TAG_WEB ); */
                 break;
             case "mp4":
                 $new_flavor_params->setFormat($target_format);
                 $new_flavor_params->setAudioCodec(flavorParams::AUDIO_CODEC_AAC);
                 $new_flavor_params->setVideoCodec(flavorParams::VIDEO_CODEC_H264);
                 $new_flavor_params->setTags(',mp4_export');
                 break;
             case "mov":
                 $new_flavor_params->setFormat($target_format);
                 $new_flavor_params->setAudioCodec(flavorParams::AUDIO_CODEC_AAC);
                 $new_flavor_params->setVideoCodec(flavorParams::VIDEO_CODEC_H264);
                 $new_flavor_params->setTags('mov_export');
                 break;
             case "avi":
                 $new_flavor_params->setFormat($target_format);
                 $new_flavor_params->setAudioCodec(flavorParams::AUDIO_CODEC_MP3);
                 $new_flavor_params->setVideoCodec(flavorParams::VIDEO_CODEC_H264);
                 $new_flavor_params->setTags('avi_export');
                 break;
             case "flv":
                 $new_flavor_params->setFormat($target_format);
                 $new_flavor_params->setAudioCodec(flavorParams::AUDIO_CODEC_MP3);
                 $new_flavor_params->setVideoCodec(flavorParams::VIDEO_CODEC_VP6);
                 $new_flavor_params->setTags(flavorParams::TAG_WEB . "," . flavorParams::TAG_MBR);
                 break;
         }
         $new_flavor_params->setName($new_name);
         $new_flavor_params->setFrameRate(0);
         // DONT set the framerate $old_conversion_params->framerate );
         if ($old_conversion_params->gop_size == 5) {
             $new_flavor_params->setGopSize(5);
             $new_flavor_params->removeTag(flavorParams::TAG_MBR);
             $new_flavor_params->addTag(flavorParams::TAG_EDIT);
         } else {
             $new_flavor_params->setGopSize(0);
             // 0 will automatically allow default gopsize
         }
         $new_flavor_params->setWidth($old_conversion_params->width);
         $new_flavor_params->setHeight($old_conversion_params->height);
         $new_flavor_params->setVersion(1);
         $new_flavor_params->setReadyBehavior(flavorParamsConversionProfile::READY_BEHAVIOR_OPTIONAL);
         $new_flavor_params->setVideoBitrate($old_conversion_params->bitrate ? $old_conversion_params->bitrate : "");
         // TODO - fill the rest ...
         $new_flavor_params->save();
         // add to the 1-to-many table
         $flavor_params_conversion_profile = new flavorParamsConversionProfile();
         $flavor_params_conversion_profile->setConversionProfileId($new_profile->getId());
         $flavor_params_conversion_profile->setFlavorParamsId($new_flavor_params->getId());
         $flavor_params_conversion_profile->setReadyBehavior($new_flavor_params->getReadyBehavior());
         $flavor_params_conversion_profile->save();
     }
     // always add to the *source* flavotParams to the 1-to-many table
     $flavor_params_conversion_profile = new flavorParamsConversionProfile();
     $flavor_params_conversion_profile->setConversionProfileId($new_profile->getId());
     $flavor_params_conversion_profile->setFlavorParamsId(flavorParams::SOURCE_FLAVOR_ID);
     $flavor_params_conversion_profile->save();
     // point to the new profile and save the old one
     $old_conversion_profile->setConversionProfile2Id($new_profile->getId());
     $old_conversion_profile->save();
     return $new_profile;
 }
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      ConversionProfile $value A ConversionProfile object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(ConversionProfile $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      ConversionProfile $value A ConversionProfile object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(ConversionProfile $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         if (isset(self::$instances[$key]) || count(self::$instances) < kConf::get('max_num_instances_in_pool')) {
             self::$instances[$key] = $obj;
             kMemoryManager::registerPeer('ConversionProfilePeer');
         }
     }
 }