This repository was archived by the owner on Sep 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
chore: move samples from GoogleCloudPlatform/python-docs-samples #125
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Transcoder API Python Samples | ||
|
||
This directory contains samples for the Transcoder API. Use this API to transcode videos into a variety of formats. The Transcoder API benefits broadcasters, production companies, businesses, and individuals looking to transform their video content for use across a variety of user devices. For more information, see the [Transcoder API documentation](https://cloud.google.com/transcoder/). | ||
|
||
## Setup | ||
|
||
To run the samples, you need to first follow the steps in [Before you begin](https://cloud.google.com/transcoder/docs/how-to/before-you-begin). | ||
|
||
For more information on authentication, refer to the | ||
[Authentication Getting Started Guide](https://cloud.google.com/docs/authentication/getting-started). | ||
|
||
## Install Dependencies | ||
|
||
1. Clone python-docs-samples and change directory to the sample directory you want to use. | ||
|
||
$ git clone https://github.com/googleapis/python-video-transcoder.git | ||
|
||
1. Install [pip](https://pip.pypa.io/) and [virtualenv](https://virtualenv.pypa.io/) if you do not already have them. You may want to refer to the [Python Development Environment Setup Guide](https://cloud.google.com/python/setup) for Google Cloud Platform for instructions. | ||
|
||
1. Create a virtualenv. Samples are compatible with Python 3.6+. | ||
|
||
$ virtualenv env | ||
$ source env/bin/activate | ||
|
||
1. Install the dependencies needed to run the samples. | ||
|
||
$ pip install -r requirements.txt | ||
|
||
## The client library | ||
|
||
This sample uses the [Google Cloud Client Library for Python](https://googlecloudplatform.github.io/google-cloud-python/). | ||
You can read the documentation for more details on API usage and use GitHub | ||
to [browse the source](https://github.com/GoogleCloudPlatform/google-cloud-python) and [report issues](https://github.com/GoogleCloudPlatform/google-cloud-python/issues). | ||
|
||
## Testing | ||
|
||
Make sure to enable the Transcoder API on the test project. Set the following environment variables: | ||
|
||
* `GOOGLE_CLOUD_PROJECT` | ||
* `GOOGLE_CLOUD_PROJECT_NUMBER` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
#!/usr/bin/env python | ||
|
||
# Copyright 2020 Google Inc. All Rights Reserved. | ||
# | ||
# 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 based on a supplied job config. | ||
|
||
Example usage: | ||
python create_job_from_ad_hoc.py --project_id <project-id> --location <location> --input_uri <uri> --output_uri <uri> | ||
""" | ||
|
||
# [START transcoder_create_job_from_ad_hoc] | ||
|
||
import argparse | ||
|
||
from google.cloud.video import transcoder_v1 | ||
from google.cloud.video.transcoder_v1.services.transcoder_service import ( | ||
TranscoderServiceClient, | ||
) | ||
|
||
|
||
def create_job_from_ad_hoc(project_id, location, input_uri, output_uri): | ||
"""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.""" | ||
|
||
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.config = transcoder_v1.types.JobConfig( | ||
elementary_streams=[ | ||
transcoder_v1.types.ElementaryStream( | ||
key="video-stream0", | ||
video_stream=transcoder_v1.types.VideoStream( | ||
h264=transcoder_v1.types.VideoStream.H264CodecSettings( | ||
height_pixels=360, | ||
width_pixels=640, | ||
bitrate_bps=550000, | ||
frame_rate=60, | ||
), | ||
), | ||
), | ||
transcoder_v1.types.ElementaryStream( | ||
key="video-stream1", | ||
video_stream=transcoder_v1.types.VideoStream( | ||
h264=transcoder_v1.types.VideoStream.H264CodecSettings( | ||
height_pixels=720, | ||
width_pixels=1280, | ||
bitrate_bps=2500000, | ||
frame_rate=60, | ||
), | ||
), | ||
), | ||
transcoder_v1.types.ElementaryStream( | ||
key="audio-stream0", | ||
audio_stream=transcoder_v1.types.AudioStream( | ||
codec="aac", bitrate_bps=64000 | ||
), | ||
), | ||
], | ||
mux_streams=[ | ||
transcoder_v1.types.MuxStream( | ||
key="sd", | ||
container="mp4", | ||
elementary_streams=["video-stream0", "audio-stream0"], | ||
), | ||
transcoder_v1.types.MuxStream( | ||
key="hd", | ||
container="mp4", | ||
elementary_streams=["video-stream1", "audio-stream0"], | ||
), | ||
], | ||
) | ||
response = client.create_job(parent=parent, job=job) | ||
print(f"Job: {response.name}") | ||
return response | ||
|
||
|
||
# [END transcoder_create_job_from_ad_hoc] | ||
|
||
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, | ||
) | ||
args = parser.parse_args() | ||
create_job_from_ad_hoc( | ||
args.project_id, args.location, args.input_uri, args.output_uri, | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#!/usr/bin/env python | ||
|
||
# Copyright 2020 Google Inc. All Rights Reserved. | ||
# | ||
# 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 based on a job preset. | ||
|
||
Example usage: | ||
python create_job_from_preset.py --project_id <project-id> --location <location> --input_uri <uri> --output_uri <uri> [--preset <preset>] | ||
""" | ||
|
||
# [START transcoder_create_job_from_preset] | ||
|
||
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(project_id, location, input_uri, output_uri, preset): | ||
"""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').""" | ||
|
||
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 | ||
|
||
response = client.create_job(parent=parent, job=job) | ||
print(f"Job: {response.name}") | ||
return response | ||
|
||
|
||
# [END transcoder_create_job_from_preset] | ||
|
||
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( | ||
args.project_id, args.location, args.input_uri, args.output_uri, args.preset, | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#!/usr/bin/env python | ||
|
||
# Copyright 2020 Google Inc. All Rights Reserved. | ||
# | ||
# 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 based on a job template. | ||
|
||
Example usage: | ||
python create_job_from_template.py --project_id <project-id> --location <location> --input_uri <uri> --output_uri <uri> --template_id <template-id> | ||
""" | ||
|
||
# [START transcoder_create_job_from_template] | ||
|
||
import argparse | ||
|
||
from google.cloud.video import transcoder_v1 | ||
from google.cloud.video.transcoder_v1.services.transcoder_service import ( | ||
TranscoderServiceClient, | ||
) | ||
|
||
|
||
def create_job_from_template(project_id, location, input_uri, output_uri, template_id): | ||
"""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.""" | ||
|
||
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 = template_id | ||
|
||
response = client.create_job(parent=parent, job=job) | ||
print(f"Job: {response.name}") | ||
return response | ||
|
||
|
||
# [END transcoder_create_job_from_template] | ||
|
||
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( | ||
"--template_id", | ||
help="The job template ID. The template must be located in the same location as the job.", | ||
required=True, | ||
) | ||
args = parser.parse_args() | ||
create_job_from_template( | ||
args.project_id, | ||
args.location, | ||
args.input_uri, | ||
args.output_uri, | ||
args.template_id, | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: this link doesn't seem to show up properly, but feel free to address this in a different PR.