本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
AWS Elemental MediaConvert 使用 AWS SDK for PHP 版本 3 的示例
AWS Elemental MediaConvert 是一种基于文件的视频转码服务,具有广播级功能。你可以用它来创建用于在互联网上进行广播和 video-on-demand (VOD) 传送的资产。有关更多信息,请参阅 用户指南。AWS Elemental MediaConvert
f PHP API AWS Elemental MediaConvert or 通过AWS.MediaConvert
客户端类公开。有关更多信息,请参阅API参考文献Class: AWS.MediaConvert
中的。
在中创建和管理转码作业 AWS Elemental MediaConvert
在此示例中,您使用 AWS SDK for PHP 版本 3 调用 AWS Elemental MediaConvert 和创建转码作业。在开始之前,您需要将输入视频上传到为输入存储预配置的 Amazon S3 存储桶。有关支持的输入视频编解码器和容器的列表,请参阅 AWS Elemental MediaConvert 用户指南中的支持的输入编解码器和容器。
以下示例演示如何:
的所有示例代码都可以在此 AWS SDK for PHP 处找到 GitHub
凭证
在运行示例代码之前,请配置您的 AWS 证书,如中所述凭证。然后导入 AWS SDK for PHP,如中所述基本用法。
要访问 MediaConvert 客户端,请创建一个IAM角色来 AWS Elemental MediaConvert 访问您的输入文件和存储输出文件的 Amazon S3 存储桶。有关详细信息,请参阅《AWS Elemental MediaConvert 用户指南》中的 “设置IAM权限”。
创建客户端
AWS SDK for PHP 通过创建 MediaConvert 客户端进行配置,其中包含您的代码所在的区域。在本示例中,区域设置为 us-west-2。
导入
require 'vendor/autoload.php'; use Aws\Exception\AwsException; use Aws\MediaConvert\MediaConvertClient;
示例代码
$mediaConvertClient = new MediaConvertClient([ 'version' => '2017-08-29', 'region' => 'us-east-2', 'profile' => 'default' ]);
定义简单的转码任务
创建用于JSON定义转码作业参数的。
这些参数有详细说明。您可以使用AWS Elemental MediaConvert 控制台
示例代码
$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' ]); 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' ]); 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,包括用于指定是按要检查的作业队列对列表进行排DESCENDING序还是按顺序排序ARN的值,以及要包含的作业的状态。ASCENDING这将返回最多 20 个任务。要检索接下来的 20 个任务,请使用与结果一起返回的 nextToken 字符串。
示例代码
$mediaConvertClient = new MediaConvertClient([ 'version' => '2017-08-29', 'region' => 'us-east-2', 'profile' => 'default' ]); 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"; }