private void AddFont(ObsProperty property, ObsData setting, List <Control> controls)
        {
            string name = property.Name;

            Label label = new Label
            {
                Width       = 300,
                Height      = 60,
                AutoSize    = false,
                BorderStyle = BorderStyle.Fixed3D,
                TextAlign   = ContentAlignment.MiddleCenter
            };

            Button button = new Button {
                Text = "Select..."
            };

            using (ObsData fontData = new ObsData(setting.GetObject(name)))
            {
                string family = fontData.GetString("face");
                //string style = fontData.GetString("style");	//not supported in Windows
                ObsFontFlags flags = (ObsFontFlags)fontData.GetInt("flags");

                label.Font = new Font(family, 25F, (FontStyle)flags);;
                label.Text = family;
            }

            button.Click += (sender, args) =>
            {
                var fontDialog = new FontDialog();

                using (ObsData fontData = new ObsData(setting.GetObject(name)))
                {
                    float size = fontData.GetInt("size");
                    fontDialog.Font = new Font(label.Font.FontFamily, size, label.Font.Style);
                }

                if (fontDialog.ShowDialog() == DialogResult.OK)
                {
                    var font = fontDialog.Font;

                    using (ObsData fontData = new ObsData(setting.GetObject(name)))
                    {
                        fontData.SetString("face", font.Name.ToString());
                        fontData.SetString("style", "");                                //not supported in Windows
                        fontData.SetInt("size", (int)font.SizeInPoints);
                        fontData.SetInt("flags", (int)font.Style);
                    }

                    view.PropertyChanged(property);

                    font       = new Font(font.Name, 25f, font.Style);
                    label.Font = font;
                    label.Text = font.Name;
                }
            };

            controls.Add(label);
            controls.Add(button);
        }
示例#2
0
        /// <summary>
        /// Creates a new Obs audio encoder with default settings.
        /// </summary>
        /// <returns></returns>
        public static ObsEncoder CreateAudioEncoder()
        {
            // mf_aac for W8 and later, ffmpeg_aac for W7
            string encoderId = "mf_aac";

            // Windows 7 is Version 6.1. Check if version 6.1 and below. We don't support anything below Windows 7.
            if (System.Environment.OSVersion.Platform == PlatformID.Win32NT &&
                ((System.Environment.OSVersion.Version.Major == 6 && System.Environment.OSVersion.Version.Minor <= 1) ||
                 System.Environment.OSVersion.Version.Major < 6)
                )
            {
                encoderId = "ffmpeg_aac";
            }

            ObsEncoder obsAudioEncoder = new ObsEncoder(ObsEncoderType.Audio, encoderId, "simple_aac");

            obsAudioEncoder.SetAudio(Obs.GetAudio());

            ObsData audioEncoderSettings = new ObsData();

            audioEncoderSettings.SetInt("bitrate", Constants.Audio.ENCODER_BITRATE);
            audioEncoderSettings.SetString("rate_control", Constants.Audio.RATE_CONTROL);
            audioEncoderSettings.SetInt("samplerate", Constants.Audio.SAMPLES_PER_SEC);
            audioEncoderSettings.SetBoolDefault("allow he-aac", true);
            obsAudioEncoder.Update(audioEncoderSettings);
            audioEncoderSettings.Dispose();

            return(obsAudioEncoder);
        }
        private void AddColor(ObsProperty property, ObsData setting, List <Control> controls)
        {
            string name = property.Name;

            // note: libobs stores color in ABGR instead of ARGB

            Color   color   = ColorHelper.FromAbgr((int)setting.GetInt(name));
            TextBox textbox = new TextBox
            {
                Width     = 300,
                ForeColor = color.GetBrightness() > 0.93 ? Color.Black : color,
                Text      = color.ToHtml(),
                TextAlign = HorizontalAlignment.Center
            };

            Button button = new Button {
                Text = "Select..."
            };

            textbox.TextChanged += (sender, args) =>
            {
                Color newColor = ColorHelper.FromAbgr((int)setting.GetInt(name));
                newColor = newColor.FromHtml(textbox.Text);

                textbox.ForeColor = newColor.GetBrightness() > 0.93 ? Color.Black : newColor;
                setting.SetInt(name, newColor.ToAbgr());
                view.PropertyChanged(property);
            };

            button.Click += (sender, args) =>
            {
                ColorDialog colorDialog = new ColorDialog
                {
                    AllowFullOpen = true,
                    AnyColor      = true,
                    Color         = ColorHelper.TryColorFromHtml(textbox.Text),
                    FullOpen      = true
                };
                colorDialog.Color = colorDialog.Color.FromHtml(textbox.Text);

                if (colorDialog.ShowDialog(this) == DialogResult.OK)
                {
                    textbox.Text = colorDialog.Color.ToHtml();
                }
            };

            controls.Add(textbox);
            controls.Add(button);
        }
