Skip to content

Instantly share code, notes, and snippets.

@walosha
Forked from RivaanRanawat/awsCopyPaste.txt
Created March 22, 2025 22:54
Show Gist options
  • Save walosha/afc1a0715b000e215c28013e30d954c8 to your computer and use it in GitHub Desktop.
Save walosha/afc1a0715b000e215c28013e30d954c8 to your computer and use it in GitHub Desktop.
All AWS Copy Paste material related to the video tutorial
AWS SQS Queue Access Policy to Store data to S3 RAW VIDEOS:
{
"Version": "2012-10-17",
"Id": "__default_policy_ID",
"Statement": [
// existing data... add the statement below
{
"Effect": "Allow",
"Principal": {
"Service": "s3.amazonaws.com"
},
"Action": "sqs:SendMessage",
"Resource": "<queue arn>",
"Condition": {
"ArnLike": {
"aws:SourceArn": "arn:aws:s3:::<bucket name>"
}
}
}
]
}
S3 Processed Videos Bucket Policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowCloudFrontAccess",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity <your oai>"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::<your bucket name>/*"
}
]
}
S3 Processed videos CORS:
[
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"GET"
],
"AllowedOrigins": [
"*"
],
"ExposeHeaders": [],
"MaxAgeSeconds": 3000
}
]
FFMPEG DASH COMMAND:
cmd = [
"ffmpeg",
"-i",
input_path,
"-filter_complex",
"[0:v]split=3[v1][v2][v3];"
"[v1]scale=640:360:flags=fast_bilinear[360p];"
"[v2]scale=1280:720:flags=fast_bilinear[720p];"
"[v3]scale=1920:1080:flags=fast_bilinear[1080p]",
# 360p video stream
"-map",
"[360p]",
"-c:v:0",
"libx264",
"-b:v:0",
"1000k",
"-preset",
"veryfast",
"-profile:v",
"high",
"-level:v",
"4.1",
"-g",
"48",
"-keyint_min",
"48",
# 720p video stream
"-map",
"[720p]",
"-c:v:1",
"libx264",
"-b:v:1",
"4000k",
"-preset",
"veryfast",
"-profile:v",
"high",
"-level:v",
"4.1",
"-g",
"48",
"-keyint_min",
"48",
# 1080p video stream
"-map",
"[1080p]",
"-c:v:2",
"libx264",
"-b:v:2",
"8000k",
"-preset",
"veryfast",
"-profile:v",
"high",
"-level:v",
"4.1",
"-g",
"48",
"-keyint_min",
"48",
# Audio stream
"-map",
"0:a",
"-c:a",
"aac",
"-b:a",
"128k",
# DASH specific settings
"-use_timeline",
"1",
"-use_template",
"1",
"-window_size",
"5",
"-adaptation_sets",
"id=0,streams=v id=1,streams=a",
"-f",
"dash",
f"{output_dir}/manifest.mpd",
]
FFMPEG HLS COMMAND:
cmd = [
"ffmpeg",
"-i",
input_path,
"-filter_complex",
"[0:v]split=3[v1][v2][v3];"
"[v1]scale=640:360:flags=fast_bilinear[360p];"
"[v2]scale=1280:720:flags=fast_bilinear[720p];"
"[v3]scale=1920:1080:flags=fast_bilinear[1080p]",
"-map",
"[360p]",
"-map",
"[720p]",
"-map",
"[1080p]",
"-c:v",
"libx264",
"-preset",
"veryfast",
"-profile:v",
"high",
"-level:v",
"4.1",
"-g",
"48",
"-keyint_min",
"48",
"-sc_threshold",
"0",
"-b:v:0",
"1000k",
"-b:v:1",
"4000k",
"-b:v:2",
"8000k",
"-f",
"hls",
"-hls_time",
"6",
"-hls_playlist_type",
"vod",
"-hls_flags",
"independent_segments",
"-hls_segment_type",
"mpegts",
"-hls_list_size",
"0",
"-master_pl_name",
"master.m3u8",
"-var_stream_map",
"v:0 v:1 v:2",
"-hls_segment_filename",
f"{output_dir}/%v/segment_%03d.ts",
f"{output_dir}/%v/playlist.m3u8",
]
to_dict function (Video.py)
def to_dict(self):
result = {}
for c in self.__table__.columns:
value = getattr(self, c.name)
if isinstance(value, enum.Enum):
value = value.value
result[c.name] = value
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment