|
| 1 | +/** |
| 2 | + * Copyright 2022, Google, Inc. |
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | + * you may not use this file except in compliance with the License. |
| 5 | + * You may obtain a copy of the License at |
| 6 | + * |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software |
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | + * See the License for the specific language governing permissions and |
| 13 | + * limitations under the License. |
| 14 | + */ |
| 15 | + |
| 16 | +'use strict'; |
| 17 | + |
| 18 | +function main(projectId, location, channelId, inputId, outputUri) { |
| 19 | + // [START livestream_create_channel] |
| 20 | + /** |
| 21 | + * TODO(developer): Uncomment these variables before running the sample. |
| 22 | + */ |
| 23 | + // projectId = 'my-project-id'; |
| 24 | + // location = 'us-central1'; |
| 25 | + // channelId = 'my-channel'; |
| 26 | + // inputId = 'my-input'; |
| 27 | + // outputUri = 'gs://my-bucket/my-output-folder/'; |
| 28 | + |
| 29 | + // Imports the Livestream library |
| 30 | + const {LivestreamServiceClient} = require('@google-cloud/livestream').v1; |
| 31 | + |
| 32 | + // Instantiates a client |
| 33 | + const livestreamServiceClient = new LivestreamServiceClient(); |
| 34 | + |
| 35 | + async function createChannel() { |
| 36 | + // Construct request |
| 37 | + const request = { |
| 38 | + parent: livestreamServiceClient.locationPath(projectId, location), |
| 39 | + channelId: channelId, |
| 40 | + channel: { |
| 41 | + inputAttachments: [ |
| 42 | + { |
| 43 | + key: 'my-input', |
| 44 | + input: livestreamServiceClient.inputPath( |
| 45 | + projectId, |
| 46 | + location, |
| 47 | + inputId |
| 48 | + ), |
| 49 | + }, |
| 50 | + ], |
| 51 | + output: { |
| 52 | + uri: outputUri, |
| 53 | + }, |
| 54 | + elementaryStreams: [ |
| 55 | + { |
| 56 | + key: 'es_video', |
| 57 | + videoStream: { |
| 58 | + h264: { |
| 59 | + profile: 'main', |
| 60 | + heightPixels: 720, |
| 61 | + widthPixels: 1280, |
| 62 | + bitrateBps: 1000000, |
| 63 | + frameRate: 30, |
| 64 | + }, |
| 65 | + }, |
| 66 | + }, |
| 67 | + { |
| 68 | + key: 'es_audio', |
| 69 | + audioStream: { |
| 70 | + codec: 'aac', |
| 71 | + channelCount: 2, |
| 72 | + bitrateBps: 160000, |
| 73 | + }, |
| 74 | + }, |
| 75 | + ], |
| 76 | + muxStreams: [ |
| 77 | + { |
| 78 | + key: 'mux_video', |
| 79 | + elementaryStreams: ['es_video'], |
| 80 | + segmentSettings: { |
| 81 | + seconds: 2, |
| 82 | + }, |
| 83 | + }, |
| 84 | + { |
| 85 | + key: 'mux_audio', |
| 86 | + elementaryStreams: ['es_audio'], |
| 87 | + segmentSettings: { |
| 88 | + seconds: 2, |
| 89 | + }, |
| 90 | + }, |
| 91 | + ], |
| 92 | + manifests: [ |
| 93 | + { |
| 94 | + fileName: 'manifest.m3u8', |
| 95 | + type: 'HLS', |
| 96 | + muxStreams: ['mux_video', 'mux_audio'], |
| 97 | + maxSegmentCount: 5, |
| 98 | + }, |
| 99 | + ], |
| 100 | + }, |
| 101 | + }; |
| 102 | + |
| 103 | + // Run request |
| 104 | + const [operation] = await livestreamServiceClient.createChannel(request); |
| 105 | + const response = await operation.promise(); |
| 106 | + const [channel] = response; |
| 107 | + console.log(`Channel: ${channel.name}`); |
| 108 | + } |
| 109 | + |
| 110 | + createChannel(); |
| 111 | + // [END livestream_create_channel] |
| 112 | +} |
| 113 | + |
| 114 | +// node createChannel.js <projectId> <location> <channelId> <inputId> <outputUri> |
| 115 | +process.on('unhandledRejection', err => { |
| 116 | + console.error(err.message); |
| 117 | + process.exitCode = 1; |
| 118 | +}); |
| 119 | +main(...process.argv.slice(2)); |
0 commit comments