Skip to content

Commit

Permalink
Added ALPR function
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnyshaw89 committed Feb 2, 2018
1 parent 2addf2b commit 061277a
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 70 deletions.
78 changes: 78 additions & 0 deletions Lambda/AnalysisLambdas/alprVideoOnBatch/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*jshint loopfunc: true */
console.log('alpr video');

var AWSXRay = require('aws-xray-sdk');
var AWS = AWSXRay.captureAWS(require('aws-sdk'));
var dynamodb = new AWS.DynamoDB.DocumentClient();
const s3 = new AWS.S3({
apiVersion: '2006-03-01',
useAccelerateEndpoint: true
});
var batch = new AWS.Batch();

exports.handler = function(event, context) {
"use strict";

for(var i = 0; i < event.Records.length; i++) {

let record = event.Records[i];

let videoId = record.Sns.Message;

dynamodb.get({
TableName: "Videos",
Key:{
"Id": videoId
},
AttributesToGet: [
'Files',
]
}, function(err, data) {
if (err) {
console.log(err);
return context.fail(err);
}
else {
let key = data.Item.Files.Original.Key;

console.log('Getting video url from Bucket [' + data.Item.Files.Original.Bucket + '] Key [' + data.Item.Files.Original.Key + ']');
var input_file = s3.getSignedUrl('getObject', {
Bucket: data.Item.Files.Original.Bucket,
Key: data.Item.Files.Original.Key,
Expires: 3600
});

var params = {
jobDefinition: process.env.jobDefinition, /* required */
jobName: process.env.jobName, /* required */
jobQueue: process.env.jobQueue, /* required */
containerOverrides: {
environment: [
{
name: 'INPUT_FILE',
value: input_file
},
{
name: 'VIDEO_ID',
value: videoId
}
]
}
};

batch.submitJob(params, function(err, data) {
if (err) {
console.error(err, err.stack);
context.fail();
return;
}
else {
console.log(data);
context.succeed();
}
});

}
});
}
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "transcodeVideo",
"name": "alprVideoOnBatch",
"version": "1.0.0",
"description": "Transcode the video to create smaller optimised versions",
"description": "Run Alpr on the video",
"main": "index.js",
"scripts": {
"lint": "jshint **.js"
Expand All @@ -12,7 +12,7 @@
"jshint": "^2.9.4"
},
"dependencies": {
"aws-sdk": "^2.33.0",
"aws-sdk": "^2.138.0",
"aws-xray-sdk": "^1.1.1"
}
}
67 changes: 0 additions & 67 deletions Lambda/TranscodingLambdas/transcodeVideo/index.js

This file was deleted.

0 comments on commit 061277a

Please sign in to comment.