示例#4
0
        /// <summary>
        /// Creates a new Obs video encoder with default settings.
        /// </summary>
        /// <returns></returns>
        public static ObsEncoder CreateVideoEncoder()
        {
            ObsEncoder obsVideoEncoder = new ObsEncoder(ObsEncoderType.Video, "obs_x264", "simple_h264_stream");
            IntPtr     obsVideoPointer = Obs.GetVideo();

            obsVideoEncoder.SetVideo(obsVideoPointer);

            ObsData videoEncoderSettings = new ObsData();

            videoEncoderSettings.SetInt("bitrate", Constants.Video.ENCODER_BITRATE);
            videoEncoderSettings.SetString("rate_control", Constants.Video.RATE_CONTROL);
            obsVideoEncoder.Update(videoEncoderSettings);
            videoEncoderSettings.Dispose();

            return(obsVideoEncoder);
        }
示例#5
0
        private ObsData CreateWebcamSettings()
        {
            ObsData webcamSettings = new ObsData();

            webcamSettings.SetString(VideoCapture.VIDEO_DEVICE_ID, selectedWebcam.value);

            int buffering = 2;

            webcamSettings.SetInt(VideoCapture.BUFFERING, buffering); // 0 = Auto, 1 = Enable, 2 = Disable

            // need to check webcam whitelist
            if (Store.Data.Webcam.WebcamSettings.ShouldUseCustomSettings)
            {
                webcamSettings.SetString(VideoCapture.RESOLUTION, Store.Data.Webcam.WebcamSettings.Resolution);
                webcamSettings.SetInt(VideoCapture.RESOLUTION_TYPE, 1);
                webcamSettings.SetInt(VideoCapture.VIDEO_FORMAT, (int)Store.Data.Webcam.WebcamSettings.VideoFormat);
                webcamSettings.SetInt(VideoCapture.FRAME_INTERVAL, Store.Data.Webcam.WebcamSettings.Fps);
            }
            else
            {
                if (selectedWebcamResolution != null)
                {
                    webcamSettings.SetString(VideoCapture.RESOLUTION, selectedWebcamResolution.value);
                    webcamSettings.SetInt(VideoCapture.RESOLUTION_TYPE, 1);
                }
                else
                {
                    var preferredResolution = WebcamService.GetOptimalWebcamResolution(selectedWebcam.dsDeviceValue);

                    if (!string.IsNullOrEmpty(preferredResolution))
                    {
                        webcamSettings.SetString(VideoCapture.RESOLUTION, preferredResolution);
                        webcamSettings.SetInt(VideoCapture.RESOLUTION_TYPE, 1);
                    }
                    else
                    {
                        webcamSettings.Erase(VideoCapture.RESOLUTION);
                        webcamSettings.SetInt(VideoCapture.RESOLUTION_TYPE, 0);
                    }
                }
            }

            webcamSettings.SetBool(VideoCapture.ACTIVATE, true);

            return(webcamSettings);
        }
        private void AddList(ObsProperty property, ObsData setting, List <Control> controls)
        {
            string name = property.Name;

            int index = 0;

            string[]     names  = property.GetListItemNames();
            object[]     values = property.GetListItemValues();
            EventHandler selectedIndexChanged = null;
            ComboBox     combobox             = new ComboBox {
                Width = 300
            };

            combobox.Items.AddRange(names.ToArray());

            //if (namelist.Length > 0)
            //	combobox.SelectedIndex = 0;

            if (property.ListType == ObsComboType.List)
            {
                combobox.DropDownStyle = ComboBoxStyle.DropDownList;
            }

            switch (property.ListFormat)
            {
            case ObsComboFormat.Float:
            {
                index = Array.IndexOf(values, setting.GetDouble(name));

                selectedIndexChanged = (sender, args) =>
                {
                    double value = (double)values.GetValue(combobox.SelectedIndex);
                    setting.SetDouble(name, value);
                    view.PropertyChanged(property);
                };
                break;
            }

            case ObsComboFormat.Int:
            {
                var val = setting.GetInt(name);
                index = Array.IndexOf(values, setting.GetInt(name));

                selectedIndexChanged = (sender, args) =>
                {
                    long value = (long)values[combobox.SelectedIndex];
                    setting.SetInt(name, (int)value);
                    view.PropertyChanged(property);
                };
                break;
            }

            case ObsComboFormat.String:
            {
                index = Array.IndexOf(values, setting.GetString(name));

                selectedIndexChanged = (sender, args) =>
                {
                    string value = (string)values[combobox.SelectedIndex];
                    setting.SetString(name, value);
                    view.PropertyChanged(property);
                };
                break;
            }
            }

            if (index != -1)
            {
                combobox.SelectedIndex = index;
            }

            combobox.SelectedIndexChanged += selectedIndexChanged;

            if (index == -1 && names.Length > 0)
            {
                combobox.SelectedIndex = 0;
            }

            controls.Add(combobox);
        }
        private void AddNumeric(ObsProperty property, ObsData setting, List <Control> controls)
        {
            ObsPropertyType type = property.Type;
            string          name = property.Name;

            NumericUpDown numeric = new NumericUpDown
            {
                Width         = 300,
                DecimalPlaces = 0
            };

            if (type == ObsPropertyType.Int)
            {
                int  intMin   = property.IntMin;
                int  intMax   = property.IntMax;
                long intValue = setting.GetInt(name);
                intValue = Math.Max(Math.Min(intValue, intMax), intMin);

                numeric.Minimum   = intMin;
                numeric.Maximum   = intMax;
                numeric.Increment = property.IntStep;
                numeric.Value     = intValue;

                numeric.ValueChanged += (sender, args) =>
                {
                    setting.SetInt(name, (int)numeric.Value);
                    view.PropertyChanged(property);
                };
            }
            else if (type == ObsPropertyType.Float)
            {
                double floatMin   = property.FloatMin;
                double floatMax   = property.FloatMax;
                double floatValue = setting.GetDouble(name);
                floatValue = Math.Max(Math.Min(floatValue, floatMax), floatMin);

                numeric.DecimalPlaces = 2;
                numeric.Minimum       = (decimal)floatMin;
                numeric.Maximum       = (decimal)floatMax;
                numeric.Increment     = (decimal)property.FloatStep;
                numeric.Value         = (decimal)floatValue;

                numeric.ValueChanged += (sender, args) =>
                {
                    setting.SetDouble(name, (double)numeric.Value);
                    view.PropertyChanged(property);
                };
            }

            if (property.IntType == ObsNumberType.Slider || property.FloatType == ObsNumberType.Slider)
            {
                numeric.Width  = 75;
                numeric.Height = 23;

                const int multiplier = 1000;
                var       trackbar   = new TrackBar
                {
                    AutoSize    = false,
                    Width       = 300,
                    Height      = 23,
                    TickStyle   = TickStyle.None,
                    Minimum     = (int)(numeric.Minimum * multiplier),
                    Maximum     = (int)(numeric.Maximum * multiplier),
                    SmallChange = (int)(numeric.Increment * multiplier),
                    LargeChange = (int)(numeric.Increment * multiplier),
                    Value       = (int)(numeric.Value * multiplier)
                };
                trackbar.ValueChanged += (sender, args) => numeric.Value = (decimal)trackbar.Value / multiplier;
                numeric.ValueChanged  += (sender, args) => trackbar.Value = (int)(numeric.Value * multiplier);
                controls.Add(trackbar);
            }
            controls.Add(numeric);
        }
