Example #1
0
        /// <summary>
        /// Creates a collection of audio mix channels <para />
        ///
        /// API endpoint:
        /// https://bitmovin.com/docs/encoding/api-reference/sections/encodings#/Encoding/PostEncodingEncodingsInputStreamsIngestByEncodingId
        /// </summary>
        /// <param name="encoding">The encoding to which the stream will be added</param>
        /// <param name="input"> The input resource providing the input file</param>
        /// <param name="inputPath"> The path to the input file</param>
        /// <param name="mappingConfigs">The configuration of the mapping of source channels to output channels</param>
        private async Task <List <AudioMixInputStreamChannel> > CreateAudioMixInputStreamChannels(Models.Encoding encoding,
                                                                                                  Input input, String inputPath, List <ChannelMappingConfiguration> mappingConfigs)
        {
            var audioMixInputStream = new List <AudioMixInputStreamChannel>();

            foreach (var mappingConfig in mappingConfigs)
            {
                var audioIngestInputStream =
                    await CreateIngestInputStreamForAudioTrack(encoding, input, inputPath,
                                                               mappingConfig.SourceChannelNumber);

                var sourceChannel = new AudioMixInputStreamSourceChannel()
                {
                    Type          = AudioMixSourceChannelType.CHANNEL_NUMBER,
                    ChannelNumber = 0
                };

                var outputChannel = new AudioMixInputStreamChannel()
                {
                    InputStreamId  = audioIngestInputStream.Id, OutputChannelType = mappingConfig.OutputChannelType,
                    SourceChannels = new List <AudioMixInputStreamSourceChannel>()
                    {
                        sourceChannel
                    }
                };
                audioMixInputStream.Add(outputChannel);
            }

            return(audioMixInputStream);
        }
        /// <summary>
        /// Adds an audio stream to an encoding, by remixing multiple channels from a source input stream
        /// API endpoint:
        /// https://bitmovin.com/docs/encoding/api-reference/sections/encodings#/Encoding/PostEncodingEncodingsInputStreamsAudioMixByEncodingId
        /// </summary>
        /// <param name="encoding">The encoding to which the stream will be added</param>
        /// <param name="inputStream">The inputStream resource providing the input file</param>
        /// <param name="channelConfigs">The configuration of the source channel mixing and mapping to the output channels</param>
        private Task <AudioMixInputStream> CreateDownmixInputStream(Models.Encoding encoding, InputStream inputStream, List <DownmixConfig> channelConfigs)
        {
            var audioMixInputStream = new AudioMixInputStream()
            {
                Name          = "Downmixing 5.1 to stereo",
                ChannelLayout = AudioMixInputChannelLayout.CL_STEREO
            };

            foreach (DownmixConfig channelConfig in channelConfigs)
            {
                var outputChannel = new AudioMixInputStreamChannel()
                {
                    InputStreamId     = inputStream.Id,
                    OutputChannelType = channelConfig.OutputChannelType
                };

                foreach (DownmixConfigChannel channelSource in channelConfig.SourceChannels)
                {
                    var sourceChannel = new AudioMixInputStreamSourceChannel()
                    {
                        Type = channelSource.SourceChannelType,
                        Gain = channelSource.Gain
                    };
                    outputChannel.SourceChannels.Add(sourceChannel);
                }
                audioMixInputStream.AudioMixChannels.Add(outputChannel);
            }
            return(_bitmovinApi.Encoding.Encodings.InputStreams.AudioMix.CreateAsync(encoding.Id, audioMixInputStream));
        }
        public async Task RunExample(string[] args)
        {
            _configProvider = new ConfigProvider(args);
            _bitmovinApi    = BitmovinApi.Builder
                              .WithApiKey(_configProvider.GetBitmovinApiKey())
                              // uncomment the following line if you are working with a multi-tenant account
                              // .WithTenantOrgIdKey(_configProvider.GetBitmovinTenantOrgId())
                              .WithLogger(new ConsoleLogger())
                              .Build();

            var encoding = await CreateEncoding("Audio Mapping - Stream Merging",
                                                "Multiple stereo input tracks -> Output with single merged stereo track");

            var h264Config = await CreateH264VideoConfiguration();

            var aacConfig = await CreateAacAudioConfiguration();

            var input = await CreateHttpInput(_configProvider.GetHttpInputHost());

            var output = await CreateS3Output(_configProvider.GetS3OutputBucketName(),
                                              _configProvider.GetS3OutputAccessKey(),
                                              _configProvider.GetS3OutputSecretKey());

            var inputFilePath          = _configProvider.GetHttpInputFilePathWithTwoStereoTracks();
            var videoIngestInputStream = await CreateIngestInputStream(encoding, input, inputFilePath);

            var mainAudioIngestInputStream =
                await CreateIngestInputStreamForAudioTrack(encoding, input, inputFilePath, 0);

            var secondaryAudioIngestInputStream =
                await CreateIngestInputStreamForAudioTrack(encoding, input, inputFilePath, 1);

            var secondaryAudioMixInputStream = new AudioMixInputStream
            {
                ChannelLayout = AudioMixInputChannelLayout.CL_STEREO
            };

            for (var i = 0; i <= 1; i++)
            {
                var sourceChannel = new AudioMixInputStreamSourceChannel
                {
                    Type          = AudioMixSourceChannelType.CHANNEL_NUMBER,
                    ChannelNumber = i,
                    Gain          = 0.5
                };

                var inputStreamChannel = new AudioMixInputStreamChannel
                {
                    InputStreamId       = secondaryAudioIngestInputStream.Id,
                    OutputChannelType   = AudioMixChannelType.CHANNEL_NUMBER,
                    OutputChannelNumber = i,
                    SourceChannels      = new List <AudioMixInputStreamSourceChannel>()
                    {
                        sourceChannel
                    }
                };

                secondaryAudioMixInputStream.AudioMixChannels.Add(inputStreamChannel);
            }

            secondaryAudioMixInputStream = await _bitmovinApi.Encoding.Encodings.InputStreams.AudioMix.CreateAsync(
                encoding.Id, secondaryAudioMixInputStream);

            var videoStream =
                await CreateStream(encoding, new List <InputStream>() { videoIngestInputStream }, h264Config);

            var audioStream =
                await CreateStream(
                    encoding,
                    new List <InputStream>() { mainAudioIngestInputStream, secondaryAudioMixInputStream },
                    aacConfig);

            await CreateMp4Muxing(
                encoding,
                output,
                "/",
                new List <Stream>() { videoStream, audioStream },
                "stereo-and-surround-tracks-mapped.mp4");

            await ExecuteEncoding(encoding);
        }
        public async Task RunExample(string[] args)
        {
            _configProvider = new ConfigProvider(args);
            _bitmovinApi    = BitmovinApi.Builder
                              .WithApiKey(_configProvider.GetBitmovinApiKey())
                              // uncomment the following line if you are working with a multi-tenant account
                              // .WithTenantOrgIdKey(_configProvider.GetBitmovinTenantOrgId())
                              .WithLogger(new ConsoleLogger())
                              .Build();

            var encoding = await CreateEncoding("Audio Mapping - Channel Mixing - Swapping Channels",
                                                "Input with stereo track -> Output with swapped stereo tracks");

            var input = await CreateHttpInput(_configProvider.GetHttpInputHost());

            var output = await CreateS3Output(_configProvider.GetS3OutputBucketName(),
                                              _configProvider.GetS3OutputAccessKey(),
                                              _configProvider.GetS3OutputSecretKey());

            var inputFilePath = _configProvider.GetHttpInputFilePathWithStereoSound();

            // Create an H264 video configuration.
            var h264VideoConfig = await CreateH264VideoConfiguration();

            // Create an AAC audio configuration.
            var aacAudioConfig = await CreateAacAudioConfiguration();

            // Add video and audio ingest input streams.
            var videoIngestInputStream = await CreateIngestInputStream(encoding, input, inputFilePath);

            var audioIngestInputStream = await CreateIngestInputStream(encoding, input, inputFilePath);

            var audioMixInputStream = new AudioMixInputStream()
            {
                Name          = "Swapping channels 0 and 1",
                ChannelLayout = AudioMixInputChannelLayout.CL_STEREO
            };

            var sourceChannel0 = new AudioMixInputStreamSourceChannel()
            {
                Type          = AudioMixSourceChannelType.CHANNEL_NUMBER,
                ChannelNumber = 0
            };

            var sourceChannel1 = new AudioMixInputStreamSourceChannel()
            {
                Type          = AudioMixSourceChannelType.CHANNEL_NUMBER,
                ChannelNumber = 1
            };

            var outputChannel0 = new AudioMixInputStreamChannel()
            {
                InputStreamId       = audioIngestInputStream.Id,
                OutputChannelType   = AudioMixChannelType.CHANNEL_NUMBER,
                OutputChannelNumber = 0,
                SourceChannels      = new List <AudioMixInputStreamSourceChannel> {
                    sourceChannel1
                }
            };

            var outputChannel1 = new AudioMixInputStreamChannel()
            {
                InputStreamId       = audioIngestInputStream.Id,
                OutputChannelType   = AudioMixChannelType.CHANNEL_NUMBER,
                OutputChannelNumber = 1,
                SourceChannels      = new List <AudioMixInputStreamSourceChannel> {
                    sourceChannel0
                }
            };

            var audioMixChannels = new List <AudioMixInputStreamChannel>()
            {
                outputChannel0, outputChannel1
            };

            audioMixInputStream = await CreateAudioMixInputStream(encoding, audioMixInputStream, audioMixChannels);

            // Create streams and add them to the encoding.
            var videoStream = await CreateStream(encoding, videoIngestInputStream, h264VideoConfig);

            var audioStream = await CreateStream(encoding, audioMixInputStream, aacAudioConfig);

            var streams = new List <Stream>();

            streams.Add(videoStream);
            streams.Add(audioStream);

            await CreateMp4Muxing(encoding, output, "/", streams, "stereo-track-swapped.mp4");
            await ExecuteEncoding(encoding);
        }