forked from pulumi/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (34 loc) · 1.53 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright 2016-2018, Pulumi Corporation. All rights reserved.
const cloud = require("@pulumi/cloud-aws");
// A task which runs a containerized FFMPEG job to extract a thumbnail image.
const ffmpegThumbnailTask = new cloud.Task("ffmpegThumbTask", {
build: "./docker-ffmpeg-thumb",
memoryReservation: 128,
});
// A bucket to store videos and thumbnails.
const bucket = new cloud.Bucket("bucket");
const bucketName = bucket.bucket.id;
// When a new video is uploaded, run the FFMPEG job on the video file.
bucket.onPut("onNewVideo", bucketArgs => {
console.log(`A new ${bucketArgs.size}B video was uploaded to ${bucketArgs.key} at ${bucketArgs.eventTime}.`);
const key = bucketArgs.key;
const thumbnailFile = key.substring(0, key.indexOf('_')) + '.png';
const framePos = key.substring(key.indexOf('_')+1, key.indexOf('.')).replace('-',':');
return ffmpegThumbnailTask.run({
environment: {
"S3_BUCKET": bucketName.get(),
"INPUT_VIDEO_FILE_NAME": key,
"POSITION_TIME_DURATION": framePos,
"OUTPUT_THUMBS_FILE_NAME": thumbnailFile,
},
}).then(() => {
console.log(`Running thumbnailer task.`);
});
}, { keySuffix: ".mp4" });
// When a new thumbnail is created, log a message.
bucket.onPut("onNewThumbnail", bucketArgs => {
console.log(`A new ${bucketArgs.size}B thumbnail was saved to ${bucketArgs.key} at ${bucketArgs.eventTime}.`);
return Promise.resolve();
}, { keySuffix: ".png" });
// Export the bucket name.
exports.bucketName = bucketName;