示例#8
0
        /// <summary>
        /// Resets and updates the video settings for video output.
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public static bool ResetVideoInfo(ResetVideoInfoParameters parameters)
        {
            if (Store.Data.Obs.Presentation != null)
            {
                if (Store.Data.Obs.Presentation.SelectedScene.GetName().ToLowerInvariant() != "main")
                {
                    Store.Data.Obs.Presentation.SetScene(0);
                }
            }

            Store.Data.Record.AppliedCrop = new obs_sceneitem_crop
            {
                left   = parameters.CropLeft,
                top    = parameters.CropTop,
                right  = parameters.CropRight,
                bottom = parameters.CropBottom
            };

            Store.Data.Record.ActiveScreen = ScreenHelper.GetScreen(parameters.ScreenX, parameters.ScreenY);

            //Set the proper display source
            if (Store.Data.Display.DisplaySource != null)
            {
                ObsData displaySettings = new ObsData();
                displaySettings.SetBool("capture_cursor", true);

                displaySettings.SetInt("monitor", ObsHelper.GetObsDisplayValueFromScreen(Store.Data.Display.DisplaySource, Store.Data.Record.ActiveScreen));

                Store.Data.Display.DisplaySource.Update(displaySettings);
                displaySettings.Dispose();
            }

            //Set the proper display bounds and crop
            if (Store.Data.Display.DisplayItem != null)
            {
                Store.Data.Display.DisplayItem.SetBounds(new Vector2(0, 0), ObsBoundsType.None, ObsAlignment.Top);
                Store.Data.Display.DisplayItem.SetCrop(Store.Data.Record.AppliedCrop);
            }

            WebcamService.CalculateItemPosition();

            var obsVideoInfo = new GenerateObsVideoInfoParameters
            {
                BaseWidth    = (uint)parameters.CanvasWidth,
                OutputWidth  = (uint)parameters.OutputWidth,
                BaseHeight   = (uint)parameters.CanvasHeight,
                OutputHeight = (uint)parameters.OutputHeight,
                FrameRate    = GetFrameRate(parameters.FrameRate)
            };

            obs_video_info ovi = ObsHelper.GenerateObsVideoInfoObject(obsVideoInfo);

            if (!Obs.ResetVideo(ovi))
            {
                return(false);
            }

            Store.Data.Record.CanvasHeight = parameters.CanvasHeight;
            Store.Data.Record.CanvasWidth  = parameters.CanvasWidth;

            return(true);
        }