def create_job_from_ad_hoc(project_id, location, input_uri, output_uri):
    """Creates a job based on an ad-hoc job configuration.

    Args:
        project_id: The GCP project ID.
        location: The location to start the job in.
        input_uri: Uri of the video in the Cloud Storage bucket.
        output_uri: Uri of the video output folder in the Cloud Storage bucket."""

    client = TranscoderServiceClient()

    parent = f"projects/{project_id}/locations/{location}"
    job = transcoder_v1beta1.types.Job()
    job.input_uri = input_uri
    job.output_uri = output_uri
    job.config = transcoder_v1beta1.types.JobConfig(
        elementary_streams=[
            transcoder_v1beta1.types.ElementaryStream(
                key="video-stream0",
                video_stream=transcoder_v1beta1.types.VideoStream(
                    codec="h264",
                    height_pixels=360,
                    width_pixels=640,
                    bitrate_bps=550000,
                    frame_rate=60,
                ),
            ),
            transcoder_v1beta1.types.ElementaryStream(
                key="video-stream1",
                video_stream=transcoder_v1beta1.types.VideoStream(
                    codec="h264",
                    height_pixels=720,
                    width_pixels=1280,
                    bitrate_bps=2500000,
                    frame_rate=60,
                ),
            ),
            transcoder_v1beta1.types.ElementaryStream(
                key="audio-stream0",
                audio_stream=transcoder_v1beta1.types.AudioStream(
                    codec="aac", bitrate_bps=64000
                ),
            ),
        ],
        mux_streams=[
            transcoder_v1beta1.types.MuxStream(
                key="sd",
                container="mp4",
                elementary_streams=["video-stream0", "audio-stream0"],
            ),
            transcoder_v1beta1.types.MuxStream(
                key="hd",
                container="mp4",
                elementary_streams=["video-stream1", "audio-stream0"],
            ),
        ],
    )
    response = client.create_job(parent=parent, job=job)
    print(f"Job: {response.name}")
    return response
Beispiel #2
0
def create_job_from_preset(project_id, location, input_uri, output_uri, preset):
    """Creates a job based on a job preset.

    Args:
        project_id: The GCP project ID.
        location: The location to start the job in.
        input_uri: Uri of the video in the Cloud Storage bucket.
        output_uri: Uri of the video output folder in the Cloud Storage bucket.
        preset: The preset template."""

    client = TranscoderServiceClient()

    parent = f"projects/{project_id}/locations/{location}"
    job = transcoder_v1beta1.types.Job()
    job.input_uri = input_uri
    job.output_uri = output_uri
    job.template_id = preset

    response = client.create_job(parent=parent, job=job)
    print(f"Job: {response.name}")
    return response
Beispiel #3
0
def create_job_with_static_overlay(
    project_id, location, input_uri, overlay_image_uri, output_uri
):
    """Creates a job based on an ad-hoc job configuration that includes a static image overlay.

    Args:
        project_id: The GCP project ID.
        location: The location to start the job in.
        input_uri: Uri of the video in the Cloud Storage bucket.
        overlay_image_uri: Uri of the JPEG image for the overlay in the Cloud Storage bucket. Must be a JPEG.
        output_uri: Uri of the video output folder in the Cloud Storage bucket."""

    client = TranscoderServiceClient()

    parent = f"projects/{project_id}/locations/{location}"
    job = transcoder_v1beta1.types.Job()
    job.input_uri = input_uri
    job.output_uri = output_uri
    job.config = transcoder_v1beta1.types.JobConfig(
        elementary_streams=[
            transcoder_v1beta1.types.ElementaryStream(
                key="video-stream0",
                video_stream=transcoder_v1beta1.types.VideoStream(
                    codec="h264",
                    height_pixels=360,
                    width_pixels=640,
                    bitrate_bps=550000,
                    frame_rate=60,
                ),
            ),
            transcoder_v1beta1.types.ElementaryStream(
                key="audio-stream0",
                audio_stream=transcoder_v1beta1.types.AudioStream(
                    codec="aac", bitrate_bps=64000
                ),
            ),
        ],
        mux_streams=[
            transcoder_v1beta1.types.MuxStream(
                key="sd",
                container="mp4",
                elementary_streams=["video-stream0", "audio-stream0"],
            ),
        ],
        overlays=[
            transcoder_v1beta1.types.Overlay(
                image=transcoder_v1beta1.types.Overlay.Image(
                    uri=overlay_image_uri,
                    resolution=transcoder_v1beta1.types.Overlay.NormalizedCoordinate(
                        x=1,
                        y=0.5,
                    ),
                    alpha=1,
                ),
                animations=[
                    transcoder_v1beta1.types.Overlay.Animation(
                        animation_static=transcoder_v1beta1.types.Overlay.AnimationStatic(
                            xy=transcoder_v1beta1.types.Overlay.NormalizedCoordinate(
                                x=0,
                                y=0,
                            ),
                            start_time_offset=duration.Duration(
                                seconds=0,
                            ),
                        ),
                    ),
                    transcoder_v1beta1.types.Overlay.Animation(
                        animation_end=transcoder_v1beta1.types.Overlay.AnimationEnd(
                            start_time_offset=duration.Duration(
                                seconds=10,
                            ),
                        ),
                    ),
                ],
            ),
        ],
    )
    response = client.create_job(parent=parent, job=job)
    print(f"Job: {response.name}")
    return response
