in media/livestream/src/create_channel_with_backup_input.php [52:146]
function create_channel_with_backup_input(
string $callingProjectId,
string $location,
string $channelId,
string $primaryInputId,
string $backupInputId,
string $outputUri
): void {
// Instantiate a client.
$livestreamClient = new LivestreamServiceClient();
$parent = $livestreamClient->locationName($callingProjectId, $location);
$channelName = $livestreamClient->channelName($callingProjectId, $location, $channelId);
$primaryInputName = $livestreamClient->inputName($callingProjectId, $location, $primaryInputId);
$backupInputName = $livestreamClient->inputName($callingProjectId, $location, $backupInputId);
$channel = (new Channel())
->setName($channelName)
->setInputAttachments([
new InputAttachment([
'key' => 'my-primary-input',
'input' => $primaryInputName,
'automatic_failover' => new InputAttachment\AutomaticFailover([
'input_keys' => ['my-backup-input']
])
]),
new InputAttachment([
'key' => 'my-backup-input',
'input' => $backupInputName
])
])
->setElementaryStreams([
new ElementaryStream([
'key' => 'es_video',
'video_stream' => new VideoStream([
'h264' => new VideoStream\H264CodecSettings([
'profile' => 'high',
'width_pixels' => 1280,
'height_pixels' => 720,
'bitrate_bps' => 3000000,
'frame_rate' => 30
])
]),
]),
new ElementaryStream([
'key' => 'es_audio',
'audio_stream' => new AudioStream([
'codec' => 'aac',
'channel_count' => 2,
'bitrate_bps' => 160000
])
])
])
->setOutput(new Channel\Output(['uri' => $outputUri]))
->setMuxStreams([
new MuxStream([
'key' => 'mux_video',
'elementary_streams' => ['es_video'],
'segment_settings' => new SegmentSettings([
'segment_duration' => new Duration(['seconds' => 2])
])
]),
new MuxStream([
'key' => 'mux_audio',
'elementary_streams' => ['es_audio'],
'segment_settings' => new SegmentSettings([
'segment_duration' => new Duration(['seconds' => 2])
])
]),
])
->setManifests([
new Manifest([
'file_name' => 'manifest.m3u8',
'type' => Manifest\ManifestType::HLS,
'mux_streams' => ['mux_video', 'mux_audio'],
'max_segment_count' => 5
])
]);
// Run the channel creation request. The response is a long-running operation ID.
$request = (new CreateChannelRequest())
->setParent($parent)
->setChannel($channel)
->setChannelId($channelId);
$operationResponse = $livestreamClient->createChannel($request);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
$result = $operationResponse->getResult();
// Print results
printf('Channel: %s' . PHP_EOL, $result->getName());
} else {
$error = $operationResponse->getError();
// handleError($error)
}
}