Skip to content

Commit 061183c

Browse files
irataxygcf-owl-bot[bot]
authored andcommitted
chore: move samples from GoogleCloudPlatform/python-docs-samples (#125)
* feat: move samples from GoogleCloudPlatform/python-docs-samples * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent b17fa1d commit 061183c

22 files changed

+2341
-0
lines changed

video/transcoder/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Transcoder API Python Samples
2+
3+
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/).
4+
5+
## Setup
6+
7+
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).
8+
9+
For more information on authentication, refer to the
10+
[Authentication Getting Started Guide](https://cloud.google.com/docs/authentication/getting-started).
11+
12+
## Install Dependencies
13+
14+
1. Clone python-docs-samples and change directory to the sample directory you want to use.
15+
16+
$ git clone https://github.com/googleapis/python-video-transcoder.git
17+
18+
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.
19+
20+
1. Create a virtualenv. Samples are compatible with Python 3.6+.
21+
22+
$ virtualenv env
23+
$ source env/bin/activate
24+
25+
1. Install the dependencies needed to run the samples.
26+
27+
$ pip install -r requirements.txt
28+
29+
## The client library
30+
31+
This sample uses the [Google Cloud Client Library for Python](https://googlecloudplatform.github.io/google-cloud-python/).
32+
You can read the documentation for more details on API usage and use GitHub
33+
to [browse the source](https://github.com/GoogleCloudPlatform/google-cloud-python) and [report issues](https://github.com/GoogleCloudPlatform/google-cloud-python/issues).
34+
35+
## Testing
36+
37+
Make sure to enable the Transcoder API on the test project. Set the following environment variables:
38+
39+
* `GOOGLE_CLOUD_PROJECT`
40+
* `GOOGLE_CLOUD_PROJECT_NUMBER`
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright 2020 Google Inc. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
"""Google Cloud Transcoder sample for creating a job based on a supplied job config.
18+
19+
Example usage:
20+
python create_job_from_ad_hoc.py --project_id <project-id> --location <location> --input_uri <uri> --output_uri <uri>
21+
"""
22+
23+
# [START transcoder_create_job_from_ad_hoc]
24+
25+
import argparse
26+
27+
from google.cloud.video import transcoder_v1
28+
from google.cloud.video.transcoder_v1.services.transcoder_service import (
29+
TranscoderServiceClient,
30+
)
31+
32+
33+
def create_job_from_ad_hoc(project_id, location, input_uri, output_uri):
34+
"""Creates a job based on an ad-hoc job configuration.
35+
36+
Args:
37+
project_id: The GCP project ID.
38+
location: The location to start the job in.
39+
input_uri: Uri of the video in the Cloud Storage bucket.
40+
output_uri: Uri of the video output folder in the Cloud Storage bucket."""
41+
42+
client = TranscoderServiceClient()
43+
44+
parent = f"projects/{project_id}/locations/{location}"
45+
job = transcoder_v1.types.Job()
46+
job.input_uri = input_uri
47+
job.output_uri = output_uri
48+
job.config = transcoder_v1.types.JobConfig(
49+
elementary_streams=[
50+
transcoder_v1.types.ElementaryStream(
51+
key="video-stream0",
52+
video_stream=transcoder_v1.types.VideoStream(
53+
h264=transcoder_v1.types.VideoStream.H264CodecSettings(
54+
height_pixels=360,
55+
width_pixels=640,
56+
bitrate_bps=550000,
57+
frame_rate=60,
58+
),
59+
),
60+
),
61+
transcoder_v1.types.ElementaryStream(
62+
key="video-stream1",
63+
video_stream=transcoder_v1.types.VideoStream(
64+
h264=transcoder_v1.types.VideoStream.H264CodecSettings(
65+
height_pixels=720,
66+
width_pixels=1280,
67+
bitrate_bps=2500000,
68+
frame_rate=60,
69+
),
70+
),
71+
),
72+
transcoder_v1.types.ElementaryStream(
73+
key="audio-stream0",
74+
audio_stream=transcoder_v1.types.AudioStream(
75+
codec="aac", bitrate_bps=64000
76+
),
77+
),
78+
],
79+
mux_streams=[
80+
transcoder_v1.types.MuxStream(
81+
key="sd",
82+
container="mp4",
83+
elementary_streams=["video-stream0", "audio-stream0"],
84+
),
85+
transcoder_v1.types.MuxStream(
86+
key="hd",
87+
container="mp4",
88+
elementary_streams=["video-stream1", "audio-stream0"],
89+
),
90+
],
91+
)
92+
response = client.create_job(parent=parent, job=job)
93+
print(f"Job: {response.name}")
94+
return response
95+
96+
97+
# [END transcoder_create_job_from_ad_hoc]
98+
99+
if __name__ == "__main__":
100+
parser = argparse.ArgumentParser()
101+
parser.add_argument("--project_id", help="Your Cloud project ID.", required=True)
102+
parser.add_argument(
103+
"--location", help="The location to start this job in.", default="us-central1",
104+
)
105+
parser.add_argument(
106+
"--input_uri",
107+
help="Uri of the video in the Cloud Storage bucket.",
108+
required=True,
109+
)
110+
parser.add_argument(
111+
"--output_uri",
112+
help="Uri of the video output folder in the Cloud Storage bucket. Must end in '/'.",
113+
required=True,
114+
)
115+
args = parser.parse_args()
116+
create_job_from_ad_hoc(
117+
args.project_id, args.location, args.input_uri, args.output_uri,
118+
)
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright 2020 Google Inc. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
"""Google Cloud Transcoder sample for creating a job based on a job preset.
18+
19+
Example usage:
20+
python create_job_from_preset.py --project_id <project-id> --location <location> --input_uri <uri> --output_uri <uri> [--preset <preset>]
21+
"""
22+
23+
# [START transcoder_create_job_from_preset]
24+
25+
import argparse
26+
27+
from google.cloud.video import transcoder_v1
28+
from google.cloud.video.transcoder_v1.services.transcoder_service import (
29+
TranscoderServiceClient,
30+
)
31+
32+
33+
def create_job_from_preset(project_id, location, input_uri, output_uri, preset):
34+
"""Creates a job based on a job preset.
35+
36+
Args:
37+
project_id: The GCP project ID.
38+
location: The location to start the job in.
39+
input_uri: Uri of the video in the Cloud Storage bucket.
40+
output_uri: Uri of the video output folder in the Cloud Storage bucket.
41+
preset: The preset template (for example, 'preset/web-hd')."""
42+
43+
client = TranscoderServiceClient()
44+
45+
parent = f"projects/{project_id}/locations/{location}"
46+
job = transcoder_v1.types.Job()
47+
job.input_uri = input_uri
48+
job.output_uri = output_uri
49+
job.template_id = preset
50+
51+
response = client.create_job(parent=parent, job=job)
52+
print(f"Job: {response.name}")
53+
return response
54+
55+
56+
# [END transcoder_create_job_from_preset]
57+
58+
if __name__ == "__main__":
59+
parser = argparse.ArgumentParser()
60+
parser.add_argument("--project_id", help="Your Cloud project ID.", required=True)
61+
parser.add_argument(
62+
"--location", help="The location to start this job in.", default="us-central1",
63+
)
64+
parser.add_argument(
65+
"--input_uri",
66+
help="Uri of the video in the Cloud Storage bucket.",
67+
required=True,
68+
)
69+
parser.add_argument(
70+
"--output_uri",
71+
help="Uri of the video output folder in the Cloud Storage bucket. Must end in '/'.",
72+
required=True,
73+
)
74+
parser.add_argument(
75+
"--preset",
76+
help="The preset template (for example, 'preset/web-hd').",
77+
default="preset/web-hd",
78+
)
79+
args = parser.parse_args()
80+
create_job_from_preset(
81+
args.project_id, args.location, args.input_uri, args.output_uri, args.preset,
82+
)
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright 2020 Google Inc. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
"""Google Cloud Transcoder sample for creating a job based on a job template.
18+
19+
Example usage:
20+
python create_job_from_template.py --project_id <project-id> --location <location> --input_uri <uri> --output_uri <uri> --template_id <template-id>
21+
"""
22+
23+
# [START transcoder_create_job_from_template]
24+
25+
import argparse
26+
27+
from google.cloud.video import transcoder_v1
28+
from google.cloud.video.transcoder_v1.services.transcoder_service import (
29+
TranscoderServiceClient,
30+
)
31+
32+
33+
def create_job_from_template(project_id, location, input_uri, output_uri, template_id):
34+
"""Creates a job based on a job template.
35+
36+
Args:
37+
project_id: The GCP project ID.
38+
location: The location to start the job in.
39+
input_uri: Uri of the video in the Cloud Storage bucket.
40+
output_uri: Uri of the video output folder in the Cloud Storage bucket.
41+
template_id: The user-defined template ID."""
42+
43+
client = TranscoderServiceClient()
44+
45+
parent = f"projects/{project_id}/locations/{location}"
46+
job = transcoder_v1.types.Job()
47+
job.input_uri = input_uri
48+
job.output_uri = output_uri
49+
job.template_id = template_id
50+
51+
response = client.create_job(parent=parent, job=job)
52+
print(f"Job: {response.name}")
53+
return response
54+
55+
56+
# [END transcoder_create_job_from_template]
57+
58+
if __name__ == "__main__":
59+
parser = argparse.ArgumentParser()
60+
parser.add_argument("--project_id", help="Your Cloud project ID.", required=True)
61+
parser.add_argument(
62+
"--location", help="The location to start this job in.", default="us-central1",
63+
)
64+
parser.add_argument(
65+
"--input_uri",
66+
help="Uri of the video in the Cloud Storage bucket.",
67+
required=True,
68+
)
69+
parser.add_argument(
70+
"--output_uri",
71+
help="Uri of the video output folder in the Cloud Storage bucket. Must end in '/'.",
72+
required=True,
73+
)
74+
parser.add_argument(
75+
"--template_id",
76+
help="The job template ID. The template must be located in the same location as the job.",
77+
required=True,
78+
)
79+
args = parser.parse_args()
80+
create_job_from_template(
81+
args.project_id,
82+
args.location,
83+
args.input_uri,
84+
args.output_uri,
85+
args.template_id,
86+
)

0 commit comments

Comments
 (0)