-
Notifications
You must be signed in to change notification settings - Fork 0
/
lambda_function.py
35 lines (28 loc) · 953 Bytes
/
lambda_function.py
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
import json
import cv2
import fluidityAnalyzer
import base64
def write_to_file(save_path, data):
with open(save_path, "wb") as f:
f.write(base64.b64decode(data))
def process(inFile, outFile):
analyzer = fluidityAnalyzer.FluidityAnalyzer(inFile, outFile)
analyzer.analyze()
def lambda_handler(event, context):
inFile = "/tmp/videoFile.mp4"
outFile = "/tmp/outputFile.mp4"
# Write request body data into file
write_to_file(inFile, event["body"])
process(inFile, outFile)
# Convert videoOutput to base64
with open(outFile, "rb") as vid:
str = base64.b64encode(vid.read())
encoded_vid = str.decode("utf-8")
# Return the data to API Gateway in base64.
# API Gateway will handle the conversion back to binary.
return {
"isBase64Encoded": True,
"statusCode": 200,
"headers": { "content-type": "video/mp4"},
"body": encoded_vid
}