简体   繁体   中英

Failed to Create preset with Amazon Elastic Transcoder

I am using Amazon Elastic transcoder and boto library to create a preset. This code works for me without any problem:

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"})

But, when I define a var with same value :

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"}'

I get into this error :

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'}

This validation is telling that the 'container' is null! But it is not null.

I am confused what is happening !

Thanks in advance

You can write this using unpacking arg list feature in Python:

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM