Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ivs): support Multitrack Video #33370

Merged
merged 7 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions packages/@aws-cdk/aws-ivs-alpha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,26 @@ const myRtmpChannel = new ivs.Channel(this, 'myRtmpChannel', {
});
```

### Multitrack Video

Multitrack video is a new, low-latency streaming paradigm supported by Amazon Interactive Video Service (IVS) and services that use Amazon IVS.

You can use Multitrack Video by setting the `multitrackInputConfiguration` property.
Multitrack Video requires both a STANDARD Channel and Fragmented Mp4.

For more information, see [Amazon IVS Multitrack Video](https://docs.aws.amazon.com/ivs/latest/LowLatencyUserGuide/multitrack-video.html).

```ts
new ivs.Channel(this, 'ChannelWithMultitrackVideo', {
type: ivs.ChannelType.STANDARD,
containerFormat: ivs.ContainerFormat.FRAGMENTED_MP4,
multitrackInputConfiguration: {
maximumResolution: ivs.MaximumResolution.HD,
policy: ivs.Policy.ALLOW,
},
});
```

### Importing an existing channel

You can reference an existing channel, for example, if you need to create a
Expand Down
107 changes: 106 additions & 1 deletion packages/@aws-cdk/aws-ivs-alpha/lib/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,22 @@ abstract class ChannelBase extends core.Resource implements IChannel {
}

/**
Channel latency mode
* Container Format
*/
export enum ContainerFormat {
/**
* Use MPEG-TS.
*/
TS = 'TS',

/**
* Use fMP4.
*/
FRAGMENTED_MP4 = 'FRAGMENTED_MP4',
}

/**
* Channel latency mode
*/
export enum LatencyMode {
/**
Expand Down Expand Up @@ -119,6 +134,16 @@ export interface ChannelProps {
*/
readonly authorized?: boolean;

/**
* Indicates which content-packaging format is used (MPEG-TS or fMP4).
*
* If `multitrackInputConfiguration` is specified, only fMP4 can be used.
* Otherwise, `containerFormat` may be set to `ContainerFormat.TS` or `ContainerFormat.FRAGMENTED_MP4`.
*
* @default - `ContainerFormat.FRAGMENTED_MP4` is automatically set when the `multitrackInputConfiguration` is specified. If not specified, it remains undefined and uses the IVS default setting (TS).
*/
readonly containerFormat?: ContainerFormat;

/**
* Whether the channel allows insecure RTMP ingest.
*
Expand All @@ -140,6 +165,17 @@ export interface ChannelProps {
*/
readonly channelName?: string;

/**
* Object specifying multitrack input configuration.
* You must specify `multitrackInputConfiguration` if you want to use MultiTrack Video.
*
* `multitrackInputConfiguration` is only supported for `ChannelType.STANDARD`.
*
* @default undefined - IVS default setting is not use MultiTrack Video.
* @see https://docs.aws.amazon.com/ivs/latest/LowLatencyUserGuide/multitrack-video.html
*/
readonly multitrackInputConfiguration?: MultitrackInputConfiguration;

/**
* The channel type, which determines the allowable resolution and bitrate.
* If you exceed the allowable resolution or bitrate, the stream will disconnect immediately
Expand All @@ -164,6 +200,56 @@ export interface ChannelProps {
readonly recordingConfiguration?: IRecordingConfiguration;
}

/**
* Maximum resolution for multitrack input.
*/
export enum MaximumResolution {
/**
* Full HD (1080p)
*/
FULL_HD = 'FULL_HD',

/**
* HD (720p)
*/
HD = 'HD',

/**
* SD (480p)
*/
SD = 'SD',
}

/**
* Whether multitrack input is allowed or required.
*/
export enum Policy {
/**
* Multitrack input is allowed.
*/
ALLOW = 'ALLOW',

/**
* Multitrack input is required.
*/
REQUIRE = 'REQUIRE',
}

/**
* A complex type that specifies multitrack input configuration.
*/
export interface MultitrackInputConfiguration {
/**
* Maximum resolution for multitrack input.
*/
readonly maximumResolution: MaximumResolution;

/**
* Indicates whether multitrack input is allowed or required.
*/
readonly policy: Policy;
}

/**
A new IVS channel
*/
Expand Down Expand Up @@ -227,6 +313,16 @@ export class Channel extends ChannelBase {
preset = props.preset;
}

if (props.multitrackInputConfiguration !== undefined) {
if (props.type !== undefined && props.type !== ChannelType.STANDARD) {
throw new Error(`\`multitrackInputConfiguration\` is only supported for \`ChannelType.STANDARD\`, got: ${props.type}.`);
}

if (props.containerFormat !== undefined && props.containerFormat !== ContainerFormat.FRAGMENTED_MP4) {
throw new Error(`\`containerFormat\` must be set to \`ContainerFormat.FRAGMENTED_MP4\` when \`multitrackInputConfiguration\` is specified, got: ${props.containerFormat}.`);
}
}

const resource = new CfnChannel(this, 'Resource', {
authorized: props.authorized,
insecureIngest: props.insecureIngest,
Expand All @@ -235,6 +331,15 @@ export class Channel extends ChannelBase {
type: props.type,
preset,
recordingConfigurationArn: props.recordingConfiguration?.recordingConfigurationArn,
containerFormat: props.containerFormat ??
(props.multitrackInputConfiguration ? ContainerFormat.FRAGMENTED_MP4 : undefined),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using multitrack video, the containerFormat needs to be set to fMP4.
Therefore, when multitrackInputConfiguration is set but containerFormat is not specified, I configured it to automatically set fMP4.
While I considered making it a validation error when containerFormat is not set, I decided this approach would be more user-friendly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree with this approach 👍

multitrackInputConfiguration: props.multitrackInputConfiguration ?
{
enabled: true,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two configuration patterns for multitrackInputConfiguration in CFn:

  • When enabled is false, other properties cannot be set. The IVS default setting has enabled as false.
  • When enabled is true, other properties must be set.

I felt that implementing these patterns in validation would become complex, and there's no real need to explicitly set enabled to false.
Therefore, in the L2 Construct, I abstracted this so that multitrackInputConfiguration is only set when we want to use multitrack video with enabled set to true.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree with this

maximumResolution: props.multitrackInputConfiguration.maximumResolution,
policy: props.multitrackInputConfiguration.policy,
}
: undefined,
});

this.channelArn = resource.attrArn;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"Resources": {
"ChannelWithMultitrackVideoE5332214": {
"Type": "AWS::IVS::Channel",
"Properties": {
"ContainerFormat": "FRAGMENTED_MP4",
"MultitrackInputConfiguration": {
"Enabled": true,
"MaximumResolution": "HD",
"Policy": "ALLOW"
},
"Name": "aws-cdk-ivs-multitarck-videoChannelWithMultitrackVideoCC53F319",
"Type": "STANDARD"
}
}
},
"Parameters": {
"BootstrapVersion": {
"Type": "AWS::SSM::Parameter::Value<String>",
"Default": "/cdk-bootstrap/hnb659fds/version",
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
}
},
"Rules": {
"CheckBootstrapVersion": {
"Assertions": [
{
"Assert": {
"Fn::Not": [
{
"Fn::Contains": [
[
"1",
"2",
"3",
"4",
"5"
],
{
"Ref": "BootstrapVersion"
}
]
}
]
},
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
}
]
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading