Skip to content

Instantly share code, notes, and snippets.

@DaisukeMiyamoto
Last active May 11, 2020 03:00
Show Gist options
  • Save DaisukeMiyamoto/4b3cacfb65fbf840b8298b787fc898ca to your computer and use it in GitHub Desktop.
Save DaisukeMiyamoto/4b3cacfb65fbf840b8298b787fc898ca to your computer and use it in GitHub Desktop.
ElasticTranscoder example
import json
import boto.elastictranscoder
def elastictranscoder_create_job(pipeline_id, input_key, output_key,
thumbnail_key='thumbnails/{resolution}-{count}',
output_key_prefix='hls/',
segment_duration = '10',
region = 'us-west-2'):
# set Preset
hls_64k_audio_preset_id = '1351620000001-200071';
hls_0400k_preset_id = '1351620000001-200050';
hls_0600k_preset_id = '1351620000001-200040';
hls_1000k_preset_id = '1351620000001-200030';
hls_1500k_preset_id = '1351620000001-200020';
hls_2000k_preset_id = '1351620000001-200010';
job_input = { 'Key': input_key }
hls_audio = {
'Key' : 'hlsAudio/',
'PresetId' : hls_64k_audio_preset_id,
'SegmentDuration' : segment_duration
}
hls_400k = {
'Key' : 'hls0400k/',
'PresetId' : hls_0400k_preset_id,
'SegmentDuration' : segment_duration
}
hls_600k = {
'Key' : 'hls0600k/',
'PresetId' : hls_0600k_preset_id,
'SegmentDuration' : segment_duration
}
hls_1000k = {
'Key' : 'hls1000k/',
'PresetId' : hls_1000k_preset_id,
'SegmentDuration' : segment_duration,
'ThumbnailPattern' : thumbnail_key
}
hls_1500k = {
'Key' : 'hls1500k/',
'PresetId' : hls_1500k_preset_id,
'SegmentDuration' : segment_duration
}
hls_2000k = {
'Key' : 'hls2000k/',
'PresetId' : hls_2000k_preset_id,
'SegmentDuration' : segment_duration
}
# job_outputs = [ hls_audio, hls_400k, hls_600k, hls_1000k, hls_1500k, hls_2000k ]
job_outputs = [ hls_audio, hls_400k, hls_1000k]
# set Playlist
playlist = {
'Name' : 'hls_' + output_key,
'Format' : 'HLSv3',
'OutputKeys' : map(lambda x: x['Key'], job_outputs)
}
# Create Job
create_job_request = {
'pipeline_id' : pipeline_id,
'input_name' : job_input,
'output_key_prefix' : output_key_prefix + output_key +'/',
'outputs' : job_outputs,
'playlists' : [ playlist ]
}
transcoder_client = boto.elastictranscoder.connect_to_region(region)
create_job_result=transcoder_client.create_job(**create_job_request)
print('HLS job has been created')
# print(json.dumps(create_job_result['Job'], indent=4, sort_keys=True)
if __name__ == '__main__':
pipeline_id = ''
target_name = ''
elastictranscoder_create_job(pipeline_id, 'original/' + target_name + '.mkv', target_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment