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
1919Example usage:
2020 python create_job_with_standalone_captions.py --project_id <project-id> --location <location> \
21- --input_video_uri <uri> --input_captions_uri <uri> --output_uri <uri>
21+ --input_video_uri <uri> --input_subtitles1_uri <uri> --input_subtitles2_uri <uri> --output_uri <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 )
0 commit comments