8000 feat: update Transcoder API samples to v1 (#6561) · orossini/python-docs-samples@7549e24 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7549e24

Browse files
authored
feat: update Transcoder API samples to v1 (GoogleCloudPlatform#6561)
## Description Fixes b:184919153 Note: It's a good idea to open an issue first for discussion. ## Checklist - [X] I have followed [Sample Guidelines from AUTHORING_GUIDE.MD](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/AUTHORING_GUIDE.md) - [] README is updated to include [all relevant information](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/AUTHORING_GUIDE.md#readme-file) - [X] **Tests** pass: `nox -s py-3.6` (see [Test Environment Setup](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/AUTHORING_GUIDE.md#test-environment-setup)) - [X] **Lint** pass: `nox -s lint` (see [Test Environment Setup](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/AUTHORING_GUIDE.md#test-environment-setup)) - [ ] These samples need a new **API enabled** in testing projects to pass (let us know which ones) - [ ] These samples need a new/updated **env vars** in testing projects set to pass (let us know which ones) - [X] Please **merge** this PR for me once it is approved. - [ ] This sample adds a new sample directory, and I updated the [CODEOWNERS file](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/.github/CODEOWNERS) with the codeowners for this sample
1 parent 781da71 commit 7549e24

16 files changed

+197
-184
lines changed

media/transcoder/create_job_from_ad_hoc.py

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
"""Google Cloud Transcoder sample for creating a job based on a supplied job config.
1818
1919
Example usage:
20-
python create_job_from_ad_hoc.py --project-id <project-id> --location <location> --input-uri <uri> --output-uri <uri>
20+
python create_job_from_ad_hoc.py --project_id <project-id> --location <location> --input_uri <uri> --output_uri <uri>
2121
"""
2222

2323
# [START transcoder_create_job_from_ad_hoc]
2424

2525
import argparse
2626

27-
from google.cloud.video import transcoder_v1beta1
28-
from google.cloud.video.transcoder_v1beta1.services.transcoder_service import (
27+
from google.cloud.video import transcoder_v1
28+
from google.cloud.video.transcoder_v1.services.transcoder_service import (
2929
TranscoderServiceClient,
3030
)
3131

@@ -42,45 +42,47 @@ def create_job_from_ad_hoc(project_id, location, input_uri, output_uri):
4242
client = TranscoderServiceClient()
4343

4444
parent = f"projects/{project_id}/locations/{location}"
45-
job = transcoder_v1beta1.types.Job()
45+
job = transcoder_v1.types.Job()
4646
job.input_uri = input_uri
4747
job.output_uri = output_uri
48-
job.config = transcoder_v1beta1.types.JobConfig(
48+
job.config = transcoder_v1.types.JobConfig(
4949
elementary_streams=[
50-
transcoder_v1beta1.types.ElementaryStream(
50+
transcoder_v1.types.ElementaryStream(
5151
key="video-stream0",
52-
video_stream=transcoder_v1beta1.types.VideoStream(
53-
codec="h264",
54-
height_pixels=360,
55-
width_pixels=640,
56-
bitrate_bps=550000,
57-
frame_rate=60,
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+
),
5859
),
5960
),
60-
transcoder_v1beta1.types.ElementaryStream(
61+
transcoder_v1.types.ElementaryStream(
6162
key="video-stream1",
62-
video_stream=transcoder_v1beta1.types.VideoStream(
63-
codec="h264",
64-
height_pixels=720,
65-
width_pixels=1280,
66-
bitrate_bps=2500000,
67-
frame_rate=60,
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 1E0A +
frame_rate=60,
69+
),
6870
),
6971
),
70-
transcoder_v1beta1.types.ElementaryStream(
72+
transcoder_v1.types.ElementaryStream(
7173
key="audio-stream0",
72-
audio_stream=transcoder_v1beta1.types.AudioStream(
74+
audio_stream=transcoder_v1.types.AudioStream(
7375
codec="aac", bitrate_bps=64000
7476
),
7577
),
7678
],
7779
mux_streams=[
78-
transcoder_v1beta1.types.MuxStream(
80+
transcoder_v1.types.MuxStream(
7981
key="sd",
8082
container="mp4",
8183
elementary_streams=["video-stream0", "audio-stream0"],
8284
),
83-
transcoder_v1beta1.types.MuxStream(
85+
transcoder_v1.types.MuxStream(
8486
key="hd",
8587
container="mp4",
8688
elementary_streams=["video-stream1", "audio-stream0"],
@@ -96,7 +98,7 @@ def create_job_from_ad_hoc(project_id, location, input_uri, output_uri):
9698

9799
if __name__ == "__main__":
98100
parser = argparse.ArgumentParser()
99-
parser.add_argument("--project-id", help="Your Cloud project ID.", required=True)
101+
parser.add_argument("--project_id", help="Your Cloud project ID.", required=True)
100102
parser.add_argument(
101103
"--location",
102104
help="The location to start this job in.",

media/transcoder/create_job_from_preset.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
"""Google Cloud Transcoder sample for creating a job based on a job preset.
1818
1919
Example usage:
20-
python create_job_from_preset.py --project-id <project-id> --location <location> --input-uri <uri> --output-uri <uri> [--preset <preset>]
20+
python create_job_from_preset.py --project_id <project-id> --location <location> --input_uri <uri> --output_uri <uri> [--preset <preset>]
2121
"""
2222

2323
# [START transcoder_create_job_from_preset]
2424

2525
import argparse
2626

27-
from google.cloud.video import transcoder_v1beta1
28-
from google.cloud.video.transcoder_v1beta1.services.transcoder_service import (
27+
from google.cloud.video import transcoder_v1
28+
from google.cloud.video.transcoder_v1.services.transcoder_service import (
2929
TranscoderServiceClient,
3030
)
3131

@@ -43,7 +43,7 @@ def create_job_from_preset(project_id, location, input_uri, output_uri, preset):
4343
client = TranscoderServiceClient()
4444

4545
parent = f"projects/{project_id}/locations/{location}"
46-
job = transcoder_v1beta1.types.Job()
46+
job = transcoder_v1.types.Job()
4747
job.input_uri = input_uri
4848
job.output_uri = output_uri
4949
job.template_id = preset
@@ -57,7 +57,7 @@ def create_job_from_preset(project_id, location, input_uri, output_uri, preset):
5757

5858
if __name__ == "__main__":
5959
parser = argparse.ArgumentParser()
60-
parser.add_argument("--project-id", help="Your Cloud project ID.", required=True)
60+
parser.add_argument("--project_id", help="Your Cloud project ID.", required=True)
6161
parser.add_argument(
6262
"--location",
6363
help="The location to start this job in.",

media/transcoder/create_job_from_template.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
"""Google Cloud Transcoder sample for creating a job based on a job template.
1818
1919
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>
20+
python create_job_from_template.py --project_id <project-id> --location <location> --input_uri <uri> --output_uri <uri> --template_id <template-id>
2121
"""
2222

2323
# [START transcoder_create_job_from_template]
2424

2525
import argparse
2626

27-
from google.cloud.video import transcoder_v1beta1
28-
from google.cloud.video.transcoder_v1beta1.services.transcoder_service import (
27+
from google.cloud.video import transcoder_v1
28+
from google.cloud.video.transcoder_v1.services.transcoder_service import (
2929
TranscoderServiceClient,
3030
)
3131

@@ -43,7 +43,7 @@ def create_job_from_template(project_id, location, input_uri, output_uri, templa
4343
client = TranscoderServiceClient()
4444

4545
parent = f"projects/{project_id}/locations/{location}"
46-
job = transcoder_v1beta1.types.Job()
46+
job = transcoder_v1.types.Job()
4747
job.input_uri = input_uri
4848
job.output_uri = output_uri
4949
job.template_id = template_id
@@ -57,7 +57,7 @@ def create_job_from_template(project_id, location, input_uri, output_uri, templa
5757

5858
if __name__ == "__main__":
5959
parser = argparse.ArgumentParser()
60-
parser.add_argument("--project-id", help="Your Cloud project ID.", required=True)
60+
parser.add_argument("--project_id", help="Your Cloud project ID.", required=True)
6161
parser.add_argument(
6262
"--location",
6363
help="The location to start this job in.",
@@ -74,7 +74,7 @@ def create_job_from_template(project_id, location, input_uri, output_uri, templa
7474
required=True,
7575
)
7676
parser.add_argument(
77-
"--template-id",
77+
"--template_id",
7878
help="The job template ID. The template must be located in the same location as the job.",
7979
required=True,
8080
)

media/transcoder/create_job_template.py

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
"""Google Cloud Transcoder sample for creating a job template.
1818
1919
Example usage:
20-
python create_job_template.py --project-id <project-id> [--location <location>] [--template-id <template-id>]
20+
python create_job_template.py --project_id <project-id> [--location <location>] [--template_id <template-id>]
2121
"""
2222

2323
# [START transcoder_create_job_template]
2424

2525
import argparse
2626

27-
from google.cloud.video import transcoder_v1beta1
28-
from google.cloud.video.transcoder_v1beta1.services.transcoder_service import (
27+
from google.cloud.video import transcoder_v1
28+
from google.cloud.video.transcoder_v1.services.transcoder_service import (
2929
TranscoderServiceClient,
3030
)
3131

@@ -42,46 +42,48 @@ def create_job_template(project_id, location, template_id):
4242

4343
parent = f"projects/{project_id}/locations/{location}"
4444

45-
job_template = transcoder_v1beta1.types.JobTemplate()
45+
job_template = transcoder_v1.types.JobTemplate()
4646
job_template.name = (
4747
f"projects/{project_id}/locations/{location}/jobTemplates/{template_id}"
4848
)
49-
job_template.config = transcoder_v1beta1.types.JobConfig(
49+
job_template.config = transcoder_v1.types.JobConfig(
5050
elementary_streams=[
51-
transcoder_v1beta1.types.ElementaryStream(
51+
transcoder_v1.types.ElementaryStream(
5252
key="video-stream0",
53-
video_stream=transcoder_v1beta1.types.VideoStream(
54-
codec="h264",
55-
height_pixels=360,
56-
width_pixels=640,
57-
bitrate_bps=550000,
58-
frame_rate=60,
53+
video_stream=transcoder_v1.types.VideoStream(
54+
h264=transcoder_v1.types.VideoStream.H264CodecSettings(
55+
height_pixels=360,
56+
width_pixels=640,
57+
bitrate_bps=550000,
58+
frame_rate=60,
59+
),
5960
),
6061
),
61-
transcoder_v1beta1.types.ElementaryStream(
62+
transcoder_v1.types.ElementaryStream(
6263
key="video-stream1",
63-
video_stream=transcoder_v1beta1.types.VideoStream(
64-
codec="h264",
65-
height_pixels=720,
66-
width_pixels=1280,
67-
bitrate_bps=2500000,
68-
frame_rate=60,
64+
video_stream=transcoder_v1.types.VideoStream(
65+
h264=transcoder_v1.types.VideoStream.H264CodecSettings(
66+
height_pixels=720,
67+
width_pixels=1280,
68+
bitrate_bps=2500000,
69+
frame_rate=60,
70+
),
6971
),
7072
),
71-
transcoder_v1beta1.types.ElementaryStream(
73+
transcoder_v1.types.ElementaryStream(
7274
key="audio-stream0",
73-
audio_stream=transcoder_v1beta1.types.AudioStream(
75+
audio_stream=transcoder_v1.types.AudioStream(
7476
codec="aac", bitrate_bps=64000
7577
),
7678
),
7779
],
7880
mux_streams=[
79-
transcoder_v1beta1.types.MuxStream(
81+
transcoder_v1.types.MuxStream(
8082
key="sd",
8183
container="mp4",
8284
elementary_streams=["video-stream0", "audio-stream0"],
8385
),
84-
transcoder_v1beta1.types.MuxStream(
86+
transcoder_v1.types.MuxStream(
8587
key="hd",
8688
container="mp4",
8789
elementary_streams=["video-stream1", "audio-stream0"],
@@ -100,14 +102,14 @@ def create_job_template(project_id, location, template_id):
100102

101103
if __name__ == "__main__":
102104
parser = argparse.ArgumentParser()
103-
parser.add_argument("--project-id", help="Your Cloud project ID.", required=True)
105+
parser.add_argument("--project_id", help="Your Cloud project ID.", required=True)
104106
parser.add_argument(
105107
"--location",
106108
help="The location to store this template in.",
107109
default="us-central1",
108110
)
109111
parser.add_argument(
110-
"--template-id", help="The job template ID.", default="my-job-template"
112+
"--template_id", help="The job template ID.", default="my-job-template"
111113
)
112114
args = parser.parse_args()
113115
create_job_template(args.project_id, args.location, args.template_id)

0 commit comments

Comments
 (0)
0