Ejemplo n.º 1
0
        public ArgumentCalculator(WorkItem wi, FFmpegPreset preset)
        {
            if (wi?.Media?.FFProbeMediaInfo == null)
            {
                throw new ArgumentException("MediaInfo is not available");
            }

            AudioStreams = wi.Media.FFProbeMediaInfo.AudioStreams ?? new HashSet <Stream>();
            VideoStreams = wi.Media.FFProbeMediaInfo.VideoStreams ?? new HashSet <Stream> ();

            Preset = preset;

            ColorPrimaries = wi.Media.FFProbeMediaInfo.VideoStreams?.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x.color_primaries))?.color_primaries;
            ColorTransfer  = wi.Media.FFProbeMediaInfo.VideoStreams?.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x.color_transfer))?.color_transfer;

            VideoEncoderOptions = new();
            foreach (var veo in preset.VideoEncoderOptions)
            {
                var eov = new EncoderOptionValue(veo.Name)
                {
                    AutoCalculate = veo.AutoCalculate,
                    EncoderOption = veo.EncoderOption,
                    Value         = veo.Value
                };
                VideoEncoderOptions.Add(eov);
            }
        }
Ejemplo n.º 2
0
        public static string GetDisplayName(this FFmpegPreset preset)
        {
            switch (preset)
            {
            case FFmpegPreset.H264Default:     return("H.264 Default (MP4)");

            case FFmpegPreset.H264Nvidia:      return("H.264 NVIDIA (MP4)");

            case FFmpegPreset.H264Lossless420: return("H.264 Lossless 420 (MP4)");

            case FFmpegPreset.H264Lossless444: return("H.264 Lossless 444 (MP4)");

            case FFmpegPreset.H265Default:     return("H.265 Default (MP4)");

            case FFmpegPreset.H265Nvidia:      return("H.265 NVIDIA (MP4)");

            case FFmpegPreset.ProRes422:       return("ProRes 422 (QuickTime)");

            case FFmpegPreset.ProRes4444:      return("ProRes 4444 (QuickTime)");

            case FFmpegPreset.VP8Default:      return("VP8 (WebM)");

            case FFmpegPreset.VP9Default:      return("VP9 (WebM)");
            }
            return(null);
        }
Ejemplo n.º 3
0
        public static string GetOptions(this FFmpegPreset preset)
        {
            switch (preset)
            {
            case FFmpegPreset.H264Default:     return("-pix_fmt yuv420p");

            case FFmpegPreset.H264Nvidia:      return("-c:v h264_nvenc -pix_fmt yuv420p");

            case FFmpegPreset.H264Lossless420: return("-pix_fmt yuv420p -preset ultrafast -crf 0");

            case FFmpegPreset.H264Lossless444: return("-pix_fmt yuv444p -preset ultrafast -crf 0");

            case FFmpegPreset.H265Default:     return("-c:v libx265 -pix_fmt yuv420p");

            case FFmpegPreset.H265Nvidia:      return("-c:v hevc_nvenc -pix_fmt yuv420p");

            case FFmpegPreset.ProRes422:       return("-c:v prores_ks -pix_fmt yuv422p10le");

            case FFmpegPreset.ProRes4444:      return("-c:v prores_ks -pix_fmt yuva444p10le");

            case FFmpegPreset.VP8Default:      return("-c:v libvpx -pix_fmt yuv420p");

            case FFmpegPreset.VP9Default:      return("-c:v libvpx-vp9");
            }
            return(null);
        }
Ejemplo n.º 4
0
 public static FFmpegSession Create(
     string streamURL,
     int width, int height, float frameRate,
     FFmpegPreset preset,
     int CrfValue,
     int maxBitrate
     )
 {
     return(CreateWithOutputPath(streamURL, width, height, frameRate, preset, CrfValue, maxBitrate));
 }
Ejemplo n.º 5
0
 public static FFmpegSession Create(
     string path,
     int width, int height, float frameRate,
     FFmpegPreset preset
     )
 {
     //name += System.DateTime.Now.ToString(" yyyy MMdd HHmmss");
     //var path = name.Replace(" ", "_") + preset.GetSuffix();
     return(CreateWithOutputPath(path, width, height, frameRate, preset));
 }
Ejemplo n.º 6
0
        void OnEnable()
        {
            _width     = serializedObject.FindProperty("_width");
            _height    = serializedObject.FindProperty("_height");
            _preset    = serializedObject.FindProperty("_preset");
            _frameRate = serializedObject.FindProperty("_frameRate");

            var presets = FFmpegPreset.GetValues(typeof(FFmpegPreset));

            _presetLabels = presets.Cast <FFmpegPreset>().
                            Select(p => new GUIContent(p.GetDisplayName())).ToArray();
            _presetOptions = presets.Cast <int>().ToArray();
        }
Ejemplo n.º 7
0
        public static FFmpegSession Create(
            string name,
            int width, int height, float frameRate,
            FFmpegPreset preset, bool recordAudio
            )
        {
#if !FFMPEG_OUT_CUSTOM_FILE_NAME
            name += System.DateTime.Now.ToString(" yyyy MMdd HHmmss");
#endif
            var    path       = name.Replace(" ", "_") + preset.GetSuffix();
            double sampleRate = AudioSettings.outputSampleRate;
            return(CreateWithOutputPath(path, width, height, frameRate, preset,
                                        recordAudio, sampleRate));
        }
Ejemplo n.º 8
0
 public static FFmpegSession CreateWithOutputPath(
     string outputPath,
     int width, int height, float frameRate,
     FFmpegPreset preset
     )
 {
     return(new FFmpegSession(
                "-y -f rawvideo -vcodec rawvideo -pixel_format rgba"
                + " -colorspace bt709"
                + " -video_size " + width + "x" + height
                + " -framerate " + frameRate
                + " -loglevel warning -i - " + preset.GetOptions()
                + " \"" + outputPath + "\""
                ));
 }
Ejemplo n.º 9
0
 public static FFmpegSession CreateWithOutputPath(
     string outputPath,
     int width, int height, float frameRate,
     FFmpegPreset preset
     )
 {
     return(new FFmpegSession(
                "-f rawvideo -vcodec rawvideo -pixel_format rgba"
                + " -colorspace bt709"
                + " -video_size " + width + "x" + height
                + " -framerate " + frameRate
                + " -loglevel warning -i - " + preset.GetOptions()
                + " -vcodec libx264 -acodec copy -preset:v ultrafast -tune:v zerolatency -f flv rtmp://..." //add you rtmp server url
                //+ " \"" + outputPath + "\""
                ));
 }
Ejemplo n.º 10
0
        void OnEnable()
        {
            _width       = serializedObject.FindProperty("_width");
            _height      = serializedObject.FindProperty("_height");
            _preset      = serializedObject.FindProperty("_preset");
            _frameRate   = serializedObject.FindProperty("_frameRate");
            _recordAudio = serializedObject.FindProperty("_recordAudio");
#if FFMPEG_OUT_CUSTOM_FILE_NAME
            _fileName = serializedObject.FindProperty("_fileName");
#endif

            var presets = FFmpegPreset.GetValues(typeof(FFmpegPreset));
            _presetLabels = presets.Cast <FFmpegPreset>().
                            Select(p => new GUIContent(p.GetDisplayName())).ToArray();
            _presetOptions = presets.Cast <int>().ToArray();
        }
Ejemplo n.º 11
0
        public static FFmpegSession CreateWithOutputPath(
            string outputPath,
            int width, int height, float frameRate,
            FFmpegPreset preset, bool recordAudio, double sampleRate
            )
        {
            /*
             * @"-y -framerate 30 -f rawvideo -pix_fmt rgb32 -video_size 800x600 "
             + @"-i unix:///var/folders/8q/p8gcyljs02lg80hxvyv49c800000gn/T/CoreFxPipe_ffv "
             +@"-f s16le -channels 1 -sample_rate 48000 "
             + @"-i unix:///var/folders/8q/p8gcyljs02lg80hxvyv49c800000gn/T/CoreFxPipe_ffa "
             +@"-map 0:0 -map 1:0 -vcodec libx264 -crf 23 -pix_fmt yuv420p -preset medium -r 30 -c:a aac out.mp4";
             + @"-y -v 9 -loglevel 99 " +
             + @" -thread_queue_size 512 -framerate "+out_fps+" -f rawvideo -pix_fmt rgb32 -video_size 800x600 " +
             + @"-i - " +
             + @"-f s16le -ac 1 -ar "+out_ar+" -thread_queue_size 512 " +
             + @"-i async:tcp://127.0.0.1:50505 -loglevel trace " +
             + @"-map 1:0 -map 0:0 -c:a aac -ac 1 -ar 48000 " + // -map 0:0 -map 1:0
             + @"-vcodec libx264 -crf 23 -pix_fmt yuv420p -preset ultrafast -r "+out_fps+" out.mp4"
             */
            string videoPipeName           = "-";
            string audioPipeName           = "async:tcp://127.0.0.1:50505?timeout=5000000";
            string audioInputSpecification = " ";
            string audioOutputOptions      = " "; // TODO: presets

            if (recordAudio)
            {
                // add audio pipe
                audioInputSpecification = " -f f32le -ac 2 -ar "
                                          + ((int)sampleRate).ToString() + " -thread_queue_size 512 -i " +
                                          audioPipeName;
                audioOutputOptions = " -map 0:0 -map 1:0 -c:a aac -ac 2 ";
            }

            string args = "-y -f rawvideo -thread_queue_size 512 -vcodec rawvideo -pixel_format rgba"
                          + " -colorspace bt709"
                          + " -video_size " + width + "x" + height
                          + " -framerate " + frameRate
                          + " -loglevel warning -i " + videoPipeName
                          + audioInputSpecification
                          + audioOutputOptions
                          + preset.GetOptions()
                          + " \"" + outputPath + "\"";

            UnityEngine.Debug.Log(args);
            return(new FFmpegSession(args, recordAudio));
        }
Ejemplo n.º 12
0
        protected override void OnEnable()
        {
            base.OnEnable();
            if (target == null)
            {
                return;
            }

            _preset = serializedObject.FindProperty("preset");

            // Preset labels
            var presets = FFmpegPreset.GetValues(typeof(FFmpegPreset));

            _presetLabels = presets.Cast <FFmpegPreset>().
                            Select(p => new GUIContent(p.GetDisplayName())).ToArray();
            _presetOptions = presets.Cast <int>().ToArray();
        }
Ejemplo n.º 13
0
 public FFmpegPresetBase(FFmpegPreset preset)
 {
     AudioStreamPresets = preset.AudioStreamPresets.Select(x => new FFmpegAudioStreamPresetBase(x)).ToList();
     B_Frames           = preset.B_Frames;
     Container          = preset.Container;
     CopyAttachments    = preset.CopyAttachments;
     CopyData           = preset.CopyData;
     CopyMetadata       = preset.CopyMetadata;
     CopySubtitles      = preset.CopySubtitles;
     FrameRate          = preset.FrameRate;
     HardwareDecoder    = preset.HardwareDecoder;
     Name = preset.Name;
     OptionalArguments    = preset.OptionalArguments;
     SubtitleEncoder      = new(preset.SubtitleEncoder);
     VideoBitRate         = preset.VideoBitRate;
     VideoBitRateAutoCalc = preset.VideoBitRateAutoCalc;
     VideoEncoderOptions  = preset.VideoEncoderOptions?.Select(x => new EncoderOptionValueBase(x)).ToHashSet();
     VideoEncoder         = new(preset.VideoEncoder);
 }
Ejemplo n.º 14
0
        public static string GetSuffix(this FFmpegPreset preset)
        {
            switch (preset)
            {
            case FFmpegPreset.H264Default:
            case FFmpegPreset.H264Nvidia:
            case FFmpegPreset.H264Lossless420:
            case FFmpegPreset.H264Lossless444:
            case FFmpegPreset.H265Default:
            case FFmpegPreset.H265Nvidia:      return(".mp4");

            case FFmpegPreset.ProRes422:
            case FFmpegPreset.ProRes4444:      return(".mov");

            case FFmpegPreset.VP9Default:
            case FFmpegPreset.VP8Default:      return(".webm");
            }
            return(null);
        }
Ejemplo n.º 15
0
        public static FFmpegSession CreateWithOutputPath(
            string streamURL,
            int width, int height, float frameRate,
            FFmpegPreset preset,
            int CrfValue,
            int maxBitrate
            )
        {
            string m_Path = Application.dataPath;

            return(new FFmpegSession(
                       "-y -f rawvideo -fflags +genpts -vcodec rawvideo -pixel_format rgba"
                       + " -colorspace bt709"
                       + " -video_size " + width + "x" + height
                       + " -framerate " + frameRate
                       + " -loglevel warning -i - " + preset.GetOptions()
                       + " -an -vpre x264-preset -crf " + CrfValue + " -maxrate " + maxBitrate + "k -bufsize " + maxBitrate + "k -g " + frameRate * 2 + " -rtsp_transport tcp -f rtsp " + streamURL

                       ));
        }
        void OnEnable()
        {
            _colorStreamWidth  = serializedObject.FindProperty("_colorStreamWidth");
            _colorStreamHeight = serializedObject.FindProperty("_colorStreamHeight");
            _depthStreamWidth  = serializedObject.FindProperty("_depthStreamWidth");
            _depthStreamHeight = serializedObject.FindProperty("_depthStreamHeight");
            _preset            = serializedObject.FindProperty("_preset");
            _frameRate         = serializedObject.FindProperty("_frameRate");
            _colorStreamURL    = serializedObject.FindProperty("_colorStreamURL");
            _depthStreamURL    = serializedObject.FindProperty("_depthStreamURL");
            _crfValue          = serializedObject.FindProperty("_crfValue");
            _maxBitrate        = serializedObject.FindProperty("_maxBitrate");



            var presets = FFmpegPreset.GetValues(typeof(FFmpegPreset));

            _presetLabels = presets.Cast <FFmpegPreset>().
                            Select(p => new GUIContent(p.GetDisplayName())).ToArray();
            _presetOptions = presets.Cast <int>().ToArray();
        }
Ejemplo n.º 17
0
        public async Task <string> SetArguments(FFmpegPreset preset, WorkItem wi, CancellationToken token, bool force = false)
        {
            using (logger.BeginScope("Set Arguments"))
            {
                if (wi.Arguments == null || force)
                {
                    await applicationService.InitialisePresets;

                    if (wi.Media?.FFProbeMediaInfo == null)
                    {
                        var ffProbeResponse = await fFmpegProcessor.GetFFProbeInfo(wi.Media.FilePath, token);

                        if (ffProbeResponse.Success)
                        {
                            wi.Media.FFProbeMediaInfo = ffProbeResponse.Result;
                        }
                        else
                        {
                            return(ffProbeResponse.ErrorMessage);
                        }
                    }

                    wi.ArgumentCalculator = new ArgumentCalculator(wi, preset);

                    await CalculateBestOptions(wi, token);

                    if (token.IsCancellationRequested)
                    {
                        return("Process cancelled");
                    }

                    wi.Arguments = GetArguments(wi);
                }

                return(null);
            }
        }