Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions video/transcoder/create_job_from_ad_hoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,23 @@
)


def create_job_from_ad_hoc(project_id, location, input_uri, output_uri):
def create_job_from_ad_hoc(
project_id: str,
location: str,
input_uri: str,
output_uri: str,
) -> transcoder_v1.types.resources.Job:
"""Creates a job based on an ad-hoc job configuration.

Args:
project_id: The GCP project ID.
location: The location to start the job in.
input_uri: Uri of the video in the Cloud Storage bucket.
output_uri: Uri of the video output folder in the Cloud Storage bucket."""
output_uri: Uri of the video output folder in the Cloud Storage bucket.

Returns:
The job resource.
"""

client = TranscoderServiceClient()

Expand Down
14 changes: 12 additions & 2 deletions video/transcoder/create_job_from_preset.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,25 @@
)


def create_job_from_preset(project_id, location, input_uri, output_uri, preset):
def create_job_from_preset(
project_id: str,
location: str,
input_uri: str,
output_uri: str,
preset: str,
) -> transcoder_v1.types.resources.Job:
"""Creates a job based on a job preset.

Args:
project_id: The GCP project ID.
location: The location to start the job in.
input_uri: Uri of the video in the Cloud Storage bucket.
output_uri: Uri of the video output folder in the Cloud Storage bucket.
preset: The preset template (for example, 'preset/web-hd')."""
preset: The preset template (for example, 'preset/web-hd').

Returns:
The job resource.
"""

client = TranscoderServiceClient()

Expand Down
101 changes: 101 additions & 0 deletions video/transcoder/create_job_from_preset_batch_mode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/usr/bin/env python

# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Google Cloud Transcoder sample for creating a job in batch mode based on a
job preset.

Example usage:
python create_job_from_preset_batch_mode.py --project_id <project-id> --location <location> --input_uri <uri> --output_uri <uri> [--preset <preset>]
"""

# [START transcoder_create_job_from_preset_batch_mode]

import argparse

from google.cloud.video import transcoder_v1
from google.cloud.video.transcoder_v1.services.transcoder_service import (
TranscoderServiceClient,
)


def create_job_from_preset_batch_mode(
Comment thread
irataxy marked this conversation as resolved.
project_id: str,
location: str,
input_uri: str,
output_uri: str,
preset: str,
) -> transcoder_v1.types.resources.Job:
"""Creates a job in batch mode based on a job preset.

Args:
project_id: The GCP project ID.
location: The location to start the job in.
input_uri: Uri of the video in the Cloud Storage bucket.
output_uri: Uri of the video output folder in the Cloud Storage bucket.
preset: The preset template (for example, 'preset/web-hd').

Returns:
The job resource.
"""

client = TranscoderServiceClient()

parent = f"projects/{project_id}/locations/{location}"
job = transcoder_v1.types.Job()
job.input_uri = input_uri
job.output_uri = output_uri
job.template_id = preset
job.mode = transcoder_v1.types.Job.ProcessingMode.PROCESSING_MODE_BATCH
job.batch_mode_priority = 10

response = client.create_job(parent=parent, job=job)
print(f"Job: {response.name}")
return response


# [END transcoder_create_job_from_preset_batch_mode]

if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--project_id", help="Your Cloud project ID.", required=True)
parser.add_argument(
"--location",
help="The location to start this job in.",
default="us-central1",
)
parser.add_argument(
"--input_uri",
help="Uri of the video in the Cloud Storage bucket.",
required=True,
)
parser.add_argument(
"--output_uri",
help="Uri of the video output folder in the Cloud Storage bucket. Must end in '/'.",
required=True,
)
parser.add_argument(
"--preset",
help="The preset template (for example, 'preset/web-hd').",
default="preset/web-hd",
)
args = parser.parse_args()
create_job_from_preset_batch_mode(
args.project_id,
args.location,
args.input_uri,
args.output_uri,
args.preset,
)
14 changes: 12 additions & 2 deletions video/transcoder/create_job_from_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,25 @@
)


def create_job_from_template(project_id, location, input_uri, output_uri, template_id):
def create_job_from_template(
project_id: str,
location: str,
input_uri: str,
output_uri: str,
template_id: str,
) -> transcoder_v1.types.resources.Job:
"""Creates a job based on a job template.

Args:
project_id: The GCP project ID.
location: The location to start the job in.
input_uri: Uri of the video in the Cloud Storage bucket.
output_uri: Uri of the video output folder in the Cloud Storage bucket.
template_id: The user-defined template ID."""
template_id: The user-defined template ID.

Returns:
The job resource.
"""

client = TranscoderServiceClient()

Expand Down
12 changes: 10 additions & 2 deletions video/transcoder/create_job_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,21 @@
)


def create_job_template(project_id, location, template_id):
def create_job_template(
project_id: str,
location: str,
template_id: str,
) -> transcoder_v1.types.resources.JobTemplate:
"""Creates a job template.

Args:
project_id: The GCP project ID.
location: The location to store this template in.
template_id: The user-defined template ID."""
template_id: The user-defined template ID.

