0

I am converting a video, uploaded to cloud storage using a signed URL, using Transcoder API. I have written a cloud function that is triggered with write operations on the bucket. Everything is working fine but I need to get a notification when the conversion is completed. I am creating the job to convert the vid using the following code. I am trying to follow the solution proposed in this answer Google Cloud Platform: Convert uploaded MP4 file to HLS file

    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 (for example, 'preset/web-hd')."""

    client = TranscoderServiceClient()

    parent = f"projects/{project_id}/locations/{location}"
    job = transcoder_v1.types.Job()
    job.input_uri = input_uri
    job.output_uri = output_uri
    job.template_id = preset
    job.ttl_after_completion_days = 1
    job.config = transcoder_v1.types.JobConfig(
        PubsubDestination={
            topic_name=f"projects/{project_id}/topics/testing"
        }
    )
    response = client.create_job(parent=parent, job=job)
    print(f"Job: {response.name}")
    return response

The following snippet in the above code is not working

    job.config = transcoder_v1.types.JobConfig(
        PubsubDestination={
            topic_name=f"projects/{project_id}/topics/testing"
        }
    )

I have viewed the following but couldn't find any solution.

https://cloud.google.com/transcoder/docs/how-to/create-pub-sub

How to configure pubsub_destination in Transcoder API of GCP

Scott B
  • 2,516
  • 1
  • 8
  • 15
Mrcreamio
  • 73
  • 2
  • 10

1 Answers1

1

You cannot not define any configuration on your JobConfig on your code if you are creating a job from a preset or template since the preset and template will already populate the JobConfig for you.

As an alternative, you may create job using an ad-hoc configuration and then define PubsubDestination as shown on below code:

Note that I also corrected the syntax in using the PubsubDestination

from google.cloud.video import transcoder_v1
from google.cloud.video.transcoder_v1.services.transcoder_service import (
    TranscoderServiceClient,
)


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_v1.types.Job()
    job.input_uri = input_uri
    job.output_uri = output_uri
    job.config = transcoder_v1.types.JobConfig(
        elementary_streams=[
            transcoder_v1.types.ElementaryStream(
                key="video-stream0",
                video_stream=transcoder_v1.types.VideoStream(
                    h264=transcoder_v1.types.VideoStream.H264CodecSettings(
                        height_pixels=360,
                        width_pixels=640,
                        bitrate_bps=550000,
                        frame_rate=60,
                    ),
                ),
            ),
            transcoder_v1.types.ElementaryStream(
                key="video-stream1",
                video_stream=transcoder_v1.types.VideoStream(
                    h264=transcoder_v1.types.VideoStream.H264CodecSettings(
                        height_pixels=720,
                        width_pixels=1280,
                        bitrate_bps=2500000,
                        frame_rate=60,
                    ),
                ),
            ),
            transcoder_v1.types.ElementaryStream(
                key="audio-stream0",
                audio_stream=transcoder_v1.types.AudioStream(
                    codec="aac", bitrate_bps=64000
                ),
            ),
        ],
        mux_streams=[
            transcoder_v1.types.MuxStream(
                key="sd",
                container="mp4",
                elementary_streams=["video-stream0", "audio-stream0"],
            ),
            transcoder_v1.types.MuxStream(
                key="hd",
                container="mp4",
                elementary_streams=["video-stream1", "audio-stream0"],
            ),
        ],
        pubsub_destination=
            transcoder_v1.types.PubsubDestination(
                topic=f"projects/{project_id}/topics/your-topic"
            ),
    )
    response = client.create_job(parent=parent, job=job)
    print(f"Job: {response.name}")
    return response

Output of my testing: enter image description here

Other alternative is to create your own job template and then use it in your template_id so that you don't have to always define PubsubDestination in your code.

Scott B
  • 2,516
  • 1
  • 8
  • 15
  • Hi @scott-b when I pass the video file without audio following error is displayed [Audio Missing](https://cloud.google.com/transcoder/docs/troubleshooting#audio-missing). Is there any workaround to bypass this requirement of having audio? – Mrcreamio Jun 23 '22 at 07:52
  • 1
    As of now, the transcoder API really requires an audio on the video file. Right now there is already a feature request created for this in this link https://issuetracker.google.com/211671037. You can star the public issue tracker feature requests and add ‘Me too’ in the thread. This will bring more attention to the request as more users request support for it. – Scott B Jun 24 '22 at 02:41
  • Please have a look at this question. https://stackoverflow.com/questions/72828010/how-to-make-video-or-audio-optional-in-transcoder-api If you can help me out that would be great. – Mrcreamio Jul 01 '22 at 10:41