Azure媒体服务php sdk创建缩略图

时间:2017-06-13 10:19:46

标签: php azure cakephp-3.0 azure-media-services

我正在使用azure媒体服务上传和编码视频。我想在编码期间获取视频的缩略图但总是给出错误。 我的代码在这里

function createThumbnail(MediaServicesRestProxy $restProxy, Asset $asset){
$mediaProcessor = $restProxy->getLatestMediaProcessor('Media Encoder Standard');
echo "Using Media Processor: {$mediaProcessor->getName()} version {$mediaProcessor->getVersion()}".PHP_EOL;
// 2.2 Create the Job; this automatically schedules and runs it
$outputAssetName = 'Encoded '.$asset->getName();
$outputAssetCreationOption = Asset::OPTIONS_NONE;
$taskBody = '<?xml version="1.0" encoding="utf-8"?><taskBody><inputAsset>JobInputAsset(0)</inputAsset><outputAsset assetCreationOptions="'.$outputAssetCreationOption.'" assetName="'.$outputAssetName.'">JobOutputAsset(0)</outputAsset></taskBody>';
$xmlThumbnail = '<?xml version="1.0 encoding="utf-8"?>
            <Thumbnail Size="50%,*" Type="Jpeg" Filename="{OriginalFilename}_{ThumbnailTime}.{DefaultExtension}">
              <Time Value="0:0:0"/>
              <Time Value="0:0:3" Step="0:0:0.25" Stop="0:0:10"/>
            </Thumbnail>';
$task = new Task($taskBody, $mediaProcessor->getId(), TaskOptions::NONE);
$task->setConfiguration($xmlThumbnail);
$job = new Job();
$job->setName('Thumbnail Creation Job');
$job = $restProxy->createJob($job, array($asset), array($task));
echo "Created Job with Id: {$job->getId()}".PHP_EOL;
// 2.3 Check to see if the Job has completed
$result = $restProxy->getJobStatus($job);
$jobStatusMap = array('Queued', 'Scheduled', 'Processing', 'Finished', 'Error', 'Canceled', 'Canceling');
while ($result != Job::STATE_FINISHED && $result != Job::STATE_ERROR && $result != Job::STATE_CANCELED) {
    echo "Job status: {$jobStatusMap[$result]}".PHP_EOL;
    sleep(5);
    $result = $restProxy->getJobStatus($job);
}
if ($result != Job::STATE_FINISHED) {
    echo "The job has finished with a wrong status: {$jobStatusMap[$result]}".PHP_EOL;
    exit(-1);
}
echo "Job Finished!".PHP_EOL;
// 2.4 Get output asset
$outputAssets = $restProxy->getJobOutputMediaAssets($job);
print_r($outputAssets);
$encodedAsset = $outputAssets[0];
echo "Thumbnail Asset encoded: name={$encodedAsset->getName()} id={$encodedAsset->getId()}".PHP_EOL;
return $encodedAsset;
}

我已经从.net代码获取refence来创建缩略图和php视频编码代码,以使用azure创建缩略图 参考链接 Stackoverflow azure java sdk thumbnail example

Using the Azure Media Services Thumbnail Task Preset with the Java SDK

0 个答案:

没有答案