Skip to content

Commit 1a7d905

Browse files
Add Google Transcoder API (#10932) (#821)
[upstream:c95102737c7c4909dfac79f26d582c42e97a1a8b] Signed-off-by: Modular Magician <[email protected]>
1 parent d02a738 commit 1a7d905

File tree

32 files changed

+1735
-0
lines changed

32 files changed

+1735
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# This file has some scaffolding to make sure that names are unique and that
2+
# a region and zone are selected when you try to create your Terraform resources.
3+
4+
locals {
5+
name_suffix = "${random_pet.suffix.id}"
6+
}
7+
8+
resource "random_pet" "suffix" {
9+
length = 2
10+
}
11+
12+
provider "google" {
13+
region = "us-central1"
14+
zone = "us-central1-c"
15+
}

transcoder_job_basic/main.tf

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
resource "google_storage_bucket" "default" {
2+
name = "transcoder-job-${local.name_suffix}"
3+
location = "US"
4+
force_destroy = true
5+
6+
uniform_bucket_level_access = true
7+
public_access_prevention = "enforced"
8+
}
9+
10+
resource "google_storage_bucket_object" "example_mp4" {
11+
name = "example.mp4"
12+
source = "./test-fixtures/example.mp4"
13+
bucket = google_storage_bucket.default.name
14+
}
15+
16+
resource "google_transcoder_job" "default" {
17+
template_id = google_transcoder_job_template.default.name
18+
location = "us-central1"
19+
20+
labels = {
21+
"label" = "key"
22+
}
23+
}
24+
25+
resource "google_transcoder_job_template" "default" {
26+
job_template_id = "example-job-template-${local.name_suffix}"
27+
location = "us-central1"
28+
config {
29+
inputs {
30+
key = "input0"
31+
uri = "gs://${google_storage_bucket.default.name}/${google_storage_bucket_object.example_mp4.name}"
32+
}
33+
output {
34+
uri = "gs://${google_storage_bucket.default.name}/outputs/"
35+
}
36+
edit_list {
37+
key = "atom0"
38+
inputs = ["input0"]
39+
start_time_offset = "0s"
40+
}
41+
elementary_streams {
42+
key = "video-stream0"
43+
video_stream {
44+
h264 {
45+
width_pixels = 640
46+
height_pixels = 360
47+
bitrate_bps = 550000
48+
frame_rate = 60
49+
pixel_format = "yuv420p"
50+
rate_control_mode = "vbr"
51+
crf_level = 21
52+
gop_duration = "3s"
53+
vbv_size_bits = 550000
54+
vbv_fullness_bits = 495000
55+
entropy_coder = "cabac"
56+
profile = "high"
57+
preset = "veryfast"
58+
59+
}
60+
}
61+
}
62+
elementary_streams {
63+
key = "video-stream1"
64+
video_stream {
65+
h264 {
66+
width_pixels = 1280
67+
height_pixels = 720
68+
bitrate_bps = 550000
69+
frame_rate = 60
70+
pixel_format = "yuv420p"
71+
rate_control_mode = "vbr"
72+
crf_level = 21
73+
gop_duration = "3s"
74+
vbv_size_bits = 2500000
75+
vbv_fullness_bits = 2250000
76+
entropy_coder = "cabac"
77+
profile = "high"
78+
preset = "veryfast"
79+
}
80+
}
81+
}
82+
elementary_streams {
83+
key = "audio-stream0"
84+
audio_stream {
85+
codec = "aac"
86+
bitrate_bps = 64000
87+
channel_count = 2
88+
channel_layout = ["fl", "fr"]
89+
sample_rate_hertz = 48000
90+
}
91+
}
92+
mux_streams {
93+
key = "sd"
94+
file_name = "sd.mp4"
95+
container = "mp4"
96+
elementary_streams = ["video-stream0", "audio-stream0"]
97+
}
98+
mux_streams {
99+
key = "hd"
100+
file_name = "hd.mp4"
101+
container = "mp4"
102+
elementary_streams = ["video-stream1", "audio-stream0"]
103+
}
104+
}
105+
labels = {
106+
"label" = "key"
107+
}
108+
}

transcoder_job_basic/motd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
===
2+
3+
These examples use real resources that will be billed to the
4+
Google Cloud Platform project you use - so make sure that you
5+
run "terraform destroy" before quitting!
6+
7+
===

transcoder_job_basic/tutorial.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Transcoder Job Basic - Terraform
2+
3+
## Setup
4+
5+
<walkthrough-author name="[email protected]" analyticsId="UA-125550242-1" tutorialName="transcoder_job_basic" repositoryUrl="https://github.com/terraform-google-modules/docs-examples"></walkthrough-author>
6+
7+
Welcome to Terraform in Google Cloud Shell! We need you to let us know what project you'd like to use with Terraform.
8+
9+
<walkthrough-project-billing-setup></walkthrough-project-billing-setup>
10+
11+
Terraform provisions real GCP resources, so anything you create in this session will be billed against this project.
12+
13+
## Terraforming!
14+
15+
Let's use {{project-id}} with Terraform! Click the Cloud Shell icon below to copy the command
16+
to your shell, and then run it from the shell by pressing Enter/Return. Terraform will pick up
17+
the project name from the environment variable.
18+
19+
```bash
20+
export GOOGLE_CLOUD_PROJECT={{project-id}}
21+
```
22+
23+
After that, let's get Terraform started. Run the following to pull in the providers.
24+
25+
```bash
26+
terraform init
27+
```
28+
29+
With the providers downloaded and a project set, you're ready to use Terraform. Go ahead!
30+
31+
```bash
32+
terraform apply
33+
```
34+
35+
Terraform will show you what it plans to do, and prompt you to accept. Type "yes" to accept the plan.
36+
37+
```bash
38+
yes
39+
```
40+
41+
42+
## Post-Apply
43+
44+
### Editing your config
45+
46+
Now you've provisioned your resources in GCP! If you run a "plan", you should see no changes needed.
47+
48+
```bash
49+
terraform plan
50+
```
51+
52+
So let's make a change! Try editing a number, or appending a value to the name in the editor. Then,
53+
run a 'plan' again.
54+
55+
```bash
56+
terraform plan
57+
```
58+
59+
Afterwards you can run an apply, which implicitly does a plan and shows you the intended changes
60+
at the 'yes' prompt.
61+
62+
```bash
63+
terraform apply
64+
```
65+
66+
```bash
67+
yes
68+
```
69+
70+
## Cleanup
71+
72+
Run the following to remove the resources Terraform provisioned:
73+
74+
```bash
75+
terraform destroy
76+
```
77+
```bash
78+
yes
79+
```
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# This file has some scaffolding to make sure that names are unique and that
2+
# a region and zone are selected when you try to create your Terraform resources.
3+
4+
locals {
5+
name_suffix = "${random_pet.suffix.id}"
6+
}
7+
8+
resource "random_pet" "suffix" {
9+
length = 2
10+
}
11+
12+
provider "google" {
13+
region = "us-central1"
14+
zone = "us-central1-c"
15+
}

transcoder_job_manifests/main.tf

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
resource "google_storage_bucket" "default" {
2+
name = "transcoder-job-${local.name_suffix}"
3+
location = "US"
4+
force_destroy = true
5+
6+
uniform_bucket_level_access = true
7+
public_access_prevention = "enforced"
8+
}
9+
10+
resource "google_storage_bucket_object" "example_mp4" {
11+
name = "example.mp4"
12+
source = "./test-fixtures/example.mp4"
13+
bucket = google_storage_bucket.default.name
14+
}
15+
16+
resource "google_transcoder_job" "default" {
17+
location = "us-central1"
18+
19+
config {
20+
inputs {
21+
key = "input0"
22+
uri = "gs://${google_storage_bucket.default.name}/${google_storage_bucket_object.example_mp4.name}"
23+
}
24+
25+
edit_list {
26+
key = "atom0"
27+
start_time_offset = "0s"
28+
inputs = ["input0"]
29+
}
30+
31+
ad_breaks {
32+
start_time_offset = "3.500s"
33+
}
34+
35+
elementary_streams {
36+
key = "video-stream0"
37+
video_stream {
38+
h264 {
39+
width_pixels = 640
40+
height_pixels = 360
41+
bitrate_bps = 550000
42+
frame_rate = 60
43+
pixel_format = "yuv420p"
44+
rate_control_mode = "vbr"
45+
crf_level = 21
46+
gop_duration = "3s"
47+
vbv_size_bits = 550000
48+
vbv_fullness_bits = 495000
49+
entropy_coder = "cabac"
50+
profile = "high"
51+
preset = "veryfast"
52+
53+
}
54+
}
55+
}
56+
57+
elementary_streams {
58+
key = "video-stream1"
59+
video_stream {
60+
h264 {
61+
width_pixels = 1280
62+
height_pixels = 720
63+
bitrate_bps = 550000
64+
frame_rate = 60
65+
pixel_format = "yuv420p"
66+
rate_control_mode = "vbr"
67+
crf_level = 21
68+
gop_duration = "3s"
69+
vbv_size_bits = 2500000
70+
vbv_fullness_bits = 2250000
71+
entropy_coder = "cabac"
72+
profile = "high"
73+
preset = "veryfast"
74+
}
75+
}
76+
}
77+
78+
elementary_streams {
79+
key = "audio-stream0"
80+
audio_stream {
81+
codec = "aac"
82+
bitrate_bps = 64000
83+
channel_count = 2
84+
channel_layout = ["fl", "fr"]
85+
sample_rate_hertz = 48000
86+
}
87+
}
88+
89+
mux_streams {
90+
key = "sd"
91+
file_name = "sd.mp4"
92+
container = "mp4"
93+
elementary_streams = ["video-stream0", "audio-stream0"]
94+
}
95+
96+
mux_streams {
97+
key = "hd"
98+
file_name = "hd.mp4"
99+
container = "mp4"
100+
elementary_streams = ["video-stream1", "audio-stream0"]
101+
}
102+
103+
mux_streams {
104+
key = "media-sd"
105+
file_name = "media-sd.ts"
106+
container = "ts"
107+
elementary_streams = ["video-stream0", "audio-stream0"]
108+
}
109+
110+
mux_streams {
111+
key = "media-hd"
112+
file_name = "media-hd.ts"
113+
container = "ts"
114+
elementary_streams = ["video-stream1", "audio-stream0"]
115+
}
116+
117+
mux_streams {
118+
key = "video-only-sd"
119+
file_name = "video-only-sd.m4s"
120+
container = "fmp4"
121+
elementary_streams = ["video-stream0"]
122+
}
123+
124+
mux_streams {
125+
key = "video-only-hd"
126+
file_name = "video-only-hd.m4s"
127+
container = "fmp4"
128+
elementary_streams = ["video-stream1"]
129+
}
130+
131+
mux_streams {
132+
key = "audio-only"
133+
file_name = "audio-only.m4s"
134+
container = "fmp4"
135+
elementary_streams = ["audio-stream0"]
136+
}
137+
138+
manifests {
139+
file_name = "manifest.m3u8"
140+
type = "HLS"
141+
mux_streams = ["media-sd", "media-hd"]
142+
}
143+
144+
manifests {
145+
file_name = "manifest.mpd"
146+
type = "DASH"
147+
mux_streams = ["video-only-sd", "video-only-hd", "audio-only"]
148+
}
149+
150+
output {
151+
uri = "gs://${google_storage_bucket.default.name}/outputs/"
152+
}
153+
}
154+
labels = {
155+
"label" = "key"
156+
}
157+
}

transcoder_job_manifests/motd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
===
2+
3+
These examples use real resources that will be billed to the
4+
Google Cloud Platform project you use - so make sure that you
5+
run "terraform destroy" before quitting!
6+
7+
===

0 commit comments

Comments
 (0)