$restProxy = ServicesBuilder::getInstance()->createMediaServicesService(new MediaServicesSettings($account, $secret)); // 1 - Upload the mezzanine $sourceAsset = uploadFileAndCreateAsset($restProxy, $mezzanineFileName); // 2 - encode the output asset $encodedAsset = encodeToAdaptiveBitrateMP4Set($restProxy, $sourceAsset); // 3 - Create Content Key $contentKey = createEnvelopeTypeContentKey($restProxy, $encodedAsset); // 4 - Create the ContentKey Authorization Policy $tokenTemplateString = null; if ($tokenRestriction) { $tokenTemplateString = addTokenRestrictedAuthorizationPolicy($restProxy, $contentKey, $tokenType); } else { addOpenAuthorizationPolicy($restProxy, $contentKey); } // 5 - Create the AssetDeliveryPolicy createAssetDeliveryPolicy($restProxy, $encodedAsset, $contentKey); // 6 - Publish publishEncodedAsset($restProxy, $encodedAsset); // 7 - Generate Test Token if ($tokenRestriction) { generateTestToken($tokenTemplateString, $contentKey); } // Done print "Done!"; //////////////////// // Helper methods // //////////////////// function uploadFileAndCreateAsset($restProxy, $mezzanineFileName) { // 1.1. create an empty "Asset" by specifying the name $asset = new Asset(Asset::OPTIONS_NONE);
$restProxy = ServicesBuilder::getInstance()->createMediaServicesService(new MediaServicesSettings($account, $secret)); // 1 - Upload the mezzanine $sourceAsset = uploadFileAndCreateAsset($restProxy, $mezzanineFileName); // 2 - encode the output asset $encodedAsset = encodeToAdaptiveBitrateMP4Set($restProxy, $sourceAsset); // 3 - Create Content Key $contentKey = createCommonCBCTypeContentKey($restProxy, $encodedAsset); // 4 - Create the ContentKey Authorization Policy $tokenTemplateString = null; if ($tokenRestriction) { $tokenTemplateString = addTokenRestrictedAuthorizationPolicy($restProxy, $contentKey, $tokenType, $fairPlayASK, $fairPlayPFXPassword, $fairPlayPFXFile, $fairPlayIV); } else { addOpenAuthorizationPolicy($restProxy, $contentKey, $fairPlayASK, $fairPlayPFXPassword, $fairPlayPFXFile, $fairPlayIV); } // 5 - Create the AssetDeliveryPolicy createAssetDeliveryPolicy($restProxy, $encodedAsset, $contentKey, $fairPlayIV); // 6 - Publish publishEncodedAsset($restProxy, $encodedAsset); // 7 - Generate Test Token if ($tokenRestriction) { generateTestToken($tokenTemplateString, $contentKey); } // Done echo "Done!"; //////////////////// // Helper methods // //////////////////// function uploadFileAndCreateAsset($restProxy, $mezzanineFileName) { // 1.1. create an empty "Asset" by specifying the name $asset = new Asset(Asset::OPTIONS_NONE);
function applyAesDynamicEncryption($restProxy, $asset, $options) { $testToken = null; // 1 - Create Content Key $contentKey = createEnvelopeTypeContentKey($restProxy, $asset); // 2 - Create the ContentKey Authorization Policy and Options if ($options->tokenRestriction) { // 2.1 - Apply Token restriction $template = addTokenRestrictedAuthorizationPolicy($restProxy, $contentKey, $options->tokenType); // 2.2 - Generate Test Token $testToken = generateTestToken($template, $contentKey); } else { // 2.1 - Apply Open restriction addOpenAuthorizationPolicy($restProxy, $contentKey); } // 3 - Create the AssetDeliveryPolicy createAssetDeliveryPolicy($restProxy, $asset, $contentKey); return $testToken; }