Skip to content

Commit

Permalink
Simplify dockerfiles for thumbnail examples (pulumi#63)
Browse files Browse the repository at this point in the history
* Move shell scripts into Dockerfile

* Update thumbnailer-machine-learning

* Bump memory to 512.
  • Loading branch information
lindydonna committed Jun 2, 2018
1 parent 8045884 commit 58edd3a
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ RUN pip install awscli

WORKDIR /tmp/workdir

COPY copy_thumb.sh /tmp/workdir
COPY copy_video.sh /tmp/workdir

ENTRYPOINT echo "Starting ffmpeg task..." && \
./copy_video.sh && \
ffmpeg -v error -i ./${INPUT_VIDEO_FILE_NAME} -ss ${POSITION_TIME_DURATION} -vframes 1 -f image2 -an -y ${OUTPUT_THUMBS_FILE_NAME} && \
./copy_thumb.sh
ENTRYPOINT \
echo "Starting ffmpeg task..." && \
echo "Copying video from s3:https://${S3_BUCKET}/${INPUT_VIDEO} to ${INPUT_VIDEO}..." && \
aws s3 cp s3:https://${S3_BUCKET}/${INPUT_VIDEO} ./${INPUT_VIDEO} && \
ffmpeg -v error -i ./${INPUT_VIDEO} -ss ${TIME_OFFSET} -vframes 1 -f image2 -an -y ${OUTPUT_FILE} && \
echo "Copying thumbnail to S3:https://${S3_BUCKET}/${OUTPUT_FILE} ..." && \
aws s3 cp ./${OUTPUT_FILE} s3:https://${S3_BUCKET}/${OUTPUT_FILE}

This file was deleted.

This file was deleted.

10 changes: 5 additions & 5 deletions cloud-js-thumbnailer-machine-learning/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const bucketName = bucket.bucket.id;
// 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,
memoryReservation: 512,
});

// Use module for processing video through Rekognition
Expand All @@ -33,10 +33,10 @@ videoProcessor.onLabelResult("cat", async (file, framePos) => {
// launch ffmpeg in a container, use environment variables to connect resources together
await ffmpegThumbnailTask.run({
environment: {
"S3_BUCKET": bucketName.get(),
"INPUT_VIDEO_FILE_NAME": file,
"POSITION_TIME_DURATION": framePos,
"OUTPUT_THUMBS_FILE_NAME": thumbnailFile,
"S3_BUCKET": bucketName.get(),
"INPUT_VIDEO": file,
"TIME_OFFSET": framePos,
"OUTPUT_FILE": thumbnailFile,
},
});
console.log("*** Launched thumbnailer task.");
Expand Down
21 changes: 12 additions & 9 deletions cloud-js-thumbnailer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,18 @@ To run this example, make sure [Docker](https://docs.docker.com/engine/installat
1. View the logs from both the Lambda function and the ECS task:

```
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.
2018-05-19T20:07:43.880-07:00[ onNewVideo] Running thumbnailer task.
2018-05-19T20:08:54.229-07:00[ ffmpegThumbTask] Starting...
2018-05-19T20:08:54.271-07:00[ ffmpegThumbTask] Copying from S3 bucket-c647dfb/cat_00-01.mp4 to cat_00-01.mp4 ...
download: s3:https://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
2018-05-19T20:08:59.687-07:00[ ffmpegThumbTask] Copying cat.jpg to S3 at bucket-c647dfb/cat.jpg ...
upload: ./cat.jpg to s3:https://bucket-c647dfb/cat.jpg ompleted 86.6 KiB/86.6 KiB (1.0 MiB/s) with 1 file(s) remaining
2018-05-19T20:09:02.289-07:00[ onNewThumbnail] *** New thumbnail: file cat.jpg was saved at 2018-05-20T03:09:02.162Z.
```
$ pulumi logs -f
Collecting logs for stack thumbnailer-testing since 2018-05-25T11:56:53.000-07:00.
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.
2018-05-25T12:57:30.705-07:00[ onNewVideo] Running thumbnailer task.
2018-05-25T12:58:34.960-07:00[ ffmpegThumbTask] Starting ffmpeg task...
2018-05-25T12:58:34.960-07:00[ ffmpegThumbTask] Copying video from S3 bucket-5ea6b28/cat_00-01.mp4 to cat_00-01.mp4...
2018-05-25T12:58:37.267-07:00[ ffmpegThumbTask] Completed 256.0 KiB/666.5 KiB (2.5 MiB/s) with 1 fildownload: s3:https://bucket-5ea6b28/cat_00-01.mp4 to ./cat_00-01.mp4
2018-05-25T12:58:40.306-07:00[ ffmpegThumbTask] Copying cat.jpg to S3 at bucket-5ea6b28/cat.jpg ...
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:https://bucket-5ea6b28/cat.jpg
2018-05-25T12:58:43.758-07:00[ onNewThumbnail] *** New thumbnail: file cat.jpg was saved at 2018-05-25T19:58:43.028Z.
```

1. Download the key frame:

Expand Down
14 changes: 7 additions & 7 deletions cloud-js-thumbnailer/docker-ffmpeg-thumb/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ RUN pip install awscli

WORKDIR /tmp/workdir

COPY copy_thumb.sh /tmp/workdir
COPY copy_video.sh /tmp/workdir

ENTRYPOINT echo "Starting ffmpeg task..." && \
./copy_video.sh && \
ffmpeg -v error -i ./${INPUT_VIDEO_FILE_NAME} -ss ${POSITION_TIME_DURATION} -vframes 1 -f image2 -an -y ${OUTPUT_THUMBS_FILE_NAME} && \
./copy_thumb.sh
ENTRYPOINT \
echo "Starting ffmpeg task..." && \
echo "Copying video from s3:https://${S3_BUCKET}/${INPUT_VIDEO} to ${INPUT_VIDEO}..." && \
aws s3 cp s3:https://${S3_BUCKET}/${INPUT_VIDEO} ./${INPUT_VIDEO} && \
ffmpeg -v error -i ./${INPUT_VIDEO} -ss ${TIME_OFFSET} -vframes 1 -f image2 -an -y ${OUTPUT_FILE} && \
echo "Copying thumbnail to S3:https://${S3_BUCKET}/${OUTPUT_FILE} ..." && \
aws s3 cp ./${OUTPUT_FILE} s3:https://${S3_BUCKET}/${OUTPUT_FILE}
4 changes: 0 additions & 4 deletions cloud-js-thumbnailer/docker-ffmpeg-thumb/copy_thumb.sh

This file was deleted.

4 changes: 0 additions & 4 deletions cloud-js-thumbnailer/docker-ffmpeg-thumb/copy_video.sh

This file was deleted.

10 changes: 5 additions & 5 deletions cloud-js-thumbnailer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const bucketName = bucket.bucket.id;
// 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,
memoryReservation: 512,
});

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

await ffmpegThumbnailTask.run({
environment: {
"S3_BUCKET": bucketName.get(),
"INPUT_VIDEO_FILE_NAME": file,
"POSITION_TIME_DURATION": framePos,
"OUTPUT_THUMBS_FILE_NAME": thumbnailFile,
"S3_BUCKET": bucketName.get(),
"INPUT_VIDEO": file,
"TIME_OFFSET": framePos,
"OUTPUT_FILE": thumbnailFile,
},
});
console.log(`Running thumbnailer task.`);
Expand Down

0 comments on commit 58edd3a

Please sign in to comment.