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

docs(samples): update captions code samples for display name and language #292

Merged
merged 6 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions samples/snippets/create_job_with_embedded_captions.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def create_job_with_embedded_captions(
input_captions_uri,
output_uri,
):
"""Creates a job based on an ad-hoc job configuration that embeds captions in the output video.
"""Creates a job based on an ad-hoc job configuration that embeds closed captions in the output video.

Args:
project_id (str): The GCP project ID.
Expand Down Expand Up @@ -87,7 +87,8 @@ def create_job_with_embedded_captions(
transcoder_v1.types.ElementaryStream(
key="audio-stream0",
audio_stream=transcoder_v1.types.AudioStream(
codec="aac", bitrate_bps=64000
codec="aac",
bitrate_bps=64000,
),
),
transcoder_v1.types.ElementaryStream(
Expand All @@ -101,15 +102,12 @@ def create_job_with_embedded_captions(
input_track=0,
),
],
language_code="en-US",
display_name="English",
),
),
],
mux_streams=[
transcoder_v1.types.MuxStream(
key="sd",
container="mp4",
elementary_streams=["video-stream0", "audio-stream0"],
),
transcoder_v1.types.MuxStream(
key="sd-hls",
container="ts",
Expand Down
81 changes: 63 additions & 18 deletions samples/snippets/create_job_with_standalone_captions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

"""Google Cloud Transcoder sample for creating a job that can use captions from a standalone file.
"""Google Cloud Transcoder sample for creating a job that can use subtitles from a standalone file.

Example usage:
python create_job_with_standalone_captions.py --project_id <project-id> --location <location> \
--input_video_uri <uri> --input_captions_uri <uri> --output_uri <uri>
--input_video_uri <uri> --input_subtitles1_uri <uri> --input_subtitles2_uri <uri> --output_uri <uri>
"""

# [START transcoder_create_job_with_standalone_captions]
Expand All @@ -36,17 +36,20 @@ def create_job_with_standalone_captions(
project_id,
location,
input_video_uri,
input_captions_uri,
input_subtitles1_uri,
input_subtitles2_uri,
output_uri,
):
"""Creates a job based on an ad-hoc job configuration that can use captions from a standalone file.
"""Creates a job based on an ad-hoc job configuration that can use subtitles from a standalone file.

Args:
project_id (str): The GCP project ID.
location (str): The location to start the job in.
input_video_uri (str): Uri of the input video in the Cloud Storage
bucket.
input_captions_uri (str): Uri of the input captions file in the Cloud
input_subtitles1_uri (str): Uri of an input subtitles file in the Cloud
Storage bucket.
input_subtitles2_uri (str): Uri of an input subtitles file in the Cloud
Storage bucket.
output_uri (str): Uri of the video output folder in the Cloud Storage
bucket."""
Expand All @@ -63,14 +66,18 @@ def create_job_with_standalone_captions(
uri=input_video_uri,
),
transcoder_v1.types.Input(
key="caption-input0",
uri=input_captions_uri,
key="subtitle-input-en",
uri=input_subtitles1_uri,
),
transcoder_v1.types.Input(
key="subtitle-input-es",
uri=input_subtitles2_uri,
),
],
edit_list=[
transcoder_v1.types.EditAtom(
key="atom0",
inputs=["input0", "caption-input0"],
inputs=["input0", "subtitle-input-en", "subtitle-input-es"],
),
],
elementary_streams=[
Expand All @@ -88,18 +95,34 @@ def create_job_with_standalone_captions(
transcoder_v1.types.ElementaryStream(
key="audio-stream0",
audio_stream=transcoder_v1.types.AudioStream(
codec="aac", bitrate_bps=64000
codec="aac",
bitrate_bps=64000,
),
),
transcoder_v1.types.ElementaryStream(
key="vtt-stream-en",
text_stream=transcoder_v1.types.TextStream(
codec="webvtt",
language_code="en-US",
display_name="English",
mapping_=[
transcoder_v1.types.TextStream.TextMapping(
atom_key="atom0",
input_key="subtitle-input-en",
),
],
),
),
transcoder_v1.types.ElementaryStream(
key="vtt-stream0",
key="vtt-stream-es",
text_stream=transcoder_v1.types.TextStream(
codec="webvtt",
language_code="es-ES",
display_name="Spanish",
mapping_=[
transcoder_v1.types.TextStream.TextMapping(
atom_key="atom0",
input_key="caption-input0",
input_track=0,
input_key="subtitle-input-es",
),
],
),
Expand All @@ -117,9 +140,20 @@ def create_job_with_standalone_captions(
elementary_streams=["audio-stream0"],
),
transcoder_v1.types.MuxStream(
key="text-vtt",
key="text-vtt-en",
container="vtt",
elementary_streams=["vtt-stream0"],
elementary_streams=["vtt-stream-en"],
segment_settings=transcoder_v1.types.SegmentSettings(
segment_duration=duration.Duration(
seconds=6,
),
individual_segments=True,
),
),
transcoder_v1.types.MuxStream(
key="text-vtt-es",
container="vtt",
elementary_streams=["vtt-stream-es"],
segment_settings=transcoder_v1.types.SegmentSettings(
segment_duration=duration.Duration(
seconds=6,
Expand All @@ -132,7 +166,12 @@ def create_job_with_standalone_captions(
transcoder_v1.types.Manifest(
file_name="manifest.m3u8",
type_="HLS",
mux_streams=["sd-hls-fmp4", "audio-hls-fmp4", "text-vtt"],
mux_streams=[
"sd-hls-fmp4",
"audio-hls-fmp4",
"text-vtt-en",
"text-vtt-es",
],
),
],
)
Expand All @@ -157,8 +196,13 @@ def create_job_with_standalone_captions(
required=True,
)
parser.add_argument(
"--input_captions_uri",
help="Uri of the input captions file in the Cloud Storage bucket.",
"--input_subtitles1_uri",
help="Uri of an input subtitles file in the Cloud Storage bucket.",
required=True,
)
parser.add_argument(
"--input_subtitles2_uri",
help="Uri of an input subtitles file in the Cloud Storage bucket.",
required=True,
)
parser.add_argument(
Expand All @@ -172,6 +216,7 @@ def create_job_with_standalone_captions(
args.project_id,
args.location,
args.input_video_uri,
args.input_captions_uri,
args.input_subtitles1_uri,
args.input_subtitles2_uri,
args.output_uri,
)
9 changes: 7 additions & 2 deletions samples/snippets/job_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,17 @@
test_overlay_image_file_name = "overlay.jpg"
test_concat1_file_name = "ForBiggerEscapes.mp4"
test_concat2_file_name = "ForBiggerJoyrides.mp4"
test_captions_file_name = "caption.srt"
test_captions_file_name = "captions.srt"
test_subtitles1_file_name = "subtitles-en.srt"
test_subtitles2_file_name = "subtitles-es.srt"

input_uri = f"gs://{input_bucket_name}{test_video_file_name}"
overlay_image_uri = f"gs://{input_bucket_name}{test_overlay_image_file_name}"
concat1_uri = f"gs://{input_bucket_name}{test_concat1_file_name}"
concat2_uri = f"gs://{input_bucket_name}{test_concat2_file_name}"
captions_uri = f"gs://{input_bucket_name}{test_captions_file_name}"
subtitles1_uri = f"gs://{input_bucket_name}{test_subtitles1_file_name}"
subtitles2_uri = f"gs://{input_bucket_name}{test_subtitles2_file_name}"
output_uri_for_preset = f"gs://{output_bucket_name}/test-output-preset/"
output_uri_for_template = f"gs://{output_bucket_name}/test-output-template/"
output_uri_for_adhoc = f"gs://{output_bucket_name}/test-output-adhoc/"
Expand Down Expand Up @@ -452,7 +456,8 @@ def test_create_job_with_standalone_captions(capsys, test_bucket):
project_id,
location,
input_uri,
captions_uri,
subtitles1_uri,
subtitles2_uri,
output_uri_for_standalone_captions,
)
out, _ = capsys.readouterr()
Expand Down