Skip to content

Commit

Permalink
be more explicit on source stream selection (#43)
Browse files Browse the repository at this point in the history
set 'selectionMode' to AUTO (instead of relying on the default) to be more explicit;
do not set 'position' when using selectionMode AUTO as it has no effect;
minor improvements regarding creation and naming of codec configurations
  • Loading branch information
fuetgeo authored Jun 1, 2022
1 parent 85e07ad commit ef134b8
Show file tree
Hide file tree
Showing 35 changed files with 178 additions and 191 deletions.
11 changes: 5 additions & 6 deletions dotnet/Bitmovin.Api.Sdk.Examples/ConcatenationMultipleInputs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ public async Task RunExample(string[] args)
_configProvider.GetS3OutputSecretKey());

// Define a video and audio stream as an IngestInputStream to represent each input file (main, bumper, and promo)
var main = await CreateIngestInputStream(encoding, httpInput, mainFilePath, StreamSelectionMode.AUTO);
var bumper = await CreateIngestInputStream(encoding, httpInput, bumperFilePath, StreamSelectionMode.AUTO);
var promo = await CreateIngestInputStream(encoding, httpInput, promoFilePath, StreamSelectionMode.AUTO);
var main = await CreateIngestInputStream(encoding, httpInput, mainFilePath);
var bumper = await CreateIngestInputStream(encoding, httpInput, bumperFilePath);
var promo = await CreateIngestInputStream(encoding, httpInput, promoFilePath);

// In this example, we trim the main input file and create two separated streams as TimeBasedTrimmingInputStream
var mainPart1 = await CreateTimeBasedTrimmingInputStream(encoding, main, 10.0, 90.0);
Expand Down Expand Up @@ -294,14 +294,13 @@ private Task<S3Output> CreateS3Output(string bucketName, string accessKey, strin
/// <param name="input">The input resource providing the input file</param>
/// <param name="inputPath">The path to the input file.</param>
/// <param name="streamSelectionMode">The algorithm how the stream in the input file will be selected.</param>
private Task<IngestInputStream> CreateIngestInputStream(Models.Encoding encoding, Input input, String inputPath,
StreamSelectionMode streamSelectionMode)
private Task<IngestInputStream> CreateIngestInputStream(Models.Encoding encoding, Input input, String inputPath)
{
var ingestInputStream = new IngestInputStream()
{
InputId = input.Id,
InputPath = inputPath,
SelectionMode = streamSelectionMode
SelectionMode = StreamSelectionMode.AUTO
};
return _bitmovinApi.Encoding.Encodings.InputStreams.Ingest.CreateAsync(encoding.Id, ingestInputStream);
}
Expand Down
3 changes: 2 additions & 1 deletion dotnet/Bitmovin.Api.Sdk.Examples/PerTitleEncoding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@ private Task<Stream> CreateStream(Models.Encoding encoding, Input input, string
var streamInput = new StreamInput()
{
InputId = input.Id,
InputPath = inputPath
InputPath = inputPath,
SelectionMode = StreamSelectionMode.AUTO
};

var stream = new Stream()
Expand Down
9 changes: 4 additions & 5 deletions dotnet/Bitmovin.Api.Sdk.Examples/RtmpLiveEncoding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ public async Task RunExample(string[] args)

// Add an H.264 video stream to the encoding
var h264VideoConfig = await CreateH264VideoConfiguration();
var h264VideoStream = await CreateStream(encoding, input, inputFilePath, h264VideoConfig, 0);
var h264VideoStream = await CreateStream(encoding, input, inputFilePath, h264VideoConfig);

// Add an AAC audio stream to the encoding
var aacConfig = await CreateAacAudioConfiguration();
var aacAudioStream = await CreateStream(encoding, input, inputFilePath, aacConfig, 1);
var aacAudioStream = await CreateStream(encoding, input, inputFilePath, aacConfig);

await CreateFmp4Muxing(encoding, output, $"/video/${h264VideoConfig.Height}p", h264VideoStream);
await CreateFmp4Muxing(encoding, output, $"/audio/${aacConfig.Bitrate! / 1000}kbps", aacAudioStream);
Expand Down Expand Up @@ -369,15 +369,14 @@ private Task<S3Output> CreateS3Output(string bucketName, string accessKey, strin
/// <param name="input">The input that should be used</param>
/// <param name="inputPath">The path to the input file</param>
/// <param name="configuration">The codec configuration to be applied to the stream</param>
/// <param name="position">The position of the input stream that is associated with the generated stream</param>
private Task<Stream> CreateStream(Models.Encoding encoding, Input input, string inputPath,
CodecConfiguration configuration, int position)
CodecConfiguration configuration)
{
var streamInput = new StreamInput()
{
InputId = input.Id,
InputPath = inputPath,
Position = position
SelectionMode = StreamSelectionMode.AUTO
};

var stream = new Stream()
Expand Down
11 changes: 5 additions & 6 deletions java/src/main/java/ConcatenationMultipleInputs.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ public static void main(String[] args) throws Exception {
configProvider.getS3OutputSecretKey()
);

IngestInputStream main = createIngestInputStream(encoding, input, mainFilePath, StreamSelectionMode.AUTO);
IngestInputStream bumper = createIngestInputStream(encoding, input, bumperFilePath, StreamSelectionMode.AUTO);
IngestInputStream promo = createIngestInputStream(encoding, input, promoFilePath, StreamSelectionMode.AUTO);
IngestInputStream main = createIngestInputStream(encoding, input, mainFilePath);
IngestInputStream bumper = createIngestInputStream(encoding, input, bumperFilePath);
IngestInputStream promo = createIngestInputStream(encoding, input, promoFilePath);

TimeBasedTrimmingInputStream mainPart1 = createTimeBasedTrimmingInputStream(encoding, main, 10.0, 90.0);
TimeBasedTrimmingInputStream mainPart2= createTimeBasedTrimmingInputStream(encoding, main, 109.0, 60.0);
Expand Down Expand Up @@ -242,13 +242,12 @@ private static S3Output createS3Output(String bucketName, String accessKey, Stri
* @param encoding The encoding to be started
* @param input The input resource providing the input file
* @param inputPath The path to the input file
* @param streamSelectionMode The algorithm how the stream in the input file will be selected
*/
private static IngestInputStream createIngestInputStream(Encoding encoding, Input input, String inputPath, StreamSelectionMode streamSelectionMode) {
private static IngestInputStream createIngestInputStream(Encoding encoding, Input input, String inputPath) {
IngestInputStream ingestInputStream = new IngestInputStream();
ingestInputStream.setInputId(input.getId());
ingestInputStream.setInputPath(inputPath);
ingestInputStream.setSelectionMode(streamSelectionMode);
ingestInputStream.setSelectionMode(StreamSelectionMode.AUTO);

return bitmovinApi.encoding.encodings.inputStreams.ingest.create(encoding.getId(), ingestInputStream);
}
Expand Down
15 changes: 4 additions & 11 deletions java/src/main/java/HdrConversions.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,10 @@ public static void main(String[] args) throws Exception {
videoInputStream =
createDolbyVisionInputStream(encoding, httpsInput, videoInputPath, inputMetadataPath);
} else {
videoInputStream =
createIngestInputStream(
encoding, httpsInput, videoInputPath, StreamSelectionMode.AUTO, 0);
videoInputStream = createIngestInputStream(encoding, httpsInput, videoInputPath);
}

InputStream audioInputStream =
createIngestInputStream(encoding, httpsInput, audioInputPath, StreamSelectionMode.AUTO, 0);
InputStream audioInputStream = createIngestInputStream(encoding, httpsInput, audioInputPath);
createH265AndAacEncoding(encoding, videoInputStream, audioInputStream, output);

executeEncoding(encoding);
Expand Down Expand Up @@ -423,7 +420,6 @@ private static HttpsInput createHttpsInput(String host) throws BitmovinException
*/
private static S3Output createS3Output(String bucketName, String accessKey, String secretKey)
throws BitmovinException {

S3Output s3Output = new S3Output();
s3Output.setBucketName(bucketName);
s3Output.setAccessKey(accessKey);
Expand All @@ -447,15 +443,12 @@ private static S3Output createS3Output(String bucketName, String accessKey, Stri
private static IngestInputStream createIngestInputStream(
Encoding encoding,
Input input,
String inputPath,
StreamSelectionMode streamSelectionMode,
int position)
String inputPath)
throws BitmovinException {
IngestInputStream ingestInputStream = new IngestInputStream();
ingestInputStream.setInputId(input.getId());
ingestInputStream.setInputPath(inputPath);
ingestInputStream.setSelectionMode(streamSelectionMode);
ingestInputStream.setPosition(position);
ingestInputStream.setSelectionMode(StreamSelectionMode.AUTO);

return bitmovinApi.encoding.encodings.inputStreams.ingest.create(
encoding.getId(), ingestInputStream);
Expand Down
48 changes: 18 additions & 30 deletions java/src/main/java/RtmpLiveEncoding.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ public class RtmpLiveEncoding {
/** This list defines the video renditions that will be generated */
private static List<VideoConfig> videoProfile =
Arrays.asList(
new VideoConfig("480p", 800_000L, 480, "/video/480p", 0),
new VideoConfig("720p", 1_200_000L, 720, "/video/720p", 0),
new VideoConfig("1080p", 3_000_000L, 1080, "/video/1080p", 0));
new VideoConfig("H.264 480p live", 800_000L, 480, "/video/480p"),
new VideoConfig("H.264 720p live", 1_200_000L, 720, "/video/720p"),
new VideoConfig("H.264 1080p live", 3_000_000L, 1080, "/video/1080p"));

/** This list defines the audio renditions that will be generated */
private static List<AudioConfig> audioProfile =
Collections.singletonList(new AudioConfig("128kbit", 128_000L, "/audio/128kb", 1));
Collections.singletonList(new AudioConfig("AAC 128 kbit/s", 128_000L, "/audio/128kb"));

private static String streamKey = "bitmovin";

Expand All @@ -121,18 +121,16 @@ public static void main(String[] args) throws Exception {
configProvider.getS3OutputSecretKey());

for (VideoConfig videoConfig : videoProfile) {
H264VideoConfiguration h264Configuration =
createH264VideoConfig(videoConfig.height, videoConfig.bitRate);
Stream stream =
createStream(encoding, input, h264Configuration, videoConfig.inputStreamPosition);
H264VideoConfiguration h264Config =
createH264VideoConfig(videoConfig.name, videoConfig.height, videoConfig.bitRate);
Stream stream = createStream(encoding, input, h264Config);

createFmp4Muxing(encoding, stream, output, videoConfig.outputPath);
}

for (AudioConfig audioConfig : audioProfile) {
AacAudioConfiguration aacConfig = createAacAudioConfig(audioConfig.bitrate);
Stream audioStream =
createStream(encoding, input, aacConfig, audioConfig.inputStreamPosition);
AacAudioConfiguration aacConfig = createAacAudioConfig(audioConfig.name, audioConfig.bitrate);
Stream audioStream = createStream(encoding, input, aacConfig);

createFmp4Muxing(encoding, audioStream, output, audioConfig.outputPath);
}
Expand Down Expand Up @@ -444,16 +442,14 @@ private static Encoding createEncoding(String name, String description) throws B
* https://bitmovin.com/docs/encoding/api-reference/sections/encodings#/Encoding/PostEncodingEncodingsStreamsByEncodingId
*
* @param encoding The encoding where to add the stream to
* @param input The input where the input file is located
* @param codecConfiguration The codec configuration to be applied to the stream
*/
private static Stream createStream(
Encoding encoding, Input input, CodecConfiguration codecConfiguration, int position)
Encoding encoding, Input input, CodecConfiguration codecConfiguration)
throws BitmovinException {
StreamInput streamInput = new StreamInput();
streamInput.setInputId(input.getId());
streamInput.setInputPath("live");
streamInput.setPosition(position);
streamInput.setSelectionMode(StreamSelectionMode.AUTO);

Stream stream = new Stream();
Expand All @@ -471,13 +467,14 @@ private static Stream createStream(
* href="https://bitmovin.com/docs/encoding/tutorials/how-to-optimize-your-h264-codec-configuration-for-different-use-cases">How
* to optimize your H264 codec configuration for different use-cases</a> for alternative presets.
*
* @param name The name of the configuration resource being created
* @param height The height of the output video
* @param bitrate The target bitrate of the output video
*/
private static H264VideoConfiguration createH264VideoConfig(int height, long bitrate)
private static H264VideoConfiguration createH264VideoConfig(String name, int height, long bitrate)
throws BitmovinException {
H264VideoConfiguration config = new H264VideoConfiguration();
config.setName(String.format("H.264 %dp live", height));
config.setName(name);
config.setPresetConfiguration(PresetConfiguration.LIVE_STANDARD);
config.setHeight(height);
config.setWidth((int) Math.ceil(aspectRatio * height));
Expand All @@ -492,61 +489,52 @@ private static H264VideoConfiguration createH264VideoConfig(int height, long bit
* <p>API endpoint:
* https://bitmovin.com/docs/encoding/api-reference/sections/configurations#/Encoding/PostEncodingConfigurationsAudioAac
*
* @param name The name of the configuration resource being created
* @param bitrate The target bitrate for the encoded audio
*/
private static AacAudioConfiguration createAacAudioConfig(long bitrate) throws BitmovinException {
private static AacAudioConfiguration createAacAudioConfig(String name, long bitrate) throws BitmovinException {
AacAudioConfiguration config = new AacAudioConfiguration();
config.setName(String.format("AAC %d kbit/s", bitrate / 1000));
config.setName(name);
config.setBitrate(bitrate);

return bitmovinApi.encoding.configurations.audio.aac.create(config);
}

private static class VideoConfig {

private String name;
private Long bitRate;
private Integer height;
private String outputPath;
private int inputStreamPosition;

/**
* @param name The name of the video configuration
* @param bitRate The target output bitrate of the video configuration
* @param height The target output height of the video configuration
* @param outputPath The output path for this video configuration
* @param inputStreamPosition The input stream position that is used for this video
* configuration
*/
private VideoConfig(
String name, Long bitRate, Integer height, String outputPath, int inputStreamPosition) {
String name, Long bitRate, Integer height, String outputPath) {
this.name = name;
this.bitRate = bitRate;
this.height = height;
this.outputPath = outputPath;
this.inputStreamPosition = inputStreamPosition;
}
}

private static class AudioConfig {

private String name;
private Long bitrate;
private String outputPath;
private int inputStreamPosition;

/**
* @param name The name of the audio configuration
* @param bitrate The target output bitrate of the audio configuration
* @param outputPath The output path for this audio configuration
* @param inputStreamPosition The input stream position that is used for this audio
* configuration
*/
public AudioConfig(String name, Long bitrate, String outputPath, int inputStreamPosition) {
public AudioConfig(String name, Long bitrate, String outputPath) {
this.name = name;
this.bitrate = bitrate;
this.outputPath = outputPath;
this.inputStreamPosition = inputStreamPosition;
}
}
}
Loading

0 comments on commit ef134b8

Please sign in to comment.