Last active
August 29, 2015 14:24
-
-
Save mitchellporter/2fac54a4f429e6541e00 to your computer and use it in GitHub Desktop.
This file contains 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
#Amazon Elastic Transcoder (ET) | |
#ET supports presets for transcoding | |
#http://docs.aws.amazon.com/elastictranscoder/latest/developerguide/preset-settings.html | |
//Let's put our video file to AWS S3. $region = "eu-west-1"; | |
$folder = "source_videos/"; //init class to work with s3. | |
$s3 = new AmazonS3(); //get real file path | |
$real_video_file = str_replace(base_url(), ROOT, $some_file); //generate new unique video name | |
$unique_string = md5(uniqid() . time()); | |
$video_file = $folder . $unique_string; //send out file to s3 storage | |
$s3->batch()->create_object("pam-media-input", $video_file, array( 'fileUpload' => $real_video_file)); | |
$file_upload_response = $s3->batch()->send(); //get upload status | |
$upload2s3_status = $file_upload_response->areOK(); | |
//if status = OK then process with new job for transcodering | |
//2) next we need to setup new transcoding job | |
//for more info check http://docs.aws.amazon.com/elastictranscoder/latest/developerguide/create-job.html //init class to work with ET | |
$et = new AWS_ET(awsAccessKey, awsSecretKey, $region); | |
//pipeline_id – some unique key from ET, we can find it in aws dashboard | |
$pipelineId = '1375815121446-2s7ven'; //$video_file = our uploaded file on s3. | |
$elastic_input = array('Key' => $video_file); | |
//next comes presets. You can find all available sets here http://docs.aws.amazon.com/elastictranscoder/latest/developerguide/create-job.html | |
$elastic_output[] = array( | |
'Key' => "hls_2000M", | |
'PresetId' => '1351620000001-200010', 'SegmentDuration' => '10' | |
); | |
$elastic_output[] = array( | |
'Key' => "hls_1500M", | |
'PresetId' => '1351620000001-200020', 'SegmentDuration' => '10' | |
); | |
$elastic_output[] = array( | |
'Key' => "hls_1000M", | |
'PresetId' => '1351620000001-200030', 'SegmentDuration' => '10' | |
); | |
$elastic_output[] = array( | |
'Key' => "hls_600M", | |
'PresetId' => '1351620000001-200040', 'SegmentDuration' => '10' | |
); | |
$elastic_output[] = array( | |
'Key' => "hls_400M", | |
'PresetId' => '1351620000001-200050', 'SegmentDuration' => '10' | |
); | |
$elastic_playlists = array( | |
'Format' => "HLSv3", | |
'Name' => "playlist", | |
'OutputKeys' => array('hls_2000M', 'hls_1500M', 'hls_1000M', 'hls_600M', 'hls_400M') | |
); | |
$outputKeyPrefix = $unique_string . "/"; //our playlist location will be: | |
$playlist = "https://s3-eu-west-1.amazonaws.com/{s3_bucken_name}/" . $outputKeyPrefix . "playlist.m3u8"; | |
//let's create new job for transcoding and get job_id | |
$elastic_result = $et->createJob($elastic_input, $elastic_output, $pipelineId, $outputKeyPrefix, | |
$elastic_playlists); | |
//job_id = $elastic_result['Job']['Id']; | |
//Finally, we can use cron job to get job status by job_id | |
//PHP example: | |
$region = "eu-west-1"; | |
$et = new AWS_ET(awsAccessKey, awsSecretKey, $region); $status = $et->readJob($job_id); | |
$text = $status['Job']['Status']; | |
//if $text == “complete”, then job done! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment