Media Live service in Java

0

Hello
I have to develop an application in Java where I have to use the service mediaLive with other aws services. In the documentation (https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/examples.html), I didn't find a code example for mediaLive to begin with it.
Could you tell me how can I develop it or give me links that can help me in my task?
Best regards
Mariem

asked 3 years ago418 views
5 Answers
0

Hi Meriem,

We are currently still in the process of improving and adding to our documentation but here are some example codes that show how to create an Internet Security Group, an Input and a Channel.

private static String createInputSecurityGroup(AWSMediaLive client, String sourceCIDR) {
System.out.println("Creating an input security group");
InputWhitelistRuleCidr c1 = new InputWhitelistRuleCidr().withCidr(sourceCIDR);
ArrayList<InputWhitelistRuleCidr> cidrs = new ArrayList<InputWhitelistRuleCidr>();
cidrs.add(c1);
CreateInputSecurityGroupRequest createISGRequest = new CreateInputSecurityGroupRequest().withWhitelistRules(cidrs)
.withTags(Collections.singletonMap("this_is", "an_input_security_group"));
CreateInputSecurityGroupResult createISGResult = client.createInputSecurityGroup(createISGRequest);
System.out.println("Input Security Group creation completed");
return createISGResult.getSecurityGroup().getId();
}
private static String createInput(AWSMediaLive client, String isgId, String inputType) {
System.out.println("Creating a input");
CreateInputRequest createInputRequest = new CreateInputRequest()
.withName("Test")
.withType(inputType)
.withInputSecurityGroups(Arrays.asList(isgId))
.withTags(Collections.singletonMap("this_is", "an_input"));
CreateInputResult createInputResult = client.createInput(createInputRequest);
System.out.println("Input creation completed");
return createInputResult.getInput().getId();
}
private static String createChannel(ArrayList<String> inputList, AWSMediaLive client) {
System.out.println("Creating a channel");
NetworkInputSettings networkInputSettings = new NetworkInputSettings();
InputSettings inputSettings = new InputSettings().withNetworkInputSettings(networkInputSettings);
ArrayList<InputAttachment> inputAttachments = new ArrayList<>();
for (String inputId : inputList) {
InputAttachment inpAttach = new InputAttachment()
.withInputId(inputId)
.withInputAttachmentName("example.reference." + inputId)
.withInputSettings(inputSettings);
inputAttachments.add(inpAttach);
}
// HLS output destination
ArrayList<OutputDestinationSettings> hlsOutputDestinationSettings = new ArrayList<OutputDestinationSettings>() {{
add(new OutputDestinationSettings().withUrl("https://example.com/a"));
add(new OutputDestinationSettings().withUrl("https://example.com/b"));
}};
AudioCodecSettings audioCodecSettings = new AudioCodecSettings()
.withAacSettings(new AacSettings().withBitrate((double) 96000));
AudioDescription audioDescription = new AudioDescription()
.withAudioSelectorName("default")
.withName("audio1")
.withCodecSettings(audioCodecSettings);
VideoDescription videoDescription = new VideoDescription()
.withName("video1")
.withHeight(720)
.withWidth(1280)
.withCodecSettings(new VideoCodecSettings()
.withH264Settings(new H264Settings()
.withBitrate(4500000)
)
);
OutputGroup hlsOutputGroup = createHlsOutputGroup();
EncoderSettings encoderSettings = new EncoderSettings()
.withTimecodeConfig(new TimecodeConfig().withSource("EMBEDDED"))
.withAudioDescriptions(audioDescription)
.withVideoDescriptions(videoDescription, frameCaptureVideoDescription)
.withOutputGroups(udpOutputGroup, hlsOutputGroup, frameCaptureOutputGroup);
InputSpecification inputSpecification = new InputSpecification()
.withMaximumBitrate("MAX_50_MBPS")
.withCodec("HEVC")
.withResolution("SD");
CreateChannelRequest createChannelRequest = new CreateChannelRequest()
.withName("TestChannel")
.withInputAttachments(inputAttachments)
.withDestinations(
new OutputDestination().withId("utpOutputDestination").withSettings(udpOutputDestinationSettings),
new OutputDestination().withId("hlsOutputDestination").withSettings(hlsOutputDestinationSettings),
new OutputDestination().withId("frameCaptureOutputDestination").withSettings(frameCaptureOutputDestinationSettings)
)
.withEncoderSettings(encoderSettings)
.withInputSpecification(inputSpecification)
.withTags(Collections.singletonMap("this_is", "a_channel"));
CreateChannelResult createChannelResult = client.createChannel(createChannelRequest);
System.out.println("Channel creation completed");
return createChannelResult.getChannel().getId();
}
private static OutputGroup createHlsOutputGroup() {
OutputGroupSettings outputGroupSettings = new OutputGroupSettings()
.withHlsGroupSettings(new HlsGroupSettings()
.withDestination(new OutputLocationRef()
.withDestinationRefId("hlsOutputDestination"))
.withHlsCdnSettings(new HlsCdnSettings()
.withHlsBasicPutSettings(new HlsBasicPutSettings()))
// Redundant manifests
.withBaseUrlManifest("http://example.com/manifest/a")
.withBaseUrlContent("http://example.com/context/a")
.withBaseUrlManifest1("http://example.com/manifest/b")
.withBaseUrlContent1("http://example.com/context/b")
.withRedundantManifest(HlsRedundantManifest.ENABLED)
// No not use timed metadata with fMP4
.withTimedMetadataId3Frame(HlsTimedMetadataId3Frame.NONE)
.withHlsId3SegmentTagging(HlsId3SegmentTaggingState.ENABLED)
);
OutputSettings outputSettings = new OutputSettings()
.withHlsOutputSettings(new HlsOutputSettings()
// Configure this channel with fMP4
.withHlsSettings(new HlsSettings()
.withFmp4HlsSettings(new Fmp4HlsSettings()
.withAudioRenditionSets("program_audio")
)
)
.withH265PackagingType(HlsH265PackagingType.HEV1)
);
// Do not specify an audio description when using fMP4
Output output = new Output()
.withOutputName("HLS output")
.withVideoDescriptionName("video1")
.withOutputSettings(outputSettings);
OutputGroup outputGroup = new OutputGroup()
.withName("HLS group 1")
.withOutputGroupSettings(outputGroupSettings)
.withOutputs(output);
return outputGroup;
}

Zach

answered 3 years ago
  • hi, how to use MediaLive with output/destination as MediaPackage ?

0

Hi Mariem,

Thank you for reaching out on the AWS MediaLive forums with this question. Here is a link to the AWS Java SDK for AWS MediaLive.

https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/medialive/AWSMediaLive.html

Please let me know if this is helpful,

Zach

answered 3 years ago
0

Thank you zack for answering my question.
I'm a beginner in aws services and I have to read all the documentation in details to know how using all these methods and theirs parameters to have a correct code for mediaLive service. Please, there isn't a complete sdk java code example for mediaLive as the the other services?
regards

answered 3 years ago
0

Hi zack
Thank you very much. That helps me a lot.
Mariem

answered 3 years ago
0

Do we have the sample code ready now?

answered 3 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions