AWS Elemental MediaConvert 中使用AmazonSDK for PHP 版本 3 - Amazon适用于 PHP 的开发工具包
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 Amazon Web Services 服务入门

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

AWS Elemental MediaConvert 中使用AmazonSDK for PHP 版本 3

在本示例中,您使用AmazonSDK for PHP 版本 3 调用 AWS Elemental MediaConvert 并创建转码任务。在开始之前,您需要将输入视频上传到为输入存储预配置的 Amazon S3 存储桶。有关支持的输入视频编解码器和容器的列表,请参阅。支持的输入编码解码器和容器中的AWS Elemental MediaConvert 用户指南.

以下示例演示如何:

  • 在 AWS Elemental MediaConvert 中创建转码任务。CreateJob.

  • 从 AWS Elemental MediaConvert 队列取消转码任务。CancelJob

  • 检索已完成转码任务的 JSON。GetJob

  • 检索最多 20 个最新创建的任务的 JSON 数组。ListJobs

所有示例代码AmazonSDK for PHP 版本 3(位于 GitHub 上).

Credentials

运行示例代码之前,请配置Amazon凭证,如中所述。的凭证AmazonSDK for PHP 版本 3. 然后导入AmazonSDK for PHP,如基本使用模式AmazonSDK for PHP 版本 3.

要访问的客户 MediaConvert,请创建 IAM 角色,该角色使能够访问输入文件以及存储输出文件的 Amazon S3 存储桶。有关详细信息,请参阅。设置 IAM 权限中的AWS Elemental MediaConvert 用户指南.

创建客户端

配置AmazonSDK for PHP 通过使用区域为您的代码创建 MediaConvert 客户端。在本示例中,区域设置为 us-west-2。AWS Elemental MediaConvert 对每个账户使用自定义终端节点,因此,请配置AWS.MediaConvert client class以使用特定于账户的终端节点。要执行此操作,请将终端节点参数设置为特定于您的账户的终端节点

导入

require 'vendor/autoload.php'; use Aws\MediaConvert\MediaConvertClient; use Aws\Exception\AwsException;

示例代码

$mediaConvertClient = new MediaConvertClient([ 'version' => '2017-08-29', 'region' => 'us-east-2', 'profile' => 'default', 'endpoint' => 'ACCOUNT_ENDPOINT' ]);

定义简单的转码任务

创建定义转码任务参数的 JSON。

这些参数有详细说明。您可以使用AWS Elemental MediaConvert 控制台生成 JSON 任务参数,方法是在控制台中选择您的任务设置,然后选择显示任务 JSON(位于底部)的作业部分。本示例说明了简单任务的 JSON。

示例代码

$jobSetting = [ "OutputGroups" => [ [ "Name" => "File Group", "OutputGroupSettings" => [ "Type" => "FILE_GROUP_SETTINGS", "FileGroupSettings" => [ "Destination" => "s3://OUTPUT_BUCKET_NAME/" ] ], "Outputs" => [ [ "VideoDescription" => [ "ScalingBehavior" => "DEFAULT", "TimecodeInsertion" => "DISABLED", "AntiAlias" => "ENABLED", "Sharpness" => 50, "CodecSettings" => [ "Codec" => "H_264", "H264Settings" => [ "InterlaceMode" => "PROGRESSIVE", "NumberReferenceFrames" => 3, "Syntax" => "DEFAULT", "Softness" => 0, "GopClosedCadence" => 1, "GopSize" => 90, "Slices" => 1, "GopBReference" => "DISABLED", "SlowPal" => "DISABLED", "SpatialAdaptiveQuantization" => "ENABLED", "TemporalAdaptiveQuantization" => "ENABLED", "FlickerAdaptiveQuantization" => "DISABLED", "EntropyEncoding" => "CABAC", "Bitrate" => 5000000, "FramerateControl" => "SPECIFIED", "RateControlMode" => "CBR", "CodecProfile" => "MAIN", "Telecine" => "NONE", "MinIInterval" => 0, "AdaptiveQuantization" => "HIGH", "CodecLevel" => "AUTO", "FieldEncoding" => "PAFF", "SceneChangeDetect" => "ENABLED", "QualityTuningLevel" => "SINGLE_PASS", "FramerateConversionAlgorithm" => "DUPLICATE_DROP", "UnregisteredSeiTimecode" => "DISABLED", "GopSizeUnits" => "FRAMES", "ParControl" => "SPECIFIED", "NumberBFramesBetweenReferenceFrames" => 2, "RepeatPps" => "DISABLED", "FramerateNumerator" => 30, "FramerateDenominator" => 1, "ParNumerator" => 1, "ParDenominator" => 1 ] ], "AfdSignaling" => "NONE", "DropFrameTimecode" => "ENABLED", "RespondToAfd" => "NONE", "ColorMetadata" => "INSERT" ], "AudioDescriptions" => [ [ "AudioTypeControl" => "FOLLOW_INPUT", "CodecSettings" => [ "Codec" => "AAC", "AacSettings" => [ "AudioDescriptionBroadcasterMix" => "NORMAL", "RateControlMode" => "CBR", "CodecProfile" => "LC", "CodingMode" => "CODING_MODE_2_0", "RawFormat" => "NONE", "SampleRate" => 48000, "Specification" => "MPEG4", "Bitrate" => 64000 ] ], "LanguageCodeControl" => "FOLLOW_INPUT", "AudioSourceName" => "Audio Selector 1" ] ], "ContainerSettings" => [ "Container" => "MP4", "Mp4Settings" => [ "CslgAtom" => "INCLUDE", "FreeSpaceBox" => "EXCLUDE", "MoovPlacement" => "PROGRESSIVE_DOWNLOAD" ] ], "NameModifier" => "_1" ] ] ] ], "AdAvailOffset" => 0, "Inputs" => [ [ "AudioSelectors" => [ "Audio Selector 1" => [ "Offset" => 0, "DefaultSelection" => "NOT_DEFAULT", "ProgramSelection" => 1, "SelectorType" => "TRACK", "Tracks" => [ 1 ] ] ], "VideoSelector" => [ "ColorSpace" => "FOLLOW" ], "FilterEnable" => "AUTO", "PsiControl" => "USE_PSI", "FilterStrength" => 0, "DeblockFilter" => "DISABLED", "DenoiseFilter" => "DISABLED", "TimecodeSource" => "EMBEDDED", "FileInput" => "s3://INPUT_BUCKET_AND_FILE_NAME" ] ], "TimecodeConfig" => [ "Source" => "EMBEDDED" ] ];

创建任务

在创建任务参数 JSON 后,通过调用 AWS.MediaConvert service object 并传递参数,来调用 createJob 方法。所创建任务的 ID 在响应数据中返回。

示例代码

try { $result = $mediaConvertClient->createJob([ "Role" => "IAM_ROLE_ARN", "Settings" => $jobSetting, //JobSettings structure "Queue" => "JOB_QUEUE_ARN", "UserMetadata" => [ "Customer" => "Amazon" ], ]); } catch (AwsException $e) { // output error message if fails echo $e->getMessage(); echo "\n"; }

检索任务

使用在调用 createjob 时返回的 JobID,您可以获取最近任务的 JSON 格式的详细描述。

示例代码

$mediaConvertClient = new MediaConvertClient([ 'version' => '2017-08-29', 'region' => 'us-east-2', 'profile' => 'default', 'endpoint' => 'ACCOUNT_ENDPOINT' ]); try { $result = $mediaConvertClient->getJob([ 'Id' => 'JOB_ID', ]); } catch (AwsException $e) { // output error message if fails echo $e->getMessage(); echo "\n"; }

取消任务

使用在调用 createjob 时返回的 JobID,您可以取消仍在队列中的任务。您无法取消已开始转码的任务。

示例代码

$mediaConvertClient = new MediaConvertClient([ 'version' => '2017-08-29', 'region' => 'us-east-2', 'profile' => 'default', 'endpoint' => 'ACCOUNT_ENDPOINT' ]); try { $result = $mediaConvertClient->cancelJob([ 'Id' => 'JOB_ID', // REQUIRED The Job ID of the job to be cancelled. ]); } catch (AwsException $e) { // output error message if fails echo $e->getMessage(); echo "\n"; }

列出最近的转码任务

创建包括值的参数 JSON,以指定是按升序还是降序对列表排序,要检查的任务队列的 ARN,以及要包含的任务的状态。这将返回最多 20 个任务。要检索后面的 20 个最近任务,请使用随结果返回的 nextToken 字符串。

示例代码

$mediaConvertClient = new MediaConvertClient([ 'version' => '2017-08-29', 'region' => 'us-east-2', 'profile' => 'default', 'endpoint' => 'ACCOUNT_ENDPOINT' ]); try { $result = $mediaConvertClient->listJobs([ 'MaxResults' => 20, 'Order' => 'ASCENDING', 'Queue' => 'QUEUE_ARN', 'Status' => 'SUBMITTED', // 'NextToken' => '<string>', //OPTIONAL To retrieve the twenty next most recent jobs ]); } catch (AwsException $e) { // output error message if fails echo $e->getMessage(); echo "\n"; }