Returns:
The job template resource.
"""

client = TranscoderServiceClient()

Expand Down
14 changes: 11 additions & 3 deletions video/transcoder/create_job_with_animated_overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,24 @@


def create_job_with_animated_overlay(
project_id, location, input_uri, overlay_image_uri, output_uri
):
project_id: str,
location: str,
input_uri: str,
overlay_image_uri: str,
output_uri: str,
) -> transcoder_v1.types.resources.Job:
"""Creates a job based on an ad-hoc job configuration that includes an animated image overlay.

Args:
project_id: The GCP project ID.
location: The location to start the job in.
input_uri: Uri of the video in the Cloud Storage bucket.
overlay_image_uri: Uri of the image for the overlay in the Cloud Storage bucket.
output_uri: Uri of the video output folder in the Cloud Storage bucket."""
output_uri: Uri of the video output folder in the Cloud Storage bucket.

Returns:
The job resource.
"""

client = TranscoderServiceClient()

Expand Down
26 changes: 15 additions & 11 deletions video/transcoder/create_job_with_concatenated_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@


def create_job_with_concatenated_inputs(
project_id,
location,
input1_uri,
start_time_input1,
end_time_input1,
input2_uri,
start_time_input2,
end_time_input2,
output_uri,
):
project_id: str,
location: str,
input1_uri: str,
start_time_input1: str,
end_time_input1: str,
input2_uri: str,
start_time_input2: str,
end_time_input2: str,
output_uri: str,
) -> transcoder_v1.types.resources.Job:
"""Creates a job based on an ad-hoc job configuration that concatenates two input videos.

Args:
Expand All @@ -61,7 +61,11 @@ def create_job_with_concatenated_inputs(
end_time_input2 (str): End time, in fractional seconds ending in 's'
(e.g., '15s'), relative to the second input video timeline.
output_uri (str): Uri of the video output folder in the Cloud Storage
bucket."""
bucket.

Returns:
The job resource.
"""

s1 = duration.Duration()
s1.FromJsonString(start_time_input1)
Expand Down
18 changes: 11 additions & 7 deletions video/transcoder/create_job_with_embedded_captions.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@


def create_job_with_embedded_captions(
project_id,
location,
input_video_uri,
input_captions_uri,
output_uri,
):
project_id: str,
location: str,
input_video_uri: str,
input_captions_uri: str,
output_uri: str,
) -> transcoder_v1.types.resources.Job:
"""Creates a job based on an ad-hoc job configuration that embeds closed captions in the output video.

Args:
Expand All @@ -48,7 +48,11 @@ def create_job_with_embedded_captions(
input_captions_uri (str): Uri of the input captions file in the Cloud
Storage bucket.
output_uri (str): Uri of the video output folder in the Cloud Storage
bucket."""
bucket.

Returns:
The job resource.
"""

client = TranscoderServiceClient()

Expand Down
13 changes: 10 additions & 3 deletions video/transcoder/create_job_with_periodic_images_spritesheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,22 @@


def create_job_with_periodic_images_spritesheet(
project_id, location, input_uri, output_uri
):
project_id: str,
location: str,
input_uri: str,
output_uri: str,
) -> transcoder_v1.types.resources.Job:
"""Creates a job based on an ad-hoc job configuration that generates two spritesheets.

Args:
project_id: The GCP project ID.
location: The location to start the job in.
input_uri: Uri of the video in the Cloud Storage bucket.
output_uri: Uri of the video output folder in the Cloud Storage bucket."""
output_uri: Uri of the video output folder in the Cloud Storage bucket.

Returns:
The job resource.
"""

client = TranscoderServiceClient()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,22 @@


def create_job_with_set_number_images_spritesheet(
project_id, location, input_uri, output_uri
):
project_id: str,
location: str,
input_uri: str,
output_uri: str,
) -> transcoder_v1.types.resources.Job:
"""Creates a job based on an ad-hoc job configuration that generates two spritesheets.

Args:
project_id: The GCP project ID.
location: The location to start the job in.
input_uri: Uri of the video in the Cloud Storage bucket.
output_uri: Uri of the video output folder in the Cloud Storage bucket."""
output_uri: Uri of the video output folder in the Cloud Storage bucket.

Returns:
The job resource.
"""

client = TranscoderServiceClient()

Expand Down
20 changes: 12 additions & 8 deletions video/transcoder/create_job_with_standalone_captions.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@


def create_job_with_standalone_captions(
project_id,
location,
input_video_uri,
input_subtitles1_uri,
input_subtitles2_uri,
output_uri,
):
project_id: str,
location: str,
input_video_uri: str,
input_subtitles1_uri: str,
input_subtitles2_uri: str,
output_uri: str,
) -> transcoder_v1.types.resources.Job:
"""Creates a job based on an ad-hoc job configuration that can use subtitles from a standalone file.

Args:
Expand All @@ -52,7 +52,11 @@ def create_job_with_standalone_captions(
input_subtitles2_uri (str): Uri of an input subtitles file in the Cloud
Storage bucket.
output_uri (str): Uri of the video output folder in the Cloud Storage
bucket."""
bucket.

Returns:
The job resource.
"""

client = TranscoderServiceClient()

Expand Down
Loading