Skip to content

Commit 58edd3a

Browse files
authored
Simplify dockerfiles for thumbnail examples (pulumi#63)
* Move shell scripts into Dockerfile * Update thumbnailer-machine-learning * Bump memory to 512.
1 parent 8045884 commit 58edd3a

File tree

9 files changed

+36
-49
lines changed

9 files changed

+36
-49
lines changed

cloud-js-thumbnailer-machine-learning/docker-ffmpeg-thumb/Dockerfile

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ RUN pip install awscli
88

99
WORKDIR /tmp/workdir
1010

11-
COPY copy_thumb.sh /tmp/workdir
12-
COPY copy_video.sh /tmp/workdir
13-
14-
ENTRYPOINT echo "Starting ffmpeg task..." && \
15-
./copy_video.sh && \
16-
ffmpeg -v error -i ./${INPUT_VIDEO_FILE_NAME} -ss ${POSITION_TIME_DURATION} -vframes 1 -f image2 -an -y ${OUTPUT_THUMBS_FILE_NAME} && \
17-
./copy_thumb.sh
11+
ENTRYPOINT \
12+
echo "Starting ffmpeg task..." && \
13+
echo "Copying video from s3://${S3_BUCKET}/${INPUT_VIDEO} to ${INPUT_VIDEO}..." && \
14+
aws s3 cp s3://${S3_BUCKET}/${INPUT_VIDEO} ./${INPUT_VIDEO} && \
15+
ffmpeg -v error -i ./${INPUT_VIDEO} -ss ${TIME_OFFSET} -vframes 1 -f image2 -an -y ${OUTPUT_FILE} && \
16+
echo "Copying thumbnail to S3://${S3_BUCKET}/${OUTPUT_FILE} ..." && \
17+
aws s3 cp ./${OUTPUT_FILE} s3://${S3_BUCKET}/${OUTPUT_FILE}

cloud-js-thumbnailer-machine-learning/docker-ffmpeg-thumb/copy_thumb.sh

-4
This file was deleted.

cloud-js-thumbnailer-machine-learning/docker-ffmpeg-thumb/copy_video.sh

-4
This file was deleted.

cloud-js-thumbnailer-machine-learning/index.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const bucketName = bucket.bucket.id;
1212
// A task which runs a containerized FFMPEG job to extract a thumbnail image.
1313
const ffmpegThumbnailTask = new cloud.Task("ffmpegThumbTask", {
1414
build: "./docker-ffmpeg-thumb",
15-
memoryReservation: 128,
15+
memoryReservation: 512,
1616
});
1717

1818
// Use module for processing video through Rekognition
@@ -33,10 +33,10 @@ videoProcessor.onLabelResult("cat", async (file, framePos) => {
3333
// launch ffmpeg in a container, use environment variables to connect resources together
3434
await ffmpegThumbnailTask.run({
3535
environment: {
36-
"S3_BUCKET": bucketName.get(),
37-
"INPUT_VIDEO_FILE_NAME": file,
38-
"POSITION_TIME_DURATION": framePos,
39-
"OUTPUT_THUMBS_FILE_NAME": thumbnailFile,
36+
"S3_BUCKET": bucketName.get(),
37+
"INPUT_VIDEO": file,
38+
"TIME_OFFSET": framePos,
39+
"OUTPUT_FILE": thumbnailFile,
4040
},
4141
});
4242
console.log("*** Launched thumbnailer task.");

cloud-js-thumbnailer/README.md

+12-9
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,18 @@ To run this example, make sure [Docker](https://docs.docker.com/engine/installat
108108
1. View the logs from both the Lambda function and the ECS task:
109109
110110
```
111-
2018-05-19T20:07:43.879-07:00[ onNewVideo] *** New video: file cat_00-01.mp4 was uploaded at 2018-05-20T03:07:42.477Z.
112-
2018-05-19T20:07:43.880-07:00[ onNewVideo] Running thumbnailer task.
113-
2018-05-19T20:08:54.229-07:00[ ffmpegThumbTask] Starting...
114-
2018-05-19T20:08:54.271-07:00[ ffmpegThumbTask] Copying from S3 bucket-c647dfb/cat_00-01.mp4 to cat_00-01.mp4 ...
115-
download: s3://bucket-c647dfb/cat_00-01.mp4 to ./cat_00-01.mp4 eted 256.0 KiB/666.5 KiB (840.9 KiB/s) with 1 file(s) remaining
116-
2018-05-19T20:08:59.687-07:00[ ffmpegThumbTask] Copying cat.jpg to S3 at bucket-c647dfb/cat.jpg ...
117-
upload: ./cat.jpg to s3://bucket-c647dfb/cat.jpg ompleted 86.6 KiB/86.6 KiB (1.0 MiB/s) with 1 file(s) remaining
118-
2018-05-19T20:09:02.289-07:00[ onNewThumbnail] *** New thumbnail: file cat.jpg was saved at 2018-05-20T03:09:02.162Z.
119-
```
111+
$ pulumi logs -f
112+
Collecting logs for stack thumbnailer-testing since 2018-05-25T11:56:53.000-07:00.
113+
114+
2018-05-25T12:57:26.326-07:00[ onNewVideo] *** New video: file cat_00-01.mp4 was uploaded at 2018-05-25T19:57:25.507Z.
115+
2018-05-25T12:57:30.705-07:00[ onNewVideo] Running thumbnailer task.
116+
2018-05-25T12:58:34.960-07:00[ ffmpegThumbTask] Starting ffmpeg task...
117+
2018-05-25T12:58:34.960-07:00[ ffmpegThumbTask] Copying video from S3 bucket-5ea6b28/cat_00-01.mp4 to cat_00-01.mp4...
118+
2018-05-25T12:58:37.267-07:00[ ffmpegThumbTask] Completed 256.0 KiB/666.5 KiB (2.5 MiB/s) with 1 fildownload: s3://bucket-5ea6b28/cat_00-01.mp4 to ./cat_00-01.mp4
119+
2018-05-25T12:58:40.306-07:00[ ffmpegThumbTask] Copying cat.jpg to S3 at bucket-5ea6b28/cat.jpg ...
120+
2018-05-25T12:58:43.034-07:00[ ffmpegThumbTask] Completed 86.6 KiB/86.6 KiB (619.7 KiB/s) with 1 filupload: ./cat.jpg to s3://bucket-5ea6b28/cat.jpg
121+
2018-05-25T12:58:43.758-07:00[ onNewThumbnail] *** New thumbnail: file cat.jpg was saved at 2018-05-25T19:58:43.028Z.
122+
```
120123
121124
1. Download the key frame:
122125

cloud-js-thumbnailer/docker-ffmpeg-thumb/Dockerfile

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ RUN pip install awscli
88

99
WORKDIR /tmp/workdir
1010

11-
COPY copy_thumb.sh /tmp/workdir
12-
COPY copy_video.sh /tmp/workdir
13-
14-
ENTRYPOINT echo "Starting ffmpeg task..." && \
15-
./copy_video.sh && \
16-
ffmpeg -v error -i ./${INPUT_VIDEO_FILE_NAME} -ss ${POSITION_TIME_DURATION} -vframes 1 -f image2 -an -y ${OUTPUT_THUMBS_FILE_NAME} && \
17-
./copy_thumb.sh
11+
ENTRYPOINT \
12+
echo "Starting ffmpeg task..." && \
13+
echo "Copying video from s3://${S3_BUCKET}/${INPUT_VIDEO} to ${INPUT_VIDEO}..." && \
14+
aws s3 cp s3://${S3_BUCKET}/${INPUT_VIDEO} ./${INPUT_VIDEO} && \
15+
ffmpeg -v error -i ./${INPUT_VIDEO} -ss ${TIME_OFFSET} -vframes 1 -f image2 -an -y ${OUTPUT_FILE} && \
16+
echo "Copying thumbnail to S3://${S3_BUCKET}/${OUTPUT_FILE} ..." && \
17+
aws s3 cp ./${OUTPUT_FILE} s3://${S3_BUCKET}/${OUTPUT_FILE}

cloud-js-thumbnailer/docker-ffmpeg-thumb/copy_thumb.sh

-4
This file was deleted.

cloud-js-thumbnailer/docker-ffmpeg-thumb/copy_video.sh

-4
This file was deleted.

cloud-js-thumbnailer/index.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const bucketName = bucket.bucket.id;
99
// A task which runs a containerized FFMPEG job to extract a thumbnail image.
1010
const ffmpegThumbnailTask = new cloud.Task("ffmpegThumbTask", {
1111
build: "./docker-ffmpeg-thumb",
12-
memoryReservation: 128,
12+
memoryReservation: 512,
1313
});
1414

1515
// When a new video is uploaded, run the FFMPEG task on the video file.
@@ -23,10 +23,10 @@ bucket.onPut("onNewVideo", async (bucketArgs) => {
2323

2424
await ffmpegThumbnailTask.run({
2525
environment: {
26-
"S3_BUCKET": bucketName.get(),
27-
"INPUT_VIDEO_FILE_NAME": file,
28-
"POSITION_TIME_DURATION": framePos,
29-
"OUTPUT_THUMBS_FILE_NAME": thumbnailFile,
26+
"S3_BUCKET": bucketName.get(),
27+
"INPUT_VIDEO": file,
28+
"TIME_OFFSET": framePos,
29+
"OUTPUT_FILE": thumbnailFile,
3030
},
3131
});
3232
console.log(`Running thumbnailer task.`);

0 commit comments

Comments
 (0)