Skip to content

Instantly share code, notes, and snippets.

@sbarski
Last active January 5, 2023 11:10
Show Gist options
  • Select an option

  • Save sbarski/93db5c0cd75a01dd86c3 to your computer and use it in GitHub Desktop.

Select an option

Save sbarski/93db5c0cd75a01dd86c3 to your computer and use it in GitHub Desktop.

Revisions

  1. sbarski revised this gist Nov 6, 2015. 1 changed file with 5 additions and 3 deletions.
    8 changes: 5 additions & 3 deletions index.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,3 @@
    //An S3 bucket needs to invoke this Lambda function which would in-turn create an Elastic Transcoder job

    'use strict';

    var AWS = require('aws-sdk');
    @@ -18,18 +16,22 @@ exports.handler = function(event, context) {
    var key = event.Records[0].s3.object.key;
    var pipelineId = '1446424116409-5pdjj8';

    console.log(key);
    console.log(event.Records[0]);

    if (bucket !== 'acloud-video-input') {
    context.fail('Incorrect Video Input Bucket');
    return;
    }

    var srcKey = decodeURIComponent(event.Records[0].s3.object.key.replace(/\+/g, " ")); //the object may have spaces
    var newKey = key.split('.')[0];

    var params = {
    PipelineId: pipelineId,
    OutputKeyPrefix: newKey + '/',
    Input: {
    Key: key,
    Key: srcKey,
    FrameRate: 'auto',
    Resolution: 'auto',
    AspectRatio: 'auto',
  2. sbarski created this gist Nov 5, 2015.
    79 changes: 79 additions & 0 deletions index.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,79 @@
    //An S3 bucket needs to invoke this Lambda function which would in-turn create an Elastic Transcoder job

    'use strict';

    var AWS = require('aws-sdk');
    var s3 = new AWS.S3({
    apiVersion: '2012-09-25'
    });
    var eltr = new AWS.ElasticTranscoder({
    apiVersion: '2012-09-25',
    region: 'us-east-1'
    });

    exports.handler = function(event, context) {
    console.log('Executing Elastic Transcoder Orchestrator');

    var bucket = event.Records[0].s3.bucket.name;
    var key = event.Records[0].s3.object.key;
    var pipelineId = '1446424116409-5pdjj8';

    if (bucket !== 'acloud-video-input') {
    context.fail('Incorrect Video Input Bucket');
    return;
    }

    var newKey = key.split('.')[0];

    var params = {
    PipelineId: pipelineId,
    OutputKeyPrefix: newKey + '/',
    Input: {
    Key: key,
    FrameRate: 'auto',
    Resolution: 'auto',
    AspectRatio: 'auto',
    Interlaced: 'auto',
    Container: 'auto'
    },
    Outputs: [{
    Key: 'mp4-' + newKey + '.mp4',
    ThumbnailPattern: 'thumbs-' + newKey + '-{resolution}' + '-{count}',
    PresetId: '1351620000001-000010', //Generic 720p
    Watermarks: [{
    InputKey: 'watermarks/logo-horiz-large.png',
    PresetWatermarkId: 'BottomRight'
    }],
    },
    {
    Key: 'webm-' + newKey + '.webm',
    ThumbnailPattern: '',
    PresetId: '1351620000001-100240', //Webm 720p
    Watermarks: [{
    InputKey: 'watermarks/logo-horiz-large.png',
    PresetWatermarkId: 'BottomRight'
    }],
    },
    {
    Key: 'hls-' + newKey + '.ts',
    ThumbnailPattern: '',
    PresetId: '1351620000001-200010', //HLS v3 2mb/s
    Watermarks: [{
    InputKey: 'watermarks/logo-horiz-large.png',
    PresetWatermarkId: 'BottomRight'
    }],
    }]
    };

    console.log('Starting Job');

    eltr.createJob(params, function(err, data){
    if (err){
    console.log(err);
    } else {
    console.log(data);
    }

    context.succeed('Job well done');
    });
    };