示例#1
0
        private string GetCommandLineArgs(MediaSourceInfo mediaSource, string inputTempFile, string targetFile, TimeSpan duration)
        {
            string videoArgs;

            if (EncodeVideo(mediaSource))
            {
                var maxBitrate = 25000000;
                videoArgs = string.Format(
                    "-codec:v:0 libx264 -force_key_frames \"expr:gte(t,n_forced*5)\" {0} -pix_fmt yuv420p -preset superfast -crf 23 -b:v {1} -maxrate {1} -bufsize ({1}*2) -vsync -1 -profile:v high -level 41",
                    GetOutputSizeParam(),
                    maxBitrate.ToString(CultureInfo.InvariantCulture));
            }
            else
            {
                videoArgs = "-codec:v:0 copy";
            }

            var durationParam   = " -t " + _mediaEncoder.GetTimeParameter(duration.Ticks);
            var inputModifiers  = "-fflags +genpts -async 1 -vsync -1";
            var commandLineArgs = "-i \"{0}\"{5} {2} -map_metadata -1 -threads 0 {3}{4}{6} -y \"{1}\"";

            long startTimeTicks = 0;

            //if (mediaSource.DateLiveStreamOpened.HasValue)
            //{
            //    var elapsed = DateTime.UtcNow - mediaSource.DateLiveStreamOpened.Value;
            //    elapsed -= TimeSpan.FromSeconds(10);
            //    if (elapsed.TotalSeconds >= 0)
            //    {
            //        startTimeTicks = elapsed.Ticks + startTimeTicks;
            //    }
            //}

            if (mediaSource.ReadAtNativeFramerate)
            {
                inputModifiers += " -re";
            }

            if (startTimeTicks > 0)
            {
                inputModifiers = "-ss " + _mediaEncoder.GetTimeParameter(startTimeTicks) + " " + inputModifiers;
            }

            var analyzeDurationSeconds = 5;
            var analyzeDuration        = " -analyzeduration " +
                                         (analyzeDurationSeconds * 1000000).ToString(CultureInfo.InvariantCulture);

            inputModifiers += analyzeDuration;

            var subtitleArgs = CopySubtitles ? " -codec:s copy" : " -sn";

            var outputParam = string.Equals(Path.GetExtension(targetFile), ".mp4", StringComparison.OrdinalIgnoreCase) ?
                              " -f mp4 -movflags frag_keyframe+empty_moov" :
                              string.Empty;

            commandLineArgs = string.Format(commandLineArgs, inputTempFile, targetFile, videoArgs, GetAudioArgs(mediaSource), subtitleArgs, durationParam, outputParam);

            return(inputModifiers + " " + commandLineArgs);
        }
示例#2
0
        private string GetCommandLineArgs(MediaSourceInfo mediaSource, string inputTempFile, string targetFile, TimeSpan duration)
        {
            string videoArgs;

            if (EncodeVideo(mediaSource))
            {
                var maxBitrate = 25000000;
                videoArgs = string.Format(
                    "-codec:v:0 libx264 -force_key_frames \"expr:gte(t,n_forced*5)\" {0} -pix_fmt yuv420p -preset superfast -crf 23 -b:v {1} -maxrate {1} -bufsize ({1}*2) -vsync -1 -profile:v high -level 41",
                    GetOutputSizeParam(),
                    maxBitrate.ToString(CultureInfo.InvariantCulture));
            }
            else
            {
                videoArgs = "-codec:v:0 copy";
            }

            var durationParam   = " -t " + _mediaEncoder.GetTimeParameter(duration.Ticks);
            var commandLineArgs = "-fflags +genpts -async 1 -vsync -1 -re -i \"{0}\"{4} -sn {2} -map_metadata -1 -threads 0 {3} -y \"{1}\"";

            if (mediaSource.ReadAtNativeFramerate)
            {
                commandLineArgs = "-re " + commandLineArgs;
            }

            commandLineArgs = string.Format(commandLineArgs, inputTempFile, targetFile, videoArgs, GetAudioArgs(mediaSource), durationParam);

            return(commandLineArgs);
        }
        private string GetCommandLineArgs(MediaSourceInfo mediaSource, string inputTempFile, string targetFile, TimeSpan duration)
        {
            string videoArgs;

            if (EncodeVideo(mediaSource))
            {
                var maxBitrate = 25000000;
                videoArgs = string.Format(
                    "-codec:v:0 libx264 -force_key_frames \"expr:gte(t,n_forced*5)\" {0} -pix_fmt yuv420p -preset superfast -crf 23 -b:v {1} -maxrate {1} -bufsize ({1}*2) -vsync -1 -profile:v high -level 41",
                    GetOutputSizeParam(),
                    maxBitrate.ToString(CultureInfo.InvariantCulture));
            }
            else
            {
                videoArgs = "-codec:v:0 copy";
            }

            var durationParam   = " -t " + _mediaEncoder.GetTimeParameter(duration.Ticks);
            var inputModifiers  = "-fflags +genpts -async 1 -vsync -1";
            var commandLineArgs = "-i \"{0}\"{4} -sn {2} -map_metadata -1 -threads 0 {3} -y \"{1}\"";

            long startTimeTicks = 0;

            //if (mediaSource.DateLiveStreamOpened.HasValue)
            //{
            //    var elapsed = DateTime.UtcNow - mediaSource.DateLiveStreamOpened.Value;
            //    elapsed -= TimeSpan.FromSeconds(10);
            //    if (elapsed.TotalSeconds >= 0)
            //    {
            //        startTimeTicks = elapsed.Ticks + startTimeTicks;
            //    }
            //}

            if (mediaSource.ReadAtNativeFramerate)
            {
                inputModifiers += " -re";
            }

            if (startTimeTicks > 0)
            {
                inputModifiers = "-ss " + _mediaEncoder.GetTimeParameter(startTimeTicks) + " " + inputModifiers;
            }

            commandLineArgs = string.Format(commandLineArgs, inputTempFile, targetFile, videoArgs, GetAudioArgs(mediaSource), durationParam);

            return(inputModifiers + " " + commandLineArgs);
        }
