Created
December 30, 2018 19:43
-
-
Save ckoster22/a4f570c4ff3e0beb8b7be7e3f442656f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/bash | |
queueUrl=https://<my-secret-queue>.fifo | |
uploadsBucket=<my-secret-bucket> | |
fromEmail=<my-secret-email> | |
while true; do | |
echo "Long polling for SQS messages.." | |
sqsResponse=`aws sqs receive-message --queue-url $queueUrl --max-number-of-messages 1 --wait-time-seconds 20 --region us-east-1` | |
if [[ -z $sqsResponse ]]; then | |
echo "No messages" | |
else | |
body=`echo $sqsResponse | jq -r '.Messages[0].Body'` | |
receiptHandle=`echo $sqsResponse | jq -r '.Messages[0].ReceiptHandle'` | |
bucket=`echo $body | jq -r '.bucket'` | |
key=`echo $body | jq -r '.key'` | |
echo $bucket | |
echo $key | |
echo $receiptHandle | |
echo "Copying $bucket/$key from S3.." | |
aws s3 cp s3://$bucket/$key incoming/vid.mp4 --region us-east-1 | |
echo "Retrieving object email tag.." | |
email=`aws s3api get-object-tagging --bucket $bucket --key $key | jq -r '.TagSet[0].Value'` | |
echo "Stabilizing.." | |
./ffmpeg-4.1-64bit-static/ffmpeg -i incoming/vid.mp4 -vf vidstabdetect=stepsize=6:shakiness=5:accuracy=15:result=transform_vectors.trf -f null - | |
./ffmpeg-4.1-64bit-static/ffmpeg -i incoming/vid.mp4 -vf vidstabtransform=input=transform_vectors.trf:zoom=0:smoothing=30:crop=black,unsharp=5:5:0.8:3:3:0.4 -vcodec libx264 -preset slow -tune film -crf 18 -acodec copy outgoing/vid.mp4 | |
echo "Copying result to S3.." | |
aws s3 cp outgoing/vid.mp4 s3://$uploadsBucket/stabilized/$key --region us-east-1 | |
echo "Obtaining presigned download url.." | |
downloadUrl=`aws s3 presign s3://$uploadsBucket/stabilized/$key --expires-in 14400` # 4 hour expiration | |
echo "Emailing download url.." | |
aws ses send-email --to $email --text "Download your video at $downloadUrl" --subject "No Reply - Your video is ready" --from $fromEmail | |
echo "Deleting SQS message.." | |
aws sqs delete-message --queue-url $queueUrl --receipt-handle $receiptHandle --region us-east-1 | |
echo "Clean up.." | |
rm transform_vectors.trf | |
rm incoming/vid.mp4 | |
rm outgoing/vid.mp4 | |
fi | |
done | |
echo "Script done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment