0

I have created a script using Lambda on Amazon web services to automatically transcode videos when a video is uploaded to a S3 bucket.

This script works great however, when I add the playlist code below into the script, the entire script stops working and it outputs no video files.

Any idea why?

Playlist: [{
  Format: 'HLSv3',
  Name: newKey + '.m3u8',
  OutputKeys: [
     newKey + '.ts'
    ]              
}]

Here you can see the code above within the script

'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-west-2'
});

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 = '1521208528859-wd01uu';

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

    if (bucket !== 'b-video-upload') {
        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: srcKey,
            FrameRate: 'auto',
            Resolution: 'auto',
            AspectRatio: 'auto',
            Interlaced: 'auto',
            Container: 'auto'
        },
        Outputs: [{
            Key: newKey + '.mp4',
            ThumbnailPattern: newKey + '-thumbnail-{resolution}' + '-{count}',
            PresetId: '1521314602259-6jnl6v', //Generic 1080p
            Watermarks: [{
                InputKey: 'watermarks/b-video-watermark.png',
                PresetWatermarkId: 'BottomLeft'
            }],
        },
        {
            Key: newKey + '.ts',
            ThumbnailPattern: '',
            PresetId: '1521267450305-5yd8hd', //HLS v3 2mb/s
            Watermarks: [{
                InputKey: 'watermarks/b-video-watermark.png',
                PresetWatermarkId: 'BottomLeft'
            }],

        }],
        Playlist: [{
                Format: 'HLSv3',
                Name: newKey + '.m3u8',
                OutputKeys: [
                newKey + '.ts'
                ]

        }]          
    };

    console.log('Starting Job');

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

        context.succeed('Job well done');
    });
};
Sridhar
  • 11,466
  • 5
  • 39
  • 43
Ryan NZ
  • 616
  • 1
  • 9
  • 25

1 Answers1

1

I had the same problem. Then i solved it by changing the play-list name.

It seems like this.

Note1: i have in output bucket a folder called 'hls-input' for transcoded videos so

newkey='input/{videoName}'

OutputKeys: ['hls-input/{videoName}.ts']

In this case the function will output a hls encrypted video has the same name of the input and worked fine!

Note2: i've used hlsv3 because hlsv4 needs a video (without sounds) and audio, I dont want to seperate the mp4 to video and audio so thats worked fine for me !

Playlists: [
 {
   Format: 'HLSv3',
   Name: newKey.split('/')[1]  ,
   OutputKeys: [ 'hls-' + newKey + '.ts' ],
 },
],