Created
October 1, 2013 23:18
-
-
Save cooncesean/6786734 to your computer and use it in GitHub Desktop.
Sample Elastic Transcoder script ... How can I set the output files to be publicly available?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This script assumes an s3 hierarchy like: | |
* bucket | |
/uploads | |
/pending # all unprocessed ('raw') files live here. these files are moved to `processed` after they have been transcoded | |
/processed # the raw file is moved here after it has been sent to the transcoder | |
/web # each transcoded 'web' file is sent here | |
/mobile # each transcoded 'mobile' file is sent here | |
""" | |
from boto import elastictranscoder | |
from boto.s3.connection import S3Connection | |
# Config | |
PENDING_PATH = 'uploads/pending/' | |
PROCESSED_PATH = 'uploads/processed/' | |
MOBILE_PATH = 'uploads/mobile/' | |
WEB_PATH = 'uploads/web/' | |
PIPELINE_ID_MOBILE = 'my_mobile_pipeline_id' | |
PIPELINE_ID_WEB = 'my_web_pipeline_id' | |
PIPELINE_REGION = 'us-west-1' | |
MOBILE_OUTPUT_PRESET_ID = '1351620000001-000030' # 480p 4:3 | |
WEB_OUTPUT_PRESET_ID = '1351620000001-000010' # 720p | |
TRANSCODE_INPUT = { | |
'FrameRate': 'auto', | |
'Resolution': 'auto', | |
'AspectRatio': 'auto', | |
'Interlaced': 'auto', | |
'Container': 'auto' | |
} | |
MOBILE_TRANSCODE_OUTPUT = { | |
'PresetId': MOBILE_OUTPUT_PRESET_ID, | |
'Rotate': '0', # dont rotate | |
'ThumbnailPattern': '', # no thumbs | |
} | |
WEB_TRANSCODE_OUTPUT = { | |
'PresetId': WEB_OUTPUT_PRESET_ID, | |
'Rotate': '0', # dont rotate | |
'ThumbnailPattern': '', # no thumbs | |
} | |
AWS_ACCESS_KEY_ID = 'my_access_key' | |
AWS_SECRET_ACCESS_KEY = 'my_secret_key' | |
AWS_STORAGE_BUCKET_NAME = 'my_storage_bucket' | |
# Create s3 and Transcoder connections | |
connection = S3Connection(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY) | |
bucket = connection.get_bucket(AWS_STORAGE_BUCKET_NAME) | |
trans_connection = elastictranscoder.connect_to_region( | |
PIPELINE_REGION, | |
aws_access_key_id=AWS_ACCESS_KEY_ID, | |
aws_secret_access_key=AWS_SECRET_ACCESS_KEY | |
) | |
# Iterate over pending videos and transcode them | |
pending_keys = [k for k in bucket.get_all_keys(prefix=PENDING_PATH) if k.name != PENDING_PATH] | |
for key in pending_keys: | |
# Move the key from `pending` to `processed` directory | |
filename = key.name.split('/')[-1] | |
renamed_key = key.copy( | |
AWS_STORAGE_BUCKET_NAME, | |
'%s%s' % (PROCESSED_PATH, filename) | |
) | |
renamed_key.set_acl('public-read') | |
key.delete() # Delete the `pending` key | |
# Set the `mobile` and `web` key names for transcoding | |
mobile_key_name = '%s%s' % (MOBILE_PATH, filename) | |
web_key_name = '%s%s' % (WEB_PATH, filename) | |
# Transcode Mobile (HOW CAN I SET THIS OUTPUT KEY TO BE PUBLICLY AVAILABLE?) | |
TRANSCODE_INPUT.update({'Key': renamed_key.name}) | |
MOBILE_TRANSCODE_OUTPUT.update({'Key': mobile_key_name}) | |
mobile_response = trans_connection.create_job( | |
PIPELINE_ID_MOBILE, | |
TRANSCODE_INPUT, | |
MOBILE_TRANSCODE_OUTPUT, | |
) | |
# Transcode Web (HOW CAN I SET THIS OUTPUT KEY TO BE PUBLICLY AVAILABLE?) | |
WEB_TRANSCODE_OUTPUT.update({'Key': web_key_name}) | |
web_response = trans_connection.create_job( | |
PIPELINE_ID_WEB, | |
TRANSCODE_INPUT, | |
WEB_TRANSCODE_OUTPUT, | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment