Пример #1
0
        protected override string GetAudioArguments(StreamState state, EncodingOptions encodingOptions)
        {
            var audioCodec = EncodingHelper.GetAudioEncoder(state);

            if (!state.IsOutputVideo)
            {
                if (string.Equals(audioCodec, "copy", StringComparison.OrdinalIgnoreCase))
                {
                    return("-acodec copy");
                }

                var audioTranscodeParams = new List <string>();

                audioTranscodeParams.Add("-acodec " + audioCodec);

                if (state.OutputAudioBitrate.HasValue)
                {
                    audioTranscodeParams.Add("-ab " + state.OutputAudioBitrate.Value.ToString(UsCulture));
                }

                if (state.OutputAudioChannels.HasValue)
                {
                    audioTranscodeParams.Add("-ac " + state.OutputAudioChannels.Value.ToString(UsCulture));
                }

                if (state.OutputAudioSampleRate.HasValue)
                {
                    audioTranscodeParams.Add("-ar " + state.OutputAudioSampleRate.Value.ToString(UsCulture));
                }

                audioTranscodeParams.Add("-vn");
                return(string.Join(" ", audioTranscodeParams.ToArray()));
            }

            if (string.Equals(audioCodec, "copy", StringComparison.OrdinalIgnoreCase))
            {
                var videoCodec = EncodingHelper.GetVideoEncoder(state, encodingOptions);

                if (string.Equals(videoCodec, "copy", StringComparison.OrdinalIgnoreCase) && state.EnableBreakOnNonKeyFrames(videoCodec))
                {
                    return("-codec:a:0 copy -copypriorss:a:0 0");
                }

                return("-codec:a:0 copy");
            }

            var args = "-codec:a:0 " + audioCodec;

            var channels = state.OutputAudioChannels;

            if (channels.HasValue)
            {
                args += " -ac " + channels.Value;
            }

            var bitrate = state.OutputAudioBitrate;

            if (bitrate.HasValue)
            {
                args += " -ab " + bitrate.Value.ToString(UsCulture);
            }

            if (state.OutputAudioSampleRate.HasValue)
            {
                args += " -ar " + state.OutputAudioSampleRate.Value.ToString(UsCulture);
            }

            args += " " + EncodingHelper.GetAudioFilterParam(state, encodingOptions, true);

            return(args);
        }