Skip to content

Commit

Permalink
Add Google Transcoder API (#10932) (#821)
Browse files Browse the repository at this point in the history
[upstream:c95102737c7c4909dfac79f26d582c42e97a1a8b]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Oct 15, 2024
1 parent d02a738 commit 1a7d905
Show file tree
Hide file tree
Showing 32 changed files with 1,735 additions and 0 deletions.
15 changes: 15 additions & 0 deletions transcoder_job_basic/backing_file.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This file has some scaffolding to make sure that names are unique and that
# a region and zone are selected when you try to create your Terraform resources.

locals {
name_suffix = "${random_pet.suffix.id}"
}

resource "random_pet" "suffix" {
length = 2
}

provider "google" {
region = "us-central1"
zone = "us-central1-c"
}
108 changes: 108 additions & 0 deletions transcoder_job_basic/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
resource "google_storage_bucket" "default" {
name = "transcoder-job-${local.name_suffix}"
location = "US"
force_destroy = true

uniform_bucket_level_access = true
public_access_prevention = "enforced"
}

resource "google_storage_bucket_object" "example_mp4" {
name = "example.mp4"
source = "./test-fixtures/example.mp4"
bucket = google_storage_bucket.default.name
}

resource "google_transcoder_job" "default" {
template_id = google_transcoder_job_template.default.name
location = "us-central1"

labels = {
"label" = "key"
}
}

resource "google_transcoder_job_template" "default" {
job_template_id = "example-job-template-${local.name_suffix}"
location = "us-central1"
config {
inputs {
key = "input0"
uri = "gs://${google_storage_bucket.default.name}/${google_storage_bucket_object.example_mp4.name}"
}
output {
uri = "gs://${google_storage_bucket.default.name}/outputs/"
}
edit_list {
key = "atom0"
inputs = ["input0"]
start_time_offset = "0s"
}
elementary_streams {
key = "video-stream0"
video_stream {
h264 {
width_pixels = 640
height_pixels = 360
bitrate_bps = 550000
frame_rate = 60
pixel_format = "yuv420p"
rate_control_mode = "vbr"
crf_level = 21
gop_duration = "3s"
vbv_size_bits = 550000
vbv_fullness_bits = 495000
entropy_coder = "cabac"
profile = "high"
preset = "veryfast"

}
}
}
elementary_streams {
key = "video-stream1"
video_stream {
h264 {
width_pixels = 1280
height_pixels = 720
bitrate_bps = 550000
frame_rate = 60
pixel_format = "yuv420p"
rate_control_mode = "vbr"
crf_level = 21
gop_duration = "3s"
vbv_size_bits = 2500000
vbv_fullness_bits = 2250000
entropy_coder = "cabac"
profile = "high"
preset = "veryfast"
}
}
}
elementary_streams {
key = "audio-stream0"
audio_stream {
codec = "aac"
bitrate_bps = 64000
channel_count = 2
channel_layout = ["fl", "fr"]
sample_rate_hertz = 48000
}
}
mux_streams {
key = "sd"
file_name = "sd.mp4"
container = "mp4"
elementary_streams = ["video-stream0", "audio-stream0"]
}
mux_streams {
key = "hd"
file_name = "hd.mp4"
container = "mp4"
elementary_streams = ["video-stream1", "audio-stream0"]
}
}
labels = {
"label" = "key"
}
}
7 changes: 7 additions & 0 deletions transcoder_job_basic/motd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
===

These examples use real resources that will be billed to the
Google Cloud Platform project you use - so make sure that you
run "terraform destroy" before quitting!

===
79 changes: 79 additions & 0 deletions transcoder_job_basic/tutorial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Transcoder Job Basic - Terraform

## Setup

<walkthrough-author name="[email protected]" analyticsId="UA-125550242-1" tutorialName="transcoder_job_basic" repositoryUrl="https://github.com/terraform-google-modules/docs-examples"></walkthrough-author>

Welcome to Terraform in Google Cloud Shell! We need you to let us know what project you'd like to use with Terraform.

<walkthrough-project-billing-setup></walkthrough-project-billing-setup>

Terraform provisions real GCP resources, so anything you create in this session will be billed against this project.

## Terraforming!

Let's use {{project-id}} with Terraform! Click the Cloud Shell icon below to copy the command
to your shell, and then run it from the shell by pressing Enter/Return. Terraform will pick up
the project name from the environment variable.

```bash
export GOOGLE_CLOUD_PROJECT={{project-id}}
```

After that, let's get Terraform started. Run the following to pull in the providers.

```bash
terraform init
```

With the providers downloaded and a project set, you're ready to use Terraform. Go ahead!

```bash
terraform apply
```

Terraform will show you what it plans to do, and prompt you to accept. Type "yes" to accept the plan.

```bash
yes
```


## Post-Apply

### Editing your config

Now you've provisioned your resources in GCP! If you run a "plan", you should see no changes needed.

```bash
terraform plan
```

So let's make a change! Try editing a number, or appending a value to the name in the editor. Then,
run a 'plan' again.

```bash
terraform plan
```

Afterwards you can run an apply, which implicitly does a plan and shows you the intended changes
at the 'yes' prompt.

```bash
terraform apply
```

```bash
yes
```

## Cleanup

Run the following to remove the resources Terraform provisioned:

```bash
terraform destroy
```
```bash
yes
```
15 changes: 15 additions & 0 deletions transcoder_job_manifests/backing_file.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This file has some scaffolding to make sure that names are unique and that
# a region and zone are selected when you try to create your Terraform resources.

locals {
name_suffix = "${random_pet.suffix.id}"
}

resource "random_pet" "suffix" {
length = 2
}

provider "google" {
region = "us-central1"
zone = "us-central1-c"
}
157 changes: 157 additions & 0 deletions transcoder_job_manifests/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
resource "google_storage_bucket" "default" {
name = "transcoder-job-${local.name_suffix}"
location = "US"
force_destroy = true

uniform_bucket_level_access = true
public_access_prevention = "enforced"
}

resource "google_storage_bucket_object" "example_mp4" {
name = "example.mp4"
source = "./test-fixtures/example.mp4"
bucket = google_storage_bucket.default.name
}

resource "google_transcoder_job" "default" {
location = "us-central1"

config {
inputs {
key = "input0"
uri = "gs://${google_storage_bucket.default.name}/${google_storage_bucket_object.example_mp4.name}"
}

edit_list {
key = "atom0"
start_time_offset = "0s"
inputs = ["input0"]
}

ad_breaks {
start_time_offset = "3.500s"
}

elementary_streams {
key = "video-stream0"
video_stream {
h264 {
width_pixels = 640
height_pixels = 360
bitrate_bps = 550000
frame_rate = 60
pixel_format = "yuv420p"
rate_control_mode = "vbr"
crf_level = 21
gop_duration = "3s"
vbv_size_bits = 550000
vbv_fullness_bits = 495000
entropy_coder = "cabac"
profile = "high"
preset = "veryfast"

}
}
}

elementary_streams {
key = "video-stream1"
video_stream {
h264 {
width_pixels = 1280
height_pixels = 720
bitrate_bps = 550000
frame_rate = 60
pixel_format = "yuv420p"
rate_control_mode = "vbr"
crf_level = 21
gop_duration = "3s"
vbv_size_bits = 2500000
vbv_fullness_bits = 2250000
entropy_coder = "cabac"
profile = "high"
preset = "veryfast"
}
}
}

elementary_streams {
key = "audio-stream0"
audio_stream {
codec = "aac"
bitrate_bps = 64000
channel_count = 2
channel_layout = ["fl", "fr"]
sample_rate_hertz = 48000
}
}

mux_streams {
key = "sd"
file_name = "sd.mp4"
container = "mp4"
elementary_streams = ["video-stream0", "audio-stream0"]
}

mux_streams {
key = "hd"
file_name = "hd.mp4"
container = "mp4"
elementary_streams = ["video-stream1", "audio-stream0"]
}

mux_streams {
key = "media-sd"
file_name = "media-sd.ts"
container = "ts"
elementary_streams = ["video-stream0", "audio-stream0"]
}

mux_streams {
key = "media-hd"
file_name = "media-hd.ts"
container = "ts"
elementary_streams = ["video-stream1", "audio-stream0"]
}

mux_streams {
key = "video-only-sd"
file_name = "video-only-sd.m4s"
container = "fmp4"
elementary_streams = ["video-stream0"]
}

mux_streams {
key = "video-only-hd"
file_name = "video-only-hd.m4s"
container = "fmp4"
elementary_streams = ["video-stream1"]
}

mux_streams {
key = "audio-only"
file_name = "audio-only.m4s"
container = "fmp4"
elementary_streams = ["audio-stream0"]
}

manifests {
file_name = "manifest.m3u8"
type = "HLS"
mux_streams = ["media-sd", "media-hd"]
}

manifests {
file_name = "manifest.mpd"
type = "DASH"
mux_streams = ["video-only-sd", "video-only-hd", "audio-only"]
}

output {
uri = "gs://${google_storage_bucket.default.name}/outputs/"
}
}
labels = {
"label" = "key"
}
}
7 changes: 7 additions & 0 deletions transcoder_job_manifests/motd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
===

These examples use real resources that will be billed to the
Google Cloud Platform project you use - so make sure that you
run "terraform destroy" before quitting!

===
Loading

0 comments on commit 1a7d905

Please sign in to comment.