-
Notifications
You must be signed in to change notification settings - Fork 2
/
transcoder.tf
193 lines (164 loc) · 5.39 KB
/
transcoder.tf
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
resource "aws_sns_topic" "this_transcode_notification" {
name = "${local.namespace}-pipeline-topic"
}
data "aws_iam_policy_document" "transcoder" {
statement {
sid = ""
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["elastictranscoder.amazonaws.com"]
}
effect = "Allow"
}
}
resource "aws_iam_role" "this_pipeline_role" {
name = "${local.namespace}-pipeline-role"
assume_role_policy = data.aws_iam_policy_document.transcoder.json
}
data "aws_iam_policy_document" "this_pipeline_policy" {
statement {
effect = "Allow"
actions = [
"s3:Put*",
"s3:ListBucket",
"s3:*MultipartUpload*",
"s3:Get*",
]
resources = [
aws_s3_bucket.this_masterfiles.arn,
aws_s3_bucket.this_derivatives.arn,
"${aws_s3_bucket.this_masterfiles.arn}/*",
"${aws_s3_bucket.this_derivatives.arn}/*",
]
}
statement {
effect = "Allow"
actions = ["sns:Publish"]
resources = [aws_sns_topic.this_transcode_notification.arn]
}
statement {
effect = "Deny"
actions = [
"s3:*Delete*",
"s3:*Policy*",
"sns:*Remove*",
"sns:*Delete*",
"sns:*Permission*",
]
resources = ["*"]
}
}
resource "aws_iam_policy" "this_pipeline_policy" {
name = "${local.namespace}-${var.app_name}-pipeline-policy"
policy = data.aws_iam_policy_document.this_pipeline_policy.json
}
resource "aws_iam_role_policy_attachment" "this_pipeline" {
role = aws_iam_role.this_pipeline_role.name
policy_arn = aws_iam_policy.this_pipeline_policy.arn
}
resource "aws_elastictranscoder_pipeline" "this_pipeline" {
name = "${local.namespace}-${var.app_name}-transcoding-pipeline"
input_bucket = aws_s3_bucket.this_masterfiles.id
output_bucket = aws_s3_bucket.this_derivatives.id
role = aws_iam_role.this_pipeline_role.arn
notifications {
completed = aws_sns_topic.this_transcode_notification.arn
error = aws_sns_topic.this_transcode_notification.arn
progressing = aws_sns_topic.this_transcode_notification.arn
warning = aws_sns_topic.this_transcode_notification.arn
}
}
locals {
containers = [
{ container = "ts", description = "hls" },
{ container = "mp4", description = "mp4" }
]
audio_qualities = [
{ quality = "high", audio_bit_rate = "320" },
{ quality = "medium", audio_bit_rate = "128" }
]
audio_presets = [
for config in setproduct(local.audio_qualities, local.containers) : {
container = config[1].container
name = "${local.namespace}-audio-${config[0].quality}-${config[1].description}"
description = "Avalon Media System: video/${config[0].quality}/${config[1].description}"
audio_bit_rate = config[0].audio_bit_rate
}
]
video_qualities = [
{ quality = "high", audio_bit_rate = "192", video_bit_rate = "2048", max_width = "1920", max_height = "1080" },
{ quality = "medium", audio_bit_rate = "128", video_bit_rate = "1024", max_width = "1280", max_height = "720" },
{ quality = "low", audio_bit_rate = "128", video_bit_rate = "500", max_width = "720", max_height = "480" }
]
video_presets = [
for config in setproduct(local.video_qualities, local.containers) : {
container = config[1].container
name = "${local.namespace}-video-${config[0].quality}-${config[1].description}"
description = "Avalon Media System: video/${config[0].quality}/${config[1].description}"
audio_bit_rate = config[0].audio_bit_rate
video_bit_rate = config[0].video_bit_rate
max_width = config[0].max_width
max_height = config[0].max_height
}
]
}
resource "aws_elastictranscoder_preset" "this_preset_audio" {
for_each = { for preset in local.audio_presets : preset.name => preset }
container = each.value.container
description = each.value.description
name = each.key
audio {
audio_packing_mode = "SingleTrack"
bit_rate = each.value.audio_bit_rate
channels = 2
codec = "AAC"
sample_rate = 44100
}
audio_codec_options {
profile = "AAC-LC"
}
}
resource "aws_elastictranscoder_preset" "this_preset_video" {
for_each = { for preset in local.video_presets : preset.name => preset }
container = each.value.container
description = each.value.description
name = each.key
audio {
audio_packing_mode = "SingleTrack"
bit_rate = each.value.audio_bit_rate
channels = 2
codec = "AAC"
sample_rate = 44100
}
audio_codec_options {
profile = "AAC-LC"
}
video {
bit_rate = each.value.video_bit_rate
codec = "H.264"
display_aspect_ratio = "auto"
fixed_gop = "true"
frame_rate = "auto"
keyframes_max_dist = 90
max_height = each.value.max_height
max_width = each.value.max_width
padding_policy = "NoPad"
sizing_policy = "ShrinkToFit"
}
video_codec_options = {
Profile = "main"
Level = "3.1"
MaxReferenceFrames = 3
InterlacedMode = "Progressive"
ColorSpaceConversionMode = "Auto"
}
thumbnails {
format = "png"
interval = 300
max_width = "192"
max_height = "108"
padding_policy = "NoPad"
sizing_policy = "ShrinkToFit"
}
}