-
Notifications
You must be signed in to change notification settings - Fork 330
Expand file tree
/
Copy pathlambda_ffmpeg_transcode.py
More file actions
39 lines (30 loc) · 999 Bytes
/
lambda_ffmpeg_transcode.py
File metadata and controls
39 lines (30 loc) · 999 Bytes
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
# -*- coding: utf-8 -*-
__author__ = "Chirag Rathod (Srce Cde)"
__license__ = "MIT"
__email__ = "chiragr83@gmail.com"
__maintainer__ = "Chirag Rathod (Srce Cde)"
import json
import os
import boto3
def lambda_handler(event, context):
# boto3 client
s3 = boto3.client("s3")
# replace below configuration
bucket_name = "bucket_name"
key = "file_to_be_downloaded"
# downloading file to /tmp directory within lambda
lambda_file_path = f"/tmp/{key}"
lambda_output_file_path = "/tmp/trancoded_file_name"
# downloading file
s3.download_file(bucket_name, key, lambda_file_path)
# transcoding
os.system(
f"/opt/ffmpeg_dir_path/ffmpeg -i {lambda_file_path} {lambda_output_file_path}"
)
# uploading transcoded file
s3.upload_file(
Bucket=bucket_name,
Key=lambda_output_file_path.split("/")[-1],
Filename=lambda_output_file_path,
)
return {"statusCode": 200, "body": json.dumps("Hello from Srce Cde!")}