Beispiel #4
0
def create_job_with_periodic_images_spritesheet(project_id, location,
                                                input_uri, output_uri):
    """Creates a job based on an ad-hoc job configuration that generates two spritesheets.

    Args:
        project_id: The GCP project ID.
        location: The location to start the job in.
        input_uri: Uri of the video in the Cloud Storage bucket.
        output_uri: Uri of the video output folder in the Cloud Storage bucket."""

    client = TranscoderServiceClient()

    parent = f"projects/{project_id}/locations/{location}"
    job = transcoder_v1beta1.types.Job()
    job.input_uri = input_uri
    job.output_uri = output_uri
    job.config = transcoder_v1beta1.types.JobConfig(
        # Create an ad-hoc job. For more information, see https://cloud.google.com/transcoder/docs/how-to/jobs#create_jobs_ad_hoc.
        # See all options for the job config at https://cloud.google.com/transcoder/docs/reference/rest/v1beta1/JobConfig.
        elementary_streams=[
            # This section defines the output video stream.
            transcoder_v1beta1.types.ElementaryStream(
                key="video-stream0",
                video_stream=transcoder_v1beta1.types.VideoStream(
                    codec="h264",
                    height_pixels=360,
                    width_pixels=640,
                    bitrate_bps=550000,
                    frame_rate=60,
                ),
            ),
            # This section defines the output audio stream.
            transcoder_v1beta1.types.ElementaryStream(
                key="audio-stream0",
                audio_stream=transcoder_v1beta1.types.AudioStream(
                    codec="aac", bitrate_bps=64000),
            ),
        ],
        # This section multiplexes the output audio and video together into a container.
        mux_streams=[
            transcoder_v1beta1.types.MuxStream(
                key="sd",
                container="mp4",
                elementary_streams=["video-stream0", "audio-stream0"],
            ),
        ],
        # Generate two sprite sheets from the input video into the GCS bucket. For more information, see
        # https://cloud.google.com/transcoder/docs/how-to/generate-spritesheet#generate_image_periodically.
        sprite_sheets=[
            # Generate a sprite sheet with 64x32px images. An image is taken every 7 seconds from the video.
            transcoder_v1beta1.types.SpriteSheet(
                file_prefix="small-sprite-sheet",
                sprite_width_pixels=64,
                sprite_height_pixels=32,
                interval=duration.Duration(seconds=7, ),
            ),
            # Generate a sprite sheet with 128x72px images. An image is taken every 7 seconds from the video.
            transcoder_v1beta1.types.SpriteSheet(
                file_prefix="large-sprite-sheet",
                sprite_width_pixels=128,
                sprite_height_pixels=72,
                interval=duration.Duration(seconds=7, ),
            ),
        ],
    )
    response = client.create_job(parent=parent, job=job)
    print(f"Job: {response.name}")
    return response