示例#4
0
        private string GetCommandLineArgs(MediaSourceInfo mediaSource, string inputTempFile, string targetFile, TimeSpan duration)
        {
            string videoArgs;

            if (EncodeVideo(mediaSource))
            {
                var maxBitrate = 25000000;
                videoArgs = string.Format(
                    "-codec:v:0 libx264 -force_key_frames \"expr:gte(t,n_forced*5)\" {0} -pix_fmt yuv420p -preset superfast -crf 23 -b:v {1} -maxrate {1} -bufsize ({1}*2) -vsync -1 -profile:v high -level 41",
                    GetOutputSizeParam(),
                    maxBitrate.ToString(CultureInfo.InvariantCulture));
            }
            else
            {
                videoArgs = "-codec:v:0 copy";
            }

            videoArgs += " -fflags +genpts";

            var durationParam = " -t " + _mediaEncoder.GetTimeParameter(duration.Ticks);

            var flags = new List <string>();

            if (mediaSource.IgnoreDts)
            {
                flags.Add("+igndts");
            }
            if (mediaSource.IgnoreIndex)
            {
                flags.Add("+ignidx");
            }
            if (mediaSource.GenPtsInput)
            {
                flags.Add("+genpts");
            }

            var inputModifier = "-async 1 -vsync -1";

            if (flags.Count > 0)
            {
                inputModifier += " -fflags " + string.Join("", flags.ToArray());
            }

            if (!string.IsNullOrWhiteSpace(GetEncodingOptions().HardwareAccelerationType))
            {
                inputModifier += " -hwaccel auto";
            }

            if (mediaSource.ReadAtNativeFramerate)
            {
                inputModifier += " -re";
            }

            if (mediaSource.RequiresLooping)
            {
                inputModifier += " -stream_loop -1";
            }

            var analyzeDurationSeconds = 5;
            var analyzeDuration        = " -analyzeduration " +
                                         (analyzeDurationSeconds * 1000000).ToString(CultureInfo.InvariantCulture);

            inputModifier += analyzeDuration;

            var subtitleArgs = CopySubtitles ? " -codec:s copy" : " -sn";

            //var outputParam = string.Equals(Path.GetExtension(targetFile), ".mp4", StringComparison.OrdinalIgnoreCase) ?
            //    " -f mp4 -movflags frag_keyframe+empty_moov" :
            //    string.Empty;

            var outputParam = string.Empty;

            var commandLineArgs = string.Format("-i \"{0}\"{5} {2} -map_metadata -1 -threads 0 {3}{4}{6} -y \"{1}\"",
                                                inputTempFile,
                                                targetFile,
                                                videoArgs,
                                                GetAudioArgs(mediaSource),
                                                subtitleArgs,
                                                durationParam,
                                                outputParam);

            return(inputModifier + " " + commandLineArgs);
        }