14
14
# See the License for the specific language governing permissions and
15
15
# limitations under the License.
16
16
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.
18
18
19
19
Example usage:
20
20
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
22
22
"""
23
23
24
24
# [START transcoder_create_job_with_standalone_captions]
@@ -36,17 +36,20 @@ def create_job_with_standalone_captions(
36
36
project_id ,
37
37
location ,
38
38
input_video_uri ,
39
- input_captions_uri ,
39
+ input_subtitles1_uri ,
40
+ input_subtitles2_uri ,
40
41
output_uri ,
41
42
):
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.
43
44
44
45
Args:
45
46
project_id (str): The GCP project ID.
46
47
location (str): The location to start the job in.
47
48
input_video_uri (str): Uri of the input video in the Cloud Storage
48
49
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
50
53
Storage bucket.
51
54
output_uri (str): Uri of the video output folder in the Cloud Storage
52
55
bucket."""
@@ -63,14 +66,18 @@ def create_job_with_standalone_captions(
63
66
uri = input_video_uri ,
64
67
),
65
68
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 ,
68
75
),
69
76
],
70
77
edit_list = [
71
78
transcoder_v1 .types .EditAtom (
72
79
key = "atom0" ,
73
- inputs = ["input0" , "caption-input0 " ],
80
+ inputs = ["input0" , "subtitle-input-en" , "subtitle-input-es " ],
74
81
),
75
82
],
76
83
elementary_streams = [
@@ -88,18 +95,34 @@ def create_job_with_standalone_captions(
88
95
transcoder_v1 .types .ElementaryStream (
89
96
key = "audio-stream0" ,
90
97
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
+ ],
92
114
),
93
115
),
94
116
transcoder_v1 .types .ElementaryStream (
95
- key = "vtt-stream0 " ,
117
+ key = "vtt-stream-es " ,
96
118
text_stream = transcoder_v1 .types .TextStream (
97
119
codec = "webvtt" ,
120
+ language_code = "es-ES" ,
121
+ display_name = "Spanish" ,
98
122
mapping_ = [
99
123
transcoder_v1 .types .TextStream .TextMapping (
100
124
atom_key = "atom0" ,
101
- input_key = "caption-input0" ,
102
- input_track = 0 ,
125
+ input_key = "subtitle-input-es" ,
103
126
),
104
127
],
105
128
),
@@ -117,9 +140,20 @@ def create_job_with_standalone_captions(
117
140
elementary_streams = ["audio-stream0" ],
118
141
),
119
142
transcoder_v1 .types .MuxStream (
120
- key = "text-vtt" ,
143
+ key = "text-vtt-en " ,
121
144
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" ],
123
157
segment_settings = transcoder_v1 .types .SegmentSettings (
124
158
segment_duration = duration .Duration (
125
159
seconds = 6 ,
@@ -132,7 +166,12 @@ def create_job_with_standalone_captions(
132
166
transcoder_v1 .types .Manifest (
133
167
file_name = "manifest.m3u8" ,
134
168
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
+ ],
136
175
),
137
176
],
138
177
)
@@ -157,8 +196,13 @@ def create_job_with_standalone_captions(
157
196
required = True ,
158
197
)
159
198
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." ,
162
206
required = True ,
163
207
)
164
208
parser .add_argument (
@@ -172,6 +216,7 @@ def create_job_with_standalone_captions(
172
216
args .project_id ,
173
217
args .location ,
174
218
args .input_video_uri ,
175
- args .input_captions_uri ,
219
+ args .input_subtitles1_uri ,
220
+ args .input_subtitles2_uri ,
176
221
args .output_uri ,
177
222
)
0 commit comments