|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +# Copyright 2023 Google Inc. All Rights Reserved. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +"""Google Cloud Video Stitcher sample for creating a live config. Live |
| 18 | +configs are used to configure live sessions. |
| 19 | +Example usage: |
| 20 | + python create_live_config.py --project_id <project-id> --location <location> \ |
| 21 | + --live_config_id <live-config-id> --live_stream_uri <uri> --ad_tag_uri <uri> \ |
| 22 | + --slate_id <id> |
| 23 | +""" |
| 24 | + |
| 25 | +# [START videostitcher_create_live_config] |
| 26 | + |
| 27 | +import argparse |
| 28 | + |
| 29 | +from google.cloud.video import stitcher_v1 |
| 30 | +from google.cloud.video.stitcher_v1.services.video_stitcher_service import ( |
| 31 | + VideoStitcherServiceClient, |
| 32 | +) |
| 33 | + |
| 34 | + |
| 35 | +def create_live_config( |
| 36 | + project_id: str, |
| 37 | + location: str, |
| 38 | + live_config_id: str, |
| 39 | + live_stream_uri: str, |
| 40 | + ad_tag_uri: str, |
| 41 | + slate_id: str, |
| 42 | +) -> str: |
| 43 | + """Creates a live config. |
| 44 | + Args: |
| 45 | + project_id: The GCP project ID. |
| 46 | + location: The location in which to create the live config. |
| 47 | + live_config_id: The user-defined live config ID. |
| 48 | + live_stream_uri: Uri of the livestream to stitch; this URI must reference either an MPEG-DASH |
| 49 | + manifest (.mpd) file or an M3U playlist manifest (.m3u8) file. |
| 50 | + ad_tag_uri: Uri of the ad tag. |
| 51 | + slate_id: The user-defined slate ID of the default slate to use when no slates are specified in an ad break's message.""" |
| 52 | + |
| 53 | + client = VideoStitcherServiceClient() |
| 54 | + |
| 55 | + parent = f"projects/{project_id}/locations/{location}" |
| 56 | + default_slate = f"projects/{project_id}/locations/{location}/slates/{slate_id}" |
| 57 | + |
| 58 | + live_config = stitcher_v1.types.LiveConfig( |
| 59 | + source_uri=live_stream_uri, |
| 60 | + ad_tag_uri=ad_tag_uri, |
| 61 | + ad_tracking="SERVER", |
| 62 | + default_slate=default_slate, |
| 63 | + ) |
| 64 | + |
| 65 | + operation = client.create_live_config( |
| 66 | + parent=parent, live_config_id=live_config_id, live_config=live_config |
| 67 | + ) |
| 68 | + response = operation.result() |
| 69 | + print(f"Live config: {response.name}") |
| 70 | + return response |
| 71 | + |
| 72 | + |
| 73 | +# [END videostitcher_create_live_config] |
| 74 | + |
| 75 | +if __name__ == "__main__": |
| 76 | + parser = argparse.ArgumentParser() |
| 77 | + parser.add_argument("--project_id", help="Your Cloud project ID.", required=True) |
| 78 | + parser.add_argument( |
| 79 | + "--location", |
| 80 | + help="The location in which to create the live config.", |
| 81 | + default="us-central1", |
| 82 | + ) |
| 83 | + parser.add_argument( |
| 84 | + "--live_config_id", |
| 85 | + help="The user-defined live config ID.", |
| 86 | + required=True, |
| 87 | + ) |
| 88 | + parser.add_argument( |
| 89 | + "--live_stream_uri", |
| 90 | + help="The uri of the livestream to stitch (.mpd or .m3u8 file) in double quotes.", |
| 91 | + required=True, |
| 92 | + ) |
| 93 | + parser.add_argument( |
| 94 | + "--ad_tag_uri", |
| 95 | + help="Uri of the ad tag in double quotes.", |
| 96 | + required=True, |
| 97 | + ) |
| 98 | + parser.add_argument( |
| 99 | + "--slate_id", |
| 100 | + help="The user-defined slate ID of the default slate.", |
| 101 | + required=True, |
| 102 | + ) |
| 103 | + args = parser.parse_args() |
| 104 | + create_live_config( |
| 105 | + args.project_id, |
| 106 | + args.location, |
| 107 | + args.live_config_id, |
| 108 | + args.live_stream_uri, |
| 109 | + args.ad_tag_uri, |
| 110 | + args.slate_id, |
| 111 | + ) |
0 commit comments