token.validateToken(req, function(err, result){ if (err) { res.json({ status: 401, message: err }, 401); return; } // fire a message to amazon and start transcoding the video into mp4 and webm var str = '%s/%s/quickcast.%s'; var strSmall = '%s/%s/quickcast-small.%s'; var et = new AWS.ElasticTranscoder(); var params = { 'PipelineId': amazonDetails.pipelineId, 'Input': { 'Key': util.format(str, result.user.userid, req.headers.castid, 'mp4'), 'FrameRate': 'auto', 'Resolution': 'auto', 'AspectRatio': 'auto', 'Interlaced': 'auto', 'Container': 'auto' }, 'Outputs': [ { 'Key': util.format(strSmall, result.user.userid, req.headers.castid, 'mp4'), 'PresetId': amazonDetails.mp4small, 'ThumbnailPattern': "", 'Rotate': '0' }, { 'Key': util.format(str, result.user.userid, req.headers.castid, 'webm'), 'PresetId': amazonDetails.webM, 'ThumbnailPattern': "", 'Rotate': '0' } ] }; // transcode et.createJob(params, function(err1, data1){ if (err1){ res.json({ status: 500, message: err1 }, 500); return; } res.json({ status: 200, message: "Encoding requested" }, 200); }); });
module.exports = function (awsOptions, pipelineId) { var transcoder = new AWS.ElasticTranscoder(awsOptions); var listJobsByPipeline = function (pageToken, cb) { transcoder.listJobsByPipeline({ PipelineId: pipelineId, Ascending: 'true', PageToken: pageToken }, function (err, data) { if (err) { return cb(err); } if (data.NextPageToken) { listJobsByPipeline(data.NextPageToken, function (err, nextJobs) { if (err) { return cb(err); } cb(null, data.Jobs.concat(nextJobs)); }); } else { cb(null, data.Jobs); } }); }; var express = require('express'); var app = express(); app.set('views', path.resolve(__dirname, 'views')); var handlebars = expressHandlebars.create({ defaultLayout: 'default', layoutsDir: path.resolve(__dirname, 'views', 'layouts'), helpers: { statusClass: function (status) { return STATUS_CLASSES[status]; } } }); app.engine('handlebars', handlebars.engine); app.set('view engine', 'handlebars'); app.get('/', function (req, res) { res.redirect(req.baseUrl + STATUS.PROGRESSING); }); app.locals.status = _.values(STATUS); _.each(STATUS, function (status) { app.get('/' + status, function (req, res) { listJobsByPipeline(void 0, function (err, jobs) { if (err) { return next(err); } res.render('index', { jobs: _.where(jobs, { Status: status }) }); }); }); }); return app; };
var listJobsByPipeline = function (pageToken, cb) { transcoder.listJobsByPipeline({ PipelineId: pipelineId, Ascending: 'true', PageToken: pageToken }, function (err, data) { if (err) { return cb(err); } if (data.NextPageToken) { listJobsByPipeline(data.NextPageToken, function (err, nextJobs) { if (err) { return cb(err); } cb(null, data.Jobs.concat(nextJobs)); }); } else { cb(null, data.Jobs); } }); };
exports.handler = function (event, context) { var key = event.Records[0].s3.object.key; console.log("Object key:", key); //the input file may have spaces so replace them with '+' var sourceKey = decodeURIComponent(key.replace(/\+/g, ' ')); console.log("Source key:", sourceKey); //remove the extension var outputKey = sourceKey.split('.')[0]; console.log("Output key:", outputKey); // get the unique video key (the folder name) var uniqueVideoKey = outputKey.split('/')[0]; console.log("Unique Video Key:", uniqueVideoKey); var params = { PipelineId: config.ELASTIC_TRANSCODER_PIPELINE_ID, Input: { Key: sourceKey }, Outputs: [ { Key: outputKey + '-web-480p' + '.mp4', PresetId: '1351620000001-000020' //480p 16:9 format } ] }; elasticTranscoder.createJob(params, function (error, data) { if (error) { console.log("Error creating elastic transcoder job."); context.fail(error); return; } // the transcoding job started, so let's make a record in firebase // that the UI can show right away console.log("Elastic transcoder job created successfully"); pushVideoEntryToFirebase(uniqueVideoKey, context); }); };
getIndex({Key: Key}, function (err, index) { if (err || !index) { callback(err); } var type = index.contentType || ''; // 動画エンコード if (type.indexOf('video/') === 0) { var transcoder = new AWS.ElasticTranscoder({apiVersion: '2012-09-25'}); var options = { PipelineId: PipelineId, Input: { Key: Key }, OutputKeyPrefix: Key + '/', Outputs: [ { PresetId: '1401553572423-strh6i', // MP4 360p 16:9 Key: 'data.mp4', ThumbnailPattern: 'thumbnail/{count}', Watermarks: [ { InputKey: 'popy150.png', PresetWatermarkId: 'TopLeft' }, { InputKey: 'MP4_0480p.png', PresetWatermarkId: 'TopRight' } ] }, { PresetId: '1401553215805-kac4dq', // HLS 400k Key: 'HLS_0400K/data', SegmentDuration: "10", Watermarks: [ { InputKey: 'popy150.png', PresetWatermarkId: 'TopLeft' }, { InputKey: 'HLS_0400k.png', PresetWatermarkId: 'TopRight' } ] }, { PresetId: '1401553359605-zgqx0x', // HLS 1,000k Key: 'HLS_1000K/data', SegmentDuration: "10", Watermarks: [ { InputKey: 'popy150.png', PresetWatermarkId: 'TopLeft' }, { InputKey: 'HLS_1000k.png', PresetWatermarkId: 'TopRight' } ] }, { PresetId: '1401553476835-6b99s4', // HLS 2,000k Key: 'HLS_2000K/data', SegmentDuration: "10", Watermarks: [ { InputKey: 'popy150.png', PresetWatermarkId: 'TopLeft' }, { InputKey: 'HLS_2000k.png', PresetWatermarkId: 'TopRight' } ] }, { PresetId: '1401624233970-fot17o', // HLS 100k Key: 'HLS_0100K/data', SegmentDuration: "10", Watermarks: [ { InputKey: 'popy150.png', PresetWatermarkId: 'TopLeft' }, { InputKey: 'HLS_0100k.png', PresetWatermarkId: 'TopRight' } ] } ], Playlists: [ { Format: 'HLSv3', Name: 'data', OutputKeys: [ 'HLS_2000K/data', 'HLS_1000K/data', 'HLS_0400K/data', 'HLS_0100K/data' ] } ] }; transcoder.createJob(options, function (err, data) { callback(err, data); }) } });