def create_job_template(project_id, location, template_id): """Creates a job template. Args: project_id: The GCP project ID. location: The location to store this template in. template_id: The user-defined template ID.""" client = TranscoderServiceClient() parent = f"projects/{project_id}/locations/{location}" job_template = transcoder_v1beta1.types.JobTemplate() job_template.name = ( f"projects/{project_id}/locations/{location}/jobTemplates/{template_id}" ) job_template.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_template(parent=parent, job_template=job_template, job_template_id=template_id) print(f"Job template: {response.name}") return response
def create_job_template(project_id, location, template_id, pubsub_topic): """Creates a job template. Args: project_id: The GCP project ID. location: The location to store this template in. Ex: us-central1 template_id: The user-defined template ID. Ex: template_transcode_to_mp4_with_notification pubsub_topic: The name of the Pub/Sub topic to publish job completion notification to. Example: my_pubsub_topic """ client = TranscoderServiceClient() parent = f"projects/{project_id}/locations/{location}" pubsub_topic_fullname = f"projects/{project_id}/topics/{pubsub_topic}" job_template = transcoder_v1beta1.types.JobTemplate() job_template.name = ( f"projects/{project_id}/locations/{location}/jobTemplates/{template_id}" ) job_template.config = transcoder_v1beta1.types.JobConfig( pubsub_destination={"topic": pubsub_topic_fullname}, 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_template(parent=parent, job_template=job_template, job_template_id=template_id) print(f"Job template: {response.name}") return response