示例#1
0
        /// <summary>
        /// Creates a new file output.
        /// </summary>
        /// <returns></returns>
        public static ObsOutput CreateOutput()
        {
            string videoDirectory = $"{FolderService.GetPath(KnownFolder.Videos)}\\{Store.Data.Record.VideoOutputFolder}";

            if (Store.Data.Record.RecordedFiles.Count == 0)
            {
                Store.Data.Record.LastVideoName = $"ScreenRecording {DateTime.Now:yyyy-MM-dd HH.mm.ss}";
            }

            string videoFileName = Store.Data.Record.LastVideoName + "_part " + (Store.Data.Record.RecordedFiles.Count + 1) + ".mp4";

            string videoFilePath = $"{videoDirectory}\\{videoFileName}";

            Store.Data.Record.RecordedFiles.Add(new FileInfo(videoFilePath));

            Directory.CreateDirectory(videoDirectory);
            videoFilePath = videoFilePath.Replace("\\", "/"); // OBS uses forward slashes

            ObsOutput obsOutput = new ObsOutput(ObsOutputType.Dummy, "ffmpeg_muxer", "simple_file_output");

            ObsData outputSettings = new ObsData();

            outputSettings.SetString("path", videoFilePath);
            outputSettings.SetString("muxer_settings", "movflags=faststart");
            obsOutput.Update(outputSettings);
            outputSettings.Dispose();

            return(obsOutput);
        }
        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);
        }
        private void AddText(ObsProperty property, ObsData setting, List <Control> controls)
        {
            string name = property.Name;

            TextBox textbox = new TextBox
            {
                Width = 300,
                Text  = setting.GetString(name)
            };

            if (property.TextType == ObsTextType.Password)
            {
                textbox.PasswordChar = '*';
            }
            else if (property.TextType == ObsTextType.Multiline)
            {
                textbox.Multiline = true;
                textbox.Height   *= 3;
            }

            textbox.TextChanged += (sender, args) =>
            {
                setting.SetString(name, textbox.Text);
                view.PropertyChanged(property);
            };

            controls.Add(textbox);
        }
示例#4
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);
        }
示例#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 AddPath(ObsProperty property, ObsData setting, List <Control> controls)
        {
            string name = property.Name;

            TextBox textbox = new TextBox
            {
                Width = 300,
                Text  = setting.GetString(name)
            };
            Button button = new Button {
                Text = "Browse..."
            };

            if (property.PathType == ObsPathType.File)
            {
                OpenFileDialog dialog = new OpenFileDialog
                {
                    AutoUpgradeEnabled = true,
                    Filter             = property.PathFilter.ToString(),
                    InitialDirectory   = property.PathDefault,
                    FilterIndex        = 1
                };

                button.Click += (sender, args) =>
                {
                    if (dialog.ShowDialog(this) == DialogResult.OK)
                    {
                        textbox.Text = dialog.FileName;
                    }
                };
            }
            else if (property.PathType == ObsPathType.Directory)
            {
                FolderBrowserDialog dialog = new FolderBrowserDialog
                {
                    SelectedPath = property.PathDefault
                };

                button.Click += (sender, args) =>
                {
                    if (dialog.ShowDialog(this) == DialogResult.OK)
                    {
                        textbox.Text = dialog.SelectedPath;
                    }
                };
            }

            textbox.TextChanged += (sender, args) =>
            {
                setting.SetString(name, textbox.Text);
                view.PropertyChanged(property);
            };

            controls.Add(textbox);
            controls.Add(button);
        }
示例#7
0
        /// <summary>
        /// Creates the click highlight settings.
        /// </summary>
        /// <returns></returns>
        private ObsData CreateClickHighlightSettings()
        {
            ObsData settings = new ObsData();

            settings.SetBool(MediaSource.IS_LOCAL_FILE, true);
            settings.SetBool(MediaSource.LOOPING, true);
            settings.SetBool(MediaSource.RESTART_ON_ACTIVATE, true);
            settings.SetBool(MediaSource.HW_DECODE, true);
            settings.SetString(MediaSource.LOCAL_FILE_PATH, _highlightImagePath);
            settings.SetBool(Common.ACTIVATE, true);
            return(settings);
        }
        /// <summary>
        /// Updates the current audio output device.
        /// </summary>
        /// <param name="deviceId"></param>
        public static void UpdateAudioOutput(string deviceId)
        {
            Store.Data.Audio.CurrentOutputId = deviceId;

            ObsData aoSettings = new ObsData();

            aoSettings.SetString(Constants.Audio.SettingKeys.DeviceId, deviceId.Equals(Constants.Audio.NO_DEVICE_ID) ? Constants.Audio.DEFAULT_DEVICE_ID : deviceId);
            Store.Data.Audio.OutputSource.Update(aoSettings);
            aoSettings.Dispose();

            Store.Data.Audio.OutputSource.Enabled = !deviceId.Equals(Constants.Audio.NO_DEVICE_ID);
            Store.Data.Audio.OutputSource.Muted   = deviceId.Equals(Constants.Audio.NO_DEVICE_ID); // Muted is used to update audio meter
        }
