Skip to content
This repository was archived by the owner on Sep 21, 2023. It is now read-only.

Commit 10adada

Browse files
authored
feat(Transcoder): update captions code samples for display name and l… (#292)
* feat(Transcoder): update captions code samples for display name and language * test bucket should be deleted * Trigger Build
1 parent 184e177 commit 10adada

File tree

3 files changed

+75
-27
lines changed

3 files changed

+75
-27
lines changed

samples/snippets/create_job_with_embedded_captions.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def create_job_with_embedded_captions(
3838
input_captions_uri,
3939
output_uri,
4040
):
41-
"""Creates a job based on an ad-hoc job configuration that embeds captions in the output video.
41+
"""Creates a job based on an ad-hoc job configuration that embeds closed captions in the output video.
4242
4343
Args:
4444
project_id (str): The GCP project ID.
@@ -87,7 +87,8 @@ def create_job_with_embedded_captions(
8787
transcoder_v1.types.ElementaryStream(
8888
key="audio-stream0",
8989
audio_stream=transcoder_v1.types.AudioStream(
90-
codec="aac", bitrate_bps=64000
90+
codec="aac",
91+
bitrate_bps=64000,
9192
),
9293
),
9394
transcoder_v1.types.ElementaryStream(
@@ -101,15 +102,12 @@ def create_job_with_embedded_captions(
101102
input_track=0,
102103
),
103104
],
105+
language_code="en-US",
106+
display_name="English",
104107
),
105108
),
106109
],
107110
mux_streams=[
108-
transcoder_v1.types.MuxStream(
109-
key="sd",
110-
container="mp4",
111-
elementary_streams=["video-stream0", "audio-stream0"],
112-
),
113111
transcoder_v1.types.MuxStream(
114112
key="sd-hls",
115113
container="ts",

samples/snippets/create_job_with_standalone_captions.py

Lines changed: 63 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
"""Google Cloud Transcoder sample for creating a job that can use captions from a standalone file.
17+
"""Google Cloud Transcoder sample for creating a job that can use subtitles from a standalone file.
1818
1919
Example usage:
2020
python create_job_with_standalone_captions.py --project_id --location \
21-
--input_video_uri --input_captions_uri --output_uri
21+
--input_video_uri --input_subtitles1_uri --input_subtitles2_uri --output_uri
2222
"""
2323

2424
# [START transcoder_create_job_with_standalone_captions]
@@ -36,17 +36,20 @@ def create_job_with_standalone_captions(
3636
project_id,
3737
location,
3838
input_video_uri,
39-
input_captions_uri,
39+
input_subtitles1_uri,
40+
input_subtitles2_uri,
4041
output_uri,
4142
):
42-
"""Creates a job based on an ad-hoc job configuration that can use captions from a standalone file.
43+
"""Creates a job based on an ad-hoc job configuration that can use subtitles from a standalone file.
4344
4445
Args:
4546
project_id (str): The GCP project ID.
4647
location (str): The location to start the job in.
4748
input_video_uri (str): Uri of the input video in the Cloud Storage
4849
bucket.
49-
input_captions_uri (str): Uri of the input captions file in the Cloud
50+
input_subtitles1_uri (str): Uri of an input subtitles file in the Cloud
51+
Storage bucket.
52+
input_subtitles2_uri (str): Uri of an input subtitles file in the Cloud
5053
Storage bucket.
5154
output_uri (str): Uri of the video output folder in the Cloud Storage
5255
bucket."""
@@ -63,14 +66,18 @@ def create_job_with_standalone_captions(
6366
uri=input_video_uri,
6467
),
6568
transcoder_v1.types.Input(
66-
key="caption-input0",
67-
uri=input_captions_uri,
69+
key="subtitle-input-en",
70+
uri=input_subtitles1_uri,
71+
),
72+
transcoder_v1.types.Input(
73+
key="subtitle-input-es",
74+
uri=input_subtitles2_uri,
6875
),
6976
],
7077
edit_list=[
7178
transcoder_v1.types.EditAtom(
7279
key="atom0",
73-
inputs=["input0", "caption-input0"],
80+
inputs=["input0", "subtitle-input-en", "subtitle-input-es"],
7481
),
7582
],
7683
elementary_streams=[
@@ -88,18 +95,34 @@ def create_job_with_standalone_captions(
8895
transcoder_v1.types.ElementaryStream(
8996
key="audio-stream0",
9097
audio_stream=transcoder_v1.types.AudioStream(
91-
codec="aac", bitrate_bps=64000
98+
codec="aac",
99+
bitrate_bps=64000,
100+
),
101+
),
102+
transcoder_v1.types.ElementaryStream(
103+
key="vtt-stream-en",
104+
text_stream=transcoder_v1.types.TextStream(
105+
codec="webvtt",
106+
language_code="en-US",
107+
display_name="English",
108+
mapping_=[
109+
transcoder_v1.types.TextStream.TextMapping(
110+
atom_key="atom0",
111+
input_key="subtitle-input-en",
112+
),
113+
],
92114
),
93115
),
94116
transcoder_v1.types.ElementaryStream(
95-
key="vtt-stream0",
117+
key="vtt-stream-es",
96118
text_stream=transcoder_v1.types.TextStream(
97119
codec="webvtt",
120+
language_code="es-ES",
121+
display_name="Spanish",
98122
mapping_=[
99123
transcoder_v1.types.TextStream.TextMapping(
100124
atom_key="atom0",
101-
input_key="caption-input0",
102-
input_track=0,
125+
input_key="subtitle-input-es",
103126
),
104127
],
105128
),
@@ -117,9 +140,20 @@ def create_job_with_standalone_captions(
117140
elementary_streams=["audio-stream0"],
118141
),
119142
transcoder_v1.types.MuxStream(
120-
key="text-vtt",
143+
key="text-vtt-en",
121144
container="vtt",
122-
elementary_streams=["vtt-stream0"],
145+
elementary_streams=["vtt-stream-en"],
146+
segment_settings=transcoder_v1.types.SegmentSettings(
147+
segment_duration=duration.Duration(
148+
seconds=6,
149+
),
150+
individual_segments=True,
151+
),
152+
),
153+
transcoder_v1.types.MuxStream(
154+
key="text-vtt-es",
155+
container="vtt",
156+
elementary_streams=["vtt-stream-es"],
123157
segment_settings=transcoder_v1.types.SegmentSettings(
124158
segment_duration=duration.Duration(
125159
seconds=6,
@@ -132,7 +166,12 @@ def create_job_with_standalone_captions(
132166
transcoder_v1.types.Manifest(
133167
file_name="manifest.m3u8",
134168
type_="HLS",
135-
mux_streams=["sd-hls-fmp4", "audio-hls-fmp4", "text-vtt"],
169+
mux_streams=[
170+
"sd-hls-fmp4",
171+
"audio-hls-fmp4",
172+
"text-vtt-en",
173+
"text-vtt-es",
174+
],
136175
),
137176
],
138177
)
@@ -157,8 +196,13 @@ def create_job_with_standalone_captions(
157196
required=True,
158197
)
159198
parser.add_argument(
160-
"--input_captions_uri",
161-
help="Uri of the input captions file in the Cloud Storage bucket.",
199+
"--input_subtitles1_uri",
200+
help="Uri of an input subtitles file in the Cloud Storage bucket.",
201+
required=True,
202+
)
203+
parser.add_argument(
204+
"--input_subtitles2_uri",
205+
help="Uri of an input subtitles file in the Cloud Storage bucket.",
162206
required=True,
163207
)
164208
parser.add_argument(
@@ -172,6 +216,7 @@ def create_job_with_standalone_captions(
172216
args.project_id,
173217
args.location,
174218
args.input_video_uri,
175-
args.input_captions_uri,
219+
args.input_subtitles1_uri,
220+
args.input_subtitles2_uri,
176221
args.output_uri,
177222
)

samples/snippets/job_test.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,17 @@
4949
test_overlay_image_file_name = "overlay.jpg"
5050
test_concat1_file_name = "ForBiggerEscapes.mp4"
5151
test_concat2_file_name = "ForBiggerJoyrides.mp4"
52-
test_captions_file_name = "caption.srt"
52+
test_captions_file_name = "captions.srt"
53+
test_subtitles1_file_name = "subtitles-en.srt"
54+
test_subtitles2_file_name = "subtitles-es.srt"
5355

5456
input_uri = f"gs://{input_bucket_name}{test_video_file_name}"
5557
overlay_image_uri = f"gs://{input_bucket_name}{test_overlay_image_file_name}"
5658
concat1_uri = f"gs://{input_bucket_name}{test_concat1_file_name}"
5759
concat2_uri = f"gs://{input_bucket_name}{test_concat2_file_name}"
5860
captions_uri = f"gs://{input_bucket_name}{test_captions_file_name}"
61+
subtitles1_uri = f"gs://{input_bucket_name}{test_subtitles1_file_name}"
62+
subtitles2_uri = f"gs://{input_bucket_name}{test_subtitles2_file_name}"
5963
output_uri_for_preset = f"gs://{output_bucket_name}/test-output-preset/"
6064
output_uri_for_template = f"gs://{output_bucket_name}/test-output-template/"
6165
output_uri_for_adhoc = f"gs://{output_bucket_name}/test-output-adhoc/"
@@ -452,7 +456,8 @@ def test_create_job_with_standalone_captions(capsys, test_bucket):
452456
project_id,
453457
location,
454458
input_uri,
455-
captions_uri,
459+
subtitles1_uri,
460+
subtitles2_uri,
456461
output_uri_for_standalone_captions,
457462
)
458463
out, _ = capsys.readouterr()

0 commit comments

Comments
 (0)