【问题标题】:How do I create a PHP function to create this JSON request to the AWS (create job)如何创建 PHP 函数来创建对 AWS 的 JSON 请求(创建作业)
【发布时间】:2013-12-16 18:00:38
【问题描述】:

AWS 上有一项名为 Elastic Transcoder 的新服务。我知道一些 PHP,但我已经咬了比我能咀嚼的更多...

我将如何创建一个简单的 PHP 函数,该函数将获取我的变量并创建一个 JSON 请求(当然格式正确)并在 AWS 上创建一个作业。这是 AWS 提供的语法:

注意:我已经创建了一个能够提供所有必填字段的表单。

To create a job, send a POST request to the

/2012-09-25/jobs

resource.

这是语法:

POST /2012-09-25/jobs HTTP/1.1
Content-Type: application/json; charset=UTF-8
Accept: */*
Host: elastictranscoder.Elastic Transcoder endpoint.amazonaws.com:443
x-amz-date: Mon, 14 Jan 2013 17:49:52 GMT
Authorization: AWS4-HMAC-SHA256 
           Credential=AccessKeyID/request-date/Elastic Transcoder endpoint/ets/aws4_request,
           SignedHeaders=host;x-amz-date;x-amz-target,
           Signature=calculated-signature
Content-Length: number of characters in the JSON string
{
"Input":{
  "Key":"name of the file to transcode",
  "FrameRate":"auto"|"10"|"15"|"23.97"|"24"|"25"|"29.97"|"30"|"60",
  "Resolution":"auto"|"width in pixelsxheight in pixels",
  "AspectRatio":"auto"|"1:1"|"4:3"|"3:2"|"16:9",
  "Interlaced":"auto"|"true"|"false",
  "Container":"auto"|"3gp"|"asf"|"avi"|"divx"|"flv"|"mkv"|"mov"|"mp4"|
     "mpeg"|"mpeg-ps"|"mpeg-ts"|"mxf"|"ogg"|"vob"|"wav"|"webm"
},
"Output":{
  "Key":"name of the transcoded file",
  "ThumbnailPattern":""|"pattern",
  "Rotate":"auto"|"0"|"90"|"180"|"270",
  "PresetId":"preset to use for the job"
},
"PipelineId":"pipeline to add the job to"
}

需要提供的上述代码部分在语法的原始发布中以斜体显示:

http://docs.aws.amazon.com/elastictranscoder/latest/developerguide/create-job.html#create-job-examples

【问题讨论】:

标签: php json amazon-web-services


【解决方案1】:

AWS SDK for PHP 包括对 Amazon Elastic Transcoder 的支持。您是否有不想使用它的理由? Here 是 PHP SDK 文档的链接。

【讨论】:

    【解决方案2】:

    我建议使用图书馆,尤其是当您感到头疼时。

    如果您不想安装 SDK 或希望避免使用较大包的开销,这里有一个用于使用 Elastic Transcoder 的独立 PHP 类:

    https://github.com/LPology/ElasticTranscoderPHP

    创建新的转码作业(使用默认设置):

    $pipelineId = 'pipelineId';
    $input = array('Key' => 'inputFile');
    $output = array(
      'Key' => 'outputFile.mp4',
      'PresetId' => 'presetId'
    );
    
    AWS_ET::setAuth($awsAccessKey, $awsSecretKey);
    $result = AWS_ET::createJob($input, array($output), $pipelineId);
    

    【讨论】:

      猜你喜欢
      • 2011-10-24
      • 1970-01-01
      • 2023-03-28
      • 2017-03-19
      • 1970-01-01
      • 1970-01-01
      • 2021-05-10
      • 1970-01-01
      相关资源
      最近更新 更多