示例#9
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);
        }
示例#10
0
        private void EditableListChanged(ListBox listBox, ObsProperty property, ObsData setting)
        {
            string       propertyName = property.Name;
            ObsDataArray array        = new ObsDataArray();

            foreach (string item in listBox.Items)
            {
                ObsData itemArray = new ObsData();
                itemArray.SetString("value", item);

                array.Add(itemArray);
                itemArray.Dispose();
            }

            setting.SetArray(propertyName, array);
            array.Dispose();
        }
示例#11
0
        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);
        }
示例#12
0
        /// <summary>
        /// Finds DirectShow audio device from current wsapi audio device to attach to the webcam.
        /// </summary>
        public static void UpdateAudioDevice()
        {
            // DISABLING CUSTOM AUDIO DEVICE - if re-enabling, search for this comment
            if (Store.Data.Audio.InputSource != null)
            {
                Store.Data.Audio.InputSource.AudioOffset = Constants.Audio.DELAY_INPUT_NOT_ATTACHED_TO_WEBCAM;
            }

            return;

            if (Store.Data.Webcam.Source == null)
            {
                return;
            }

            // Disable the main microphone, we need to attach it to the webcamsource_webcam
            Store.Data.Audio.InputSource.Enabled = false;

            var foundWebcamAudio = false;

            if (Store.Data.Audio.CurrentInputId == Constants.Audio.NO_DEVICE_ID)
            {
                ObsData wcSettings = new ObsData();
                wcSettings.SetBool("use_custom_audio_device", false);
                Store.Data.Webcam.Source.Update(wcSettings);
                foundWebcamAudio = true;
                return;
            }

            Store.Data.Webcam.Source.GetProperties();

            string      devenumDir            = FX35Helper.Is64BitProcess() ? "devenum 64-bit" : "devenum";
            RegistryKey inputDevicesDirectory = Registry.CurrentUser.OpenSubKey("SOFTWARE")?.OpenSubKey("Microsoft")?.OpenSubKey("ActiveMovie")?.OpenSubKey(devenumDir)?.OpenSubKey("{33D9A762-90C8-11D0-BD43-00A0C911CE86}");

            if (inputDevicesDirectory == null)
            {
                foundWebcamAudio = false;
                return;
            }

            string[] subKeyNames        = inputDevicesDirectory.GetSubKeyNames();
            string   directShowDeviceId = null;

            foreach (string name in subKeyNames)
            {
                RegistryKey subkey     = inputDevicesDirectory.OpenSubKey(name);
                string      endpointId = subkey.GetValue("EndpointId")?.ToString();
                object      waveInId   = subkey.GetValue("WaveInId");

                if (Store.Data.Audio.CurrentInputId == Constants.Audio.DEFAULT_DEVICE_ID)
                {
                    if (waveInId == null || (int)waveInId != 0)
                    {
                        continue;
                    }
                }
                else if (endpointId == null || endpointId != Store.Data.Audio.CurrentInputId)
                {
                    continue;
                }

                string friendlyName = subkey.GetValue("FriendlyName")?.ToString();
                if (friendlyName != null)
                {
                    // Direct show adds a colon to the friendly name for the id
                    directShowDeviceId = $"{friendlyName}:";
                    break;
                }
            }

            if (directShowDeviceId == null)
            {
                foundWebcamAudio = false;
                return;
            }

            ObsData wSettings = new ObsData();

            wSettings.SetBool("use_custom_audio_device", true);
            wSettings.SetString("audio_device_id", directShowDeviceId);
            Store.Data.Webcam.Source.Update(wSettings);
            foundWebcamAudio = true;
        }