def create_job_with_periodic_images_spritesheet(project_id, location,
                                                input_uri, output_uri):
    """Creates a job based on an ad-hoc job configuration that generates two spritesheets.

    Args:
        project_id: The GCP project ID.
        location: The location to start the job in.
        input_uri: Uri of the video in the Cloud Storage bucket.
        output_uri: Uri of the video output folder in the Cloud Storage bucket."""

    client = TranscoderServiceClient()

    parent = f"projects/{project_id}/locations/{location}"
    job = transcoder_v1beta1.types.Job()
    job.input_uri = input_uri
    job.output_uri = output_uri
    job.config = transcoder_v1beta1.types.JobConfig(
        # Create an ad-hoc job. For more information, see https://cloud.google.com/transcoder/docs/how-to/jobs#create_jobs_ad_hoc.
        # See all options for the job config at https://cloud.google.com/transcoder/docs/reference/rest/v1beta1/JobConfig.
        inputs=[
            transcoder_v1beta1.types.Input(
                key="caption_input0",
                uri="gs://alme-test-eyu/transcode_input/subs_2.srt",
            ),
            transcoder_v1beta1.types.Input(key="input0", )
        ],
        edit_list=[
            transcoder_v1beta1.types.EditAtom(
                key="atom0",
                inputs=[
                    "caption_input0",
                    "input0",
                ],
            ),
        ],
        elementary_streams=[
            # This section defines the output video stream.
            transcoder_v1beta1.types.ElementaryStream(
                key="video-stream0",
                video_stream=transcoder_v1beta1.types.VideoStream(
                    codec="h264",
                    height_pixels=360,
                    width_pixels=640,
                    bitrate_bps=550000,
                    frame_rate=60,
                ),
            ),
            # This section defines the output audio stream.
            transcoder_v1beta1.types.ElementaryStream(
                key="audio-stream0",
                audio_stream=transcoder_v1beta1.types.AudioStream(
                    codec="aac", bitrate_bps=64000),
            ),
            # This section defines the output text stream.
            transcoder_v1beta1.types.ElementaryStream(
                key="text-stream0",
                text_stream=transcoder_v1beta1.types.TextStream(
                    codec="webvtt",
                    #codec="cea608",
                    language_code="en-US",
                    #mapping=[
                    #    transcoder_v1beta1.types.TextStream.TextAtom(
                    #        key="atom0",
                    #        inputs=[
                    #            transcoder_v1beta1.types.TextStream.TextAtom.TextInput(
                    #                key="caption_input0",
                    #            ),
                    #        ],
                    #    ),
                    #]
                ),
            ),
        ],
        # This section multiplexes the output audio and video together into a container.
        #mux_streams=[
        #    transcoder_v1beta1.types.MuxStream(
        #        key="sd",
        #        container="mp4",
        #        elementary_streams=["video-stream0", "audio-stream0", "text-stream0"],
        #    ),
        #],
        mux_streams=[
            transcoder_v1beta1.types.MuxStream(
                key="sd",
                container="ts",
                elementary_streams=["video-stream0", "audio-stream0"],
                #segment_settings=transcoder_v1beta1.types.SegmentSettings(
                #    segment_duration=duration.Duration(seconds=6),
                #    individual_segments=True
                #),
            ),
            #transcoder_v1beta1.types.MuxStream(
            #    key="audio",
            #    container="fmp4",
            #    elementary_streams=["audio-stream0"],
            #    segment_settings=transcoder_v1beta1.types.SegmentSettings(
            #        segment_duration=duration.Duration(seconds=5),
            #        individual_segments=True
            #    ),
            #),
            transcoder_v1beta1.types.MuxStream(
                key="subtitle",
                container="vtt",
                elementary_streams=["text-stream0"],
                segment_settings=transcoder_v1beta1.types.SegmentSettings(
                    segment_duration=duration.Duration(seconds=6),
                    individual_segments=True),
            ),
        ],
        manifests=[
            transcoder_v1beta1.types.Manifest(
                file_name="master.m3u8",
                type_="HLS",
                mux_streams=["sd", "subtitle"],
            )
        ],

        # Generate two sprite sheets from the input video into the GCS bucket. For more information, see
        # https://cloud.google.com/transcoder/docs/how-to/generate-spritesheet#generate_image_periodically.
        sprite_sheets=[
            # Generate a sprite sheet with 64x32px images. An image is taken every 7 seconds from the video.
            transcoder_v1beta1.types.SpriteSheet(
                file_prefix="4-3-",
                sprite_width_pixels=720,
                sprite_height_pixels=540,
                column_count=1,
                row_count=1,
                total_count=5,
                #interval=duration.Duration(
                #    seconds=7,
                #),
            ),
            # Generate a sprite sheet with 128x72px images. An image is taken every 7 seconds from the video.
            transcoder_v1beta1.types.SpriteSheet(
                file_prefix="16-9-",
                sprite_width_pixels=960,
                sprite_height_pixels=540,
                column_count=1,
                row_count=1,
                total_count=5,
                #interval=duration.Duration(
                #    seconds=7,
                #),
            ),
        ],
    )
    response = client.create_job(parent=parent, job=job)
    print(f"Job: {response.name}")
    return response