无法使用Amazon Elastic Transcoder创建预设

时间:2015-06-03 11:17:22

标签: amazon-web-services amazon-ec2 amazon-s3 amazon boto

我正在使用Amazon Elastic转码器和boto库来创建预设。 这段代码对我没有任何问题:

preset1=transcode.create_preset('preset', 'preset', 'mp4', {"Codec":"H.264", "CodecOptions":{"Profile":"baseline", "Level":"3", 
"MaxReferenceFrames":"3"}, "KeyframesMaxDist":"200", "FixedGOP":"false", "BitRate":"600", "FrameRate":"10", "Resolution":"640x480", 
"AspectRatio":"4:3" }, {"Codec":"AAC","CodecOptions":{"Profile":"AAC-LC"}, "SampleRate":"22050", "BitRate":"32", "Channels":"1" }, 
{"Format":"png", "Interval":"60", "Resolution":"192x144", "AspectRatio":"4:3"})

但是,当我定义一个具有相同值的var时:

preset_h264_480p_100kbs_mp4_command='"Name":"preset","Description": "preset", "Container":"mp4","video": 
{"Codec":"H.264", "CodecOptions":{"Profile":"baseline", "Level":"3", "MaxReferenceFrames":"3"}, "KeyframesMaxDist":"200", 
"FixedGOP":"false", "BitRate":"600", "FrameRate":"10", "Resolution":"640x480", "AspectRatio":"4:3" },"audio": 
{"Codec":"AAC","CodecOptions":{"Profile":"AAC-LC"}, "SampleRate":"22050", "BitRate":"32", "Channels":"1" }, "thumbnails":
{"Format":"png", "Interval":"60", "Resolution":"192x144", "AspectRatio":"4:3"}'

我遇到了这个错误:

transcode.create_preset(preset_h264_480p_100kbs_mp4_command)Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/boto/elastictranscoder/layer1.py", line 421, in create_preset
    data=json.dumps(params))
  File "/usr/local/lib/python2.7/dist-packages/boto/elastictranscoder/layer1.py", line 932, in make_request
    raise error_class(response.status, response.reason, body)
boto.elastictranscoder.exceptions.ValidationException: ValidationException: 400 Bad Request
{u'message': u'2 validation errors detected: Value null at \'container\' failed to satisfy constraint: Member must not be null; Value \'"Name":"preset","Description": "preset", "Container":"mp4","video": {"Codec":"H.264", "CodecOptions":{"Profile":"baseline", "Level":"3", "MaxReferenceFrames":"3"}, "KeyframesMaxDist":"200", "FixedGOP":"false", "BitRate":"600", "FrameRate":"10", "Resolution":"640x480", "AspectRatio":"4:3" },"audio": {"Codec":"AAC","CodecOptions":{"Profile":"AAC-LC"}, "SampleRate":"22050", "BitRate":"32", "Channels":"1" }, "thumbnails":{"Format":"png", "Interval":"60", "Resolution":"192x144", "AspectRatio":"4:3"}\' at \'name\' failed to satisfy constraint: Member must have length less than or equal to 40'}

此验证告诉'容器'为空!但它不是空的。

我很困惑发生了什么!

提前致谢

1 个答案:

答案 0 :(得分:2)

您可以使用Python中的unpacking arg list功能编写此内容:

preset_h264_480p_100kbs_mp4_command={ "name":"preset","description": "preset", "container":"mp4","video": 
{"Codec":"H.264", "CodecOptions":{"Profile":"baseline", "Level":"3", "MaxReferenceFrames":"3"}, "KeyframesMaxDist":"200", 
"FixedGOP":"false", "BitRate":"600", "FrameRate":"10", "Resolution":"640x480", "AspectRatio":"4:3" },"audio": 
{"Codec":"AAC","CodecOptions":{"Profile":"AAC-LC"}, "SampleRate":"22050", "BitRate":"32", "Channels":"1" }, "thumbnails":
{"Format":"png", "Interval":"60", "Resolution":"192x144", "AspectRatio":"4:3"} }

transcode.create_preset(**preset_h264_480p_100kbs_mp4_command)