示例#1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            CreateEngine();

            Text += $" (SDK v{VideoCapture1.SDK_Version()})";

            // enumerate devices
            foreach (var device in VideoCapture1.Video_CaptureDevices())
            {
                cbVideoInputDevice.Items.Add(device.Name);
            }

            if (cbVideoInputDevice.Items.Count > 0)
            {
                cbVideoInputDevice.SelectedIndex = 0;
            }

            foreach (var device in VideoCapture1.Audio_CaptureDevices())
            {
                cbAudioInputDevice.Items.Add(device.Name);
            }

            if (cbAudioInputDevice.Items.Count > 0)
            {
                cbAudioInputDevice.SelectedIndex = 0;
            }
        }
示例#2
0
        private async void btStart_Click(object sender, EventArgs e)
        {
            VideoCapture1.Debug_Mode      = cbDebugMode.Checked;
            VideoCapture1.Debug_Dir       = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "VisioForge");
            VideoCapture1.Debug_Telemetry = cbTelemetry.Checked;

            // configure source
            var screenSource = new ScreenCaptureSourceSettings();

            screenSource.Mode = ScreenCaptureMode.Screen;

            screenSource.FullScreen = rbScreenFullScreen.Checked;
            screenSource.Top        = Convert.ToInt32(edScreenTop.Text);
            screenSource.Bottom     = Convert.ToInt32(edScreenBottom.Text);
            screenSource.Left       = Convert.ToInt32(edScreenLeft.Text);
            screenSource.Right      = Convert.ToInt32(edScreenRight.Text);

            screenSource.DisplayIndex    = Convert.ToInt32(cbScreenCaptureDisplayIndex.Text);
            screenSource.FrameRate       = Convert.ToInt32(edScreenFrameRate.Text);
            screenSource.GrabMouseCursor = cbScreenCapture_GrabMouseCursor.Checked;
            screenSource.AllowDesktopDuplicationEngine = cbScreenCapture_DesktopDuplication.Checked;
            VideoCapture1.Screen_Capture_Source        = screenSource;

            // audio capture
            if (cbAudioCapture.Checked)
            {
                VideoCapture1.Audio_PlayAudio   = false;
                VideoCapture1.Audio_RecordAudio = true;

                // select first audio device with default parameters
                if (VideoCapture1.Audio_CaptureDevices().Any())
                {
                    VideoCapture1.Audio_CaptureDevice = new AudioCaptureSource(VideoCapture1.Audio_CaptureDevices()[0].Name);
                }
            }
            else
            {
                VideoCapture1.Audio_PlayAudio   = false;
                VideoCapture1.Audio_RecordAudio = false;
            }

            // configure output
            if (cbCapture.Checked)
            {
                VideoCapture1.Mode            = VideoCaptureMode.ScreenCapture;
                VideoCapture1.Output_Format   = new MP4Output();
                VideoCapture1.Output_Filename = edOutput.Text;
            }
            else
            {
                VideoCapture1.Mode = VideoCaptureMode.ScreenPreview;
            }

            await VideoCapture1.StartAsync();
        }
示例#3
0
        private void cbAudioInputDevice_SelectedIndexChanged(object sender, SelectionChangedEventArgs e)
        {
            if (cbAudioInputDevice.SelectedIndex != -1 && e != null && e.AddedItems.Count > 0)
            {
                cbAudioInputFormat.Items.Clear();

                var deviceItem =
                    VideoCapture1.Audio_CaptureDevices().FirstOrDefault(device => device.Name == e.AddedItems[0].ToString());
                if (deviceItem == null)
                {
                    return;
                }

                var defaultValue       = "PCM, 44100 Hz, 16 Bits, 2 Channels";
                var defaultValueExists = false;
                foreach (string format in deviceItem.Formats)
                {
                    cbAudioInputFormat.Items.Add(format);

                    if (defaultValue == format)
                    {
                        defaultValueExists = true;
                    }
                }

                if (cbAudioInputFormat.Items.Count > 0)
                {
                    cbAudioInputFormat.SelectedIndex = 0;

                    if (defaultValueExists)
                    {
                        cbAudioInputFormat.Text = defaultValue;
                    }
                }

                cbAudioInputLine.Items.Clear();

                foreach (var line in deviceItem.Lines)
                {
                    cbAudioInputLine.Items.Add(line);
                }

                if (cbAudioInputLine.Items.Count > 0)
                {
                    cbAudioInputLine.SelectedIndex = 0;
                }

                btAudioInputDeviceSettings.IsEnabled = deviceItem.DialogDefault;
            }
        }
示例#4
0
        private void Form1_Load(object sender, EventArgs e)
        {
            CreateEngineCapture();
            CreateEnginePlayer();

            Text += $" (SDK v{VideoCapture1.SDK_Version()})";

            cbIPCameraType.SelectedIndex = 2;

            edOutput.Text = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "VisioForge", "output.avi");

            foreach (var device in VideoCapture1.Video_CaptureDevices())
            {
                cbVideoInputDevice.Items.Add(device.Name);
            }

            if (cbVideoInputDevice.Items.Count > 0)
            {
                cbVideoInputDevice.SelectedIndex = 0;
                cbVideoInputDevice_SelectedIndexChanged(null, null);
            }

            foreach (var device in VideoCapture1.Audio_CaptureDevices())
            {
                cbAudioInputDevice.Items.Add(device.Name);
            }

            if (cbAudioInputDevice.Items.Count > 0)
            {
                cbAudioInputDevice.SelectedIndex = 0;
                cbAudioInputDevice_SelectedIndexChanged(null, null);
            }

            cbOutputFormat.SelectedIndex = 0;

            if (FilterHelpers.Filter_Supported_EVR())
            {
                VideoCapture1.Video_Renderer.VideoRenderer = VideoRendererMode.EVR;
            }
            else if (FilterHelpers.Filter_Supported_VMR9())
            {
                VideoCapture1.Video_Renderer.VideoRenderer = VideoRendererMode.VMR9;
            }
            else
            {
                VideoCapture1.Video_Renderer.VideoRenderer = VideoRendererMode.VideoRenderer;
            }
        }
示例#5
0
        private async void btStart_Click(object sender, EventArgs e)
        {
            videoCapture1.Video_CaptureDevice = new VideoCaptureSource(videoCapture1.Video_CaptureDevices()[0].Name);
            videoCapture1.Audio_CaptureDevice = new AudioCaptureSource(videoCapture1.Audio_CaptureDevices()[0].Name);
            videoCapture1.Mode = VideoCaptureMode.VideoPreview;

            await videoCapture1.StartAsync();
        }
示例#6
0
        private async void btStart_Click(object sender, EventArgs e)
        {
            // default video and audio sources will be used
            videoCapture1.Video_CaptureDevice = new VideoCaptureSource(videoCapture1.Video_CaptureDevices()[0].Name);
            videoCapture1.Audio_CaptureDevice = new AudioCaptureSource(videoCapture1.Audio_CaptureDevices()[0].Name);
            videoCapture1.Output_Filename     = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyVideos), "output.mp4");
            videoCapture1.Output_Format       = new MP4Output(); // MP4 output with default settings
            videoCapture1.Mode = VideoCaptureMode.VideoCapture;

            await videoCapture1.StartAsync();
        }
示例#7
0
        private async void btStart_Click(object sender, EventArgs e)
        {
            videoCapture1.Video_CaptureDevice = new VideoCaptureSource(videoCapture1.Video_CaptureDevices()[0].Name);
            videoCapture1.Audio_CaptureDevice = new AudioCaptureSource(videoCapture1.Audio_CaptureDevices()[0].Name);
            videoCapture1.Mode            = VideoCaptureMode.VideoCapture;
            videoCapture1.Output_Filename = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyVideos), "output.mp4");
            videoCapture1.Output_Format   = new MP4Output();

            // add text overlay
            videoCapture1.Video_Effects_Enabled = true;
            videoCapture1.Video_Effects_Clear();
            var textOverlay = new VideoEffectTextLogo(true)
            {
                Text = "Hello World!", Top = 50, Left = 50, FontColor = Color.Red
            };

            videoCapture1.Video_Effects_Add(textOverlay);

            await videoCapture1.StartAsync();
        }
示例#8
0
        private async void btStartWithAudio_Click(object sender, EventArgs e)
        {
            // set screen capture with full screen enabled
            videoCapture1.Screen_Capture_Source = new ScreenCaptureSourceSettings()
            {
                FullScreen = true
            };

            // select first audio device with default parameters
            videoCapture1.Audio_CaptureDevice = new AudioCaptureSource(videoCapture1.Audio_CaptureDevices()[0].Name);

            // disable audio playback
            videoCapture1.Audio_PlayAudio = false;

            // enable audio recording
            videoCapture1.Audio_RecordAudio = true;

            // set output filename, output format and screen capture mode
            videoCapture1.Output_Filename = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyVideos), "output.mp4");
            videoCapture1.Output_Format   = new MP4Output();
            videoCapture1.Mode            = VideoCaptureMode.ScreenCapture;

            await videoCapture1.StartAsync();
        }
示例#9
0
        private void Form1_Load(object sender, EventArgs e)
        {
            Text += $" (SDK v{VideoCapture1.SDK_Version()})";
            cbMode.SelectedIndex = 0;

            tmRecording.Elapsed += (senderx, args) =>
            {
                UpdateRecordingTime();
            };

            foreach (var device in VideoCapture1.Audio_CaptureDevices())
            {
                cbAudioInputDevice.Items.Add(device.Name);
            }

            if (cbAudioInputDevice.Items.Count > 0)
            {
                cbAudioInputDevice.SelectedIndex = 0;
                cbAudioInputDevice_SelectedIndexChanged(null, null);
            }

            cbAudioInputLine.Items.Clear();

            if (!string.IsNullOrEmpty(cbAudioInputDevice.Text))
            {
                var deviceItem = VideoCapture1.Audio_CaptureDevices().FirstOrDefault(device => device.Name == cbAudioInputDevice.Text);
                if (deviceItem != null)
                {
                    foreach (string line in deviceItem.Lines)
                    {
                        cbAudioInputLine.Items.Add(line);
                    }
                }
            }

            if (cbAudioInputLine.Items.Count > 0)
            {
                cbAudioInputLine.SelectedIndex = 0;
            }

            string defaultAudioRenderer = string.Empty;

            foreach (string audioOutputDevice in VideoCapture1.Audio_OutputDevices())
            {
                cbAudioOutputDevice.Items.Add(audioOutputDevice);

                if (audioOutputDevice.Contains("Default DirectSound Device"))
                {
                    defaultAudioRenderer = audioOutputDevice;
                }
            }

            if (cbAudioOutputDevice.Items.Count > 0)
            {
                if (string.IsNullOrEmpty(defaultAudioRenderer))
                {
                    cbAudioOutputDevice.SelectedIndex = 0;
                }
                else
                {
                    cbAudioOutputDevice.Text = defaultAudioRenderer;
                }

                cbAudioOutputDevice_SelectedIndexChanged(null, null);
            }

            foreach (string preset in VideoCapture1.Audio_Effects_Equalizer_Presets())
            {
                cbAudEqualizerPreset.Items.Add(preset);
            }

            cbOutputFormat.SelectedIndex       = 1;
            cbAudEqualizerPreset.SelectedIndex = 0;
            cbAudEqualizerPreset_SelectedIndexChanged(null, null);

            edOutput.Text = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "VisioForge", "output.mp3");
        }
        private void MainWindow_Activated(object sender, EventArgs e)
        {
            if (_initialized)
            {
                return;
            }

            Closing += Window_Closing;

            _initialized = true;

            CreateEngine();

            Title += $" (SDK v{VideoCapture1.SDK_Version()})";
            VideoCapture1.Debug_Dir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "VisioForge");

            tmRecording.Elapsed += (senderx, args) => { UpdateRecordingTime(); };

            cbOutputFormat.SelectedIndex = 2;

            foreach (var device in VideoCapture1.Video_CaptureDevices())
            {
                VideoInputDevices.Add(device.Name);
            }

            if (VideoInputDevices.Count > 0)
            {
                cbVideoInputDevice.SelectedIndex = 0;
            }

            cbVideoInputDevice_SelectionChanged(null, null);

            foreach (var device in VideoCapture1.Audio_CaptureDevices())
            {
                AudioInputDevices.Add(device.Name);
            }

            if (AudioInputDevices.Count > 0)
            {
                cbAudioInputDevice.SelectedIndex = 0;
                cbAudioInputDevice_SelectionChanged(null, null);
            }

            AudioInputLines.Clear();

            if (!string.IsNullOrEmpty(cbAudioInputDevice.SelectedItem.ToString()))
            {
                var deviceItem =
                    VideoCapture1.Audio_CaptureDevices().FirstOrDefault(device => device.Name == cbAudioInputDevice.SelectedItem.ToString());
                if (deviceItem != null)
                {
                    foreach (var line in deviceItem.Lines)
                    {
                        AudioInputLines.Add(line);
                    }

                    if (AudioInputLines.Count > 0)
                    {
                        cbAudioInputLine.SelectedIndex = 0;
                    }
                }
            }

            string defaultAudioRenderer = string.Empty;

            foreach (string audioOutputDevice in VideoCapture1.Audio_OutputDevices())
            {
                AudioOutputDevices.Add(audioOutputDevice);

                if (audioOutputDevice.Contains("Default DirectSound Device"))
                {
                    defaultAudioRenderer = audioOutputDevice;
                }
            }

            if (AudioOutputDevices.Count > 0)
            {
                if (string.IsNullOrEmpty(defaultAudioRenderer))
                {
                    cbAudioOutputDevice.SelectedIndex = 0;
                }
                else
                {
                    cbAudioOutputDevice.SelectedItem = defaultAudioRenderer;
                }
            }

            edOutput.Text = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "VisioForge", "output.mp4");
        }
示例#11
0
        static void Main(string[] args)
        {
            var videoCapture = new VideoCaptureCore();

            videoCapture.OnTVTunerTuneChannels += videoCapture_OnTVTunerTuneChannels;
            videoCapture.OnError += VideoCapture_OnError;
            videoCapture.Video_Renderer.VideoRenderer = VideoRendererMode.None;

            // get video capture devices
            var videoCaptureDevices = videoCapture.Video_CaptureDevices();

            Console.WriteLine(@"Video capture devices: ");
            for (int i = 0; i < videoCaptureDevices.Count; i++)
            {
                Console.WriteLine(i + @": " + videoCaptureDevices[i].Name);
            }

            Console.Write(@"Select video capture device index: ");
            int videoCaptureDeviceIndex = Convert.ToInt32(Console.ReadLine());

            // get audio capture devices
            var audioCaptureDevices = videoCapture.Audio_CaptureDevices();

            Console.WriteLine(@"Audio capture devices: ");
            Console.WriteLine(@"0: Use video capture device if possible.");
            for (int i = 0; i < audioCaptureDevices.Count; i++)
            {
                Console.WriteLine((i + 1).ToString() + @": " + audioCaptureDevices[i].Name);
            }

            Console.Write(@"Select audio capture device index: ");
            int audioCaptureDeviceIndex = Convert.ToInt32(Console.ReadLine());

            // get tv tuner info
            videoCapture.TVTuner_ReadAsync();

            var tuners         = new List <string>();
            var tunerFormats   = new List <string>();
            var tunerCountries = new List <string>();

            foreach (string tunerDevice in videoCapture.TVTuner_Devices())
            {
                tuners.Add(tunerDevice);
            }

            foreach (string tunerTVFormat in videoCapture.TVTuner_TVFormats())
            {
                tunerFormats.Add(tunerTVFormat);
            }

            foreach (string tunerCountry in videoCapture.TVTuner_Countries())
            {
                tunerCountries.Add(tunerCountry);
            }

            Console.WriteLine(@"TV tuners: ");
            for (int i = 0; i < tuners.Count; i++)
            {
                Console.WriteLine(i + @": " + tuners[i]);
            }

            Console.Write(@"Select TV tuner index: ");
            int tunerIndex = Convert.ToInt32(Console.ReadLine());

            Console.Write(@"Select country (empty to use default): ");
            string country = Console.ReadLine();

            // mode
            Console.Write(@"Select mode. 0 - Enumerate channels, 1 - Capture to AVI, 2 - Capture to MP4: ");
            int mode = Convert.ToInt32(Console.ReadLine());

            switch (mode)
            {
            case 0:
            {
                videoCapture.Mode = VideoCaptureMode.VideoPreview;
            }
            break;

            case 1:
            {
                videoCapture.Mode = VideoCaptureMode.VideoCapture;

                string outputFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "VisioForge", "output.avi");
                videoCapture.Output_Filename = outputFile;
                Console.WriteLine(@"Output file: " + outputFile);

                videoCapture.Output_Format = new AVIOutput();
            }

            break;

            case 2:
            {
                videoCapture.Mode = VideoCaptureMode.VideoCapture;

                string outputFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "VisioForge", "output.mp4");
                videoCapture.Output_Filename = outputFile;
                Console.WriteLine(@"Output file: " + outputFile);

                videoCapture.Output_Format = new MP4HWOutput();
            }

            break;

            default:
                Console.WriteLine(@"Wrong mode. Press ESC to exit.");
                Console.ReadKey();
                return;
            }

            // set properties
            videoCapture.Video_CaptureDevice = new VideoCaptureSource(videoCaptureDevices[videoCaptureDeviceIndex].Name);
            videoCapture.Video_CaptureDevice.Format_UseBest = true;
            videoCapture.Video_CaptureDevice.FrameRate      = 0; // auto

            if (audioCaptureDeviceIndex == 0)
            {
                videoCapture.Video_CaptureDevice.IsAudioSource = true;
            }
            else
            {
                videoCapture.Video_CaptureDevice.IsAudioSource = false;
                videoCapture.Audio_CaptureDevice = new AudioCaptureSource(audioCaptureDevices[audioCaptureDeviceIndex - 1].Name);
                videoCapture.Audio_CaptureDevice.Format_UseBest = true;
            }

            videoCapture.TVTuner_Country = country;
            videoCapture.TVTuner_Name    = tuners[tunerIndex];
            videoCapture.TVTuner_Mode    = TVTunerMode.FMRadio;

            // videoCapture.TVTuner_Apply();

            videoCapture.TVTuner_Read();

            const int KHz = 1000;
            const int MHz = 1000000;

            videoCapture.TVTuner_Read();

            videoCapture.TVTuner_FM_Tuning_StartFrequency = 100 * MHz;
            videoCapture.TVTuner_FM_Tuning_StopFrequency  = 110 * MHz;
            videoCapture.TVTuner_FM_Tuning_Step           = 100 * KHz;

            videoCapture.Start();

            if (mode == 0)
            {
                videoCapture.TVTuner_TuneChannels_Start();
            }

            Console.WriteLine(@"Press ESC to stop");
            do
            {
                while (!Console.KeyAvailable)
                {
                    Thread.Sleep(100);
                }
            }while (Console.ReadKey(true).Key != ConsoleKey.Escape);

            videoCapture.Stop();

            videoCapture.Dispose();
        }
示例#12
0
        private void Form1_Load(object sender, RoutedEventArgs e)
        {
            Title += " (SDK v" + VideoCaptureCore.SDK_Version + ", " + VideoCaptureCore.SDK_State + ")";
            cbMode.SelectedIndex = 0;

            foreach (var device in VideoCapture1.Audio_CaptureDevices())
            {
                cbAudioInputDevice.Items.Add(device.Name);
            }

            if (cbAudioInputDevice.Items.Count > 0)
            {
                cbAudioInputDevice.SelectedIndex = 0;
                cbAudioInputDevice_SelectedIndexChanged(null, null);
            }

            cbAudioInputLine.Items.Clear();

            if (!string.IsNullOrEmpty(cbAudioInputDevice.Text))
            {
                var deviceItem =
                    VideoCapture1.Audio_CaptureDevices().First(device => device.Name == cbAudioInputDevice.Text);
                if (deviceItem != null)
                {
                    foreach (var line in deviceItem.Lines)
                    {
                        cbAudioInputLine.Items.Add(line);
                    }

                    if (cbAudioInputLine.Items.Count > 0)
                    {
                        cbAudioInputLine.SelectedIndex = 0;
                        cbAudioInputLine_SelectedIndexChanged(null, null);
                        cbAudioInputFormat_SelectedIndexChanged(null, null);
                    }
                }
            }

            string defaultAudioRenderer = string.Empty;

            foreach (string audioOutputDevice in VideoCapture1.Audio_OutputDevices())
            {
                cbAudioOutputDevice.Items.Add(audioOutputDevice);

                if (audioOutputDevice.Contains("Default DirectSound Device"))
                {
                    defaultAudioRenderer = audioOutputDevice;
                }
            }

            if (cbAudioOutputDevice.Items.Count > 0)
            {
                if (string.IsNullOrEmpty(defaultAudioRenderer))
                {
                    cbAudioOutputDevice.SelectedIndex = 0;
                }
                else
                {
                    cbAudioOutputDevice.Text = defaultAudioRenderer;
                }

                cbAudioOutputDevice_SelectedIndexChanged(null, null);
            }

            foreach (var preset in VideoCapture1.Audio_Effects_Equalizer_Presets())
            {
                cbAudEqualizerPreset.Items.Add(preset);
            }

            cbAudEqualizerPreset.SelectedIndex = 0;
            cbAudEqualizerPreset_SelectedIndexChanged(null, null);

            edOutput.Text = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\VisioForge\\" + "output.mp3";
        }
示例#13
0
        static void Main(string[] args)
        {
            var videoCapture = new VideoCaptureCore();

            videoCapture.OnError += VideoCapture_OnError;

            videoCapture.Video_Renderer.VideoRenderer = VideoRendererMode.None;

            // get video capture devices
            var videoCaptureDevices = videoCapture.Video_CaptureDevices();

            Console.WriteLine(@"Video capture devices: ");
            for (int i = 0; i < videoCaptureDevices.Count; i++)
            {
                Console.WriteLine(i + @": " + videoCaptureDevices[i].Name);
            }

            Console.Write(@"Select video capture device index: ");
            int videoCaptureDeviceIndex = Convert.ToInt32(Console.ReadLine());

            // video formats
            VideoCaptureDeviceFormat videoFormat = new VideoCaptureDeviceFormat(string.Empty);

            if (videoCaptureDevices[videoCaptureDeviceIndex].VideoFormats.Count > 0)
            {
                Console.WriteLine(@"Video capture device formats: ");
                for (int i = 0; i < videoCaptureDevices[videoCaptureDeviceIndex].VideoFormats.Count; i++)
                {
                    Console.WriteLine(i + @": " + videoCaptureDevices[videoCaptureDeviceIndex].VideoFormats[i]);
                }

                Console.Write(@"Select video format index: ");
                int videoFormatIndex = Convert.ToInt32(Console.ReadLine());
                videoFormat = videoCaptureDevices[videoCaptureDeviceIndex].VideoFormats[videoFormatIndex];
            }

            // video frame rates
            double videoFrameRate = 0;

            if (videoFormat.FrameRates.Count > 0)
            {
                Console.WriteLine(@"Video capture device frame rates: ");
                for (int i = 0; i < videoFormat.FrameRates.Count; i++)
                {
                    Console.WriteLine(i + @": " + videoFormat.FrameRates[i]);
                }

                Console.Write(@"Select video frame rate index: ");
                int videoFrameRateIndex = Convert.ToInt32(Console.ReadLine());
                videoFrameRate = videoFormat.FrameRates[videoFrameRateIndex];
            }

            // get audio capture devices
            var audioCaptureDevices = videoCapture.Audio_CaptureDevices();

            Console.WriteLine(@"Audio capture devices: ");
            Console.WriteLine(@"0: Use video capture device if possible.");
            for (int i = 0; i < audioCaptureDevices.Count; i++)
            {
                Console.WriteLine((i + 1).ToString() + @": " + audioCaptureDevices[i].Name);
            }

            Console.Write(@"Select audio capture device index: ");
            int audioCaptureDeviceIndex = Convert.ToInt32(Console.ReadLine());

            // audio formats
            string audioFormat = string.Empty;

            if (audioCaptureDeviceIndex == 0)
            {
                if (videoCaptureDevices[videoCaptureDeviceIndex].AudioFormats.Count > 0)
                {
                    Console.WriteLine(@"Audio capture device formats: ");
                    for (int i = 0; i < videoCaptureDevices[videoCaptureDeviceIndex].AudioFormats.Count; i++)
                    {
                        Console.WriteLine(i + @": " + videoCaptureDevices[videoCaptureDeviceIndex].AudioFormats[i]);
                    }

                    Console.Write(@"Select audio format index: ");
                    int audioFormatIndex = Convert.ToInt32(Console.ReadLine());
                    audioFormat = videoCaptureDevices[videoCaptureDeviceIndex].AudioFormats[audioFormatIndex];
                }
            }
            else
            {
                if (audioCaptureDevices[audioCaptureDeviceIndex - 1].Formats.Count > 0)
                {
                    Console.WriteLine(@"Audio capture device formats: ");
                    for (int i = 0; i < audioCaptureDevices[audioCaptureDeviceIndex - 1].Formats.Count; i++)
                    {
                        Console.WriteLine(i + @": " + audioCaptureDevices[audioCaptureDeviceIndex - 1].Formats[i]);
                    }

                    Console.Write(@"Select audio format index: ");
                    int audioFormatIndex = Convert.ToInt32(Console.ReadLine());
                    audioFormat = audioCaptureDevices[audioCaptureDeviceIndex - 1].Formats[audioFormatIndex];
                }
            }

            // mode
            Console.Write(@"Select mode. 0 - Capture to AVI, 1 - Capture to MP4: ");
            int mode = Convert.ToInt32(Console.ReadLine());

            // set properties
            videoCapture.Video_CaptureDevice = new VideoCaptureSource(videoCaptureDevices[videoCaptureDeviceIndex].Name);

            if (string.IsNullOrEmpty(videoFormat.Name))
            {
                videoCapture.Video_CaptureDevice.Format_UseBest = true;
            }
            else
            {
                videoCapture.Video_CaptureDevice.Format_UseBest = false;
                videoCapture.Video_CaptureDevice.Format         = videoFormat.Name;
            }

            videoCapture.Video_CaptureDevice.FrameRate = Convert.ToDouble(videoFrameRate, CultureInfo.InvariantCulture);

            if (audioCaptureDeviceIndex == 0)
            {
                videoCapture.Video_CaptureDevice.IsAudioSource = true;
            }
            else
            {
                videoCapture.Video_CaptureDevice.IsAudioSource = false;
                videoCapture.Audio_CaptureDevice = new AudioCaptureSource(audioCaptureDevices[audioCaptureDeviceIndex - 1].Name);
                videoCapture.Audio_CaptureDevice.Format_UseBest = false;
                videoCapture.Audio_CaptureDevice.Format         = audioFormat;
            }



            switch (mode)
            {
            case 0:
            {
                string outputFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "VisioForge", "output.avi");
                videoCapture.Output_Filename = outputFile;
                Console.WriteLine(@"Output file: " + outputFile);

                videoCapture.Output_Format = new AVIOutput();
            }

            break;

            case 1:
            {
                string outputFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "VisioForge", "output.mp4");
                videoCapture.Output_Filename = outputFile;
                Console.WriteLine(@"Output file: " + outputFile);

                videoCapture.Output_Format = new MP4HWOutput();
            }

            break;

            default:
                Console.WriteLine(@"Wrong mode. Press ESC to exit.");
                Console.ReadKey();
                return;
            }

            videoCapture.Mode = VideoCaptureMode.VideoCapture;
            videoCapture.Start();

            Console.WriteLine(@"Press ESC to stop");
            do
            {
                while (!Console.KeyAvailable)
                {
                    Thread.Sleep(100);
                }
            }while (Console.ReadKey(true).Key != ConsoleKey.Escape);

            videoCapture.Stop();

            videoCapture.Dispose();
        }
示例#14
0
        private void Form1_Load(object sender, EventArgs e)
        {
            CreateEngine();

            Text += $" (SDK v{VideoCapture1.SDK_Version()})";

            tmRecording.Elapsed += (senderx, args) =>
            {
                UpdateRecordingTime();
            };

            cbOutputFormat.SelectedIndex = 2;

            foreach (var device in VideoCapture1.Video_CaptureDevices())
            {
                cbVideoInputDevice.Items.Add(device.Name);
            }

            if (cbVideoInputDevice.Items.Count > 0)
            {
                cbVideoInputDevice.SelectedIndex = 0;
            }

            cbVideoInputDevice_SelectedIndexChanged(null, null);

            foreach (var device in VideoCapture1.Audio_CaptureDevices())
            {
                cbAudioInputDevice.Items.Add(device.Name);
            }

            if (cbAudioInputDevice.Items.Count > 0)
            {
                cbAudioInputDevice.SelectedIndex = 0;
                cbAudioInputDevice_SelectedIndexChanged(null, null);
            }

            cbAudioInputLine.Items.Clear();

            if (!string.IsNullOrEmpty(cbAudioInputDevice.Text))
            {
                var deviceItem =
                    VideoCapture1.Audio_CaptureDevices().FirstOrDefault(device => device.Name == cbAudioInputDevice.Text);
                if (deviceItem != null)
                {
                    foreach (string line in deviceItem.Lines)
                    {
                        cbAudioInputLine.Items.Add(line);
                    }

                    if (cbAudioInputLine.Items.Count > 0)
                    {
                        cbAudioInputLine.SelectedIndex = 0;
                    }
                }
            }

            string defaultAudioRenderer = string.Empty;

            foreach (string audioOutputDevice in VideoCapture1.Audio_OutputDevices())
            {
                cbAudioOutputDevice.Items.Add(audioOutputDevice);

                if (audioOutputDevice.Contains("Default DirectSound Device"))
                {
                    defaultAudioRenderer = audioOutputDevice;
                }
            }

            if (cbAudioOutputDevice.Items.Count > 0)
            {
                if (string.IsNullOrEmpty(defaultAudioRenderer))
                {
                    cbAudioOutputDevice.SelectedIndex = 0;
                }
                else
                {
                    cbAudioOutputDevice.Text = defaultAudioRenderer;
                }
            }

            edOutput.Text      = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "VisioForge", "output.mp4");
            edNewFilename.Text = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "VisioForge", "output_new.mp4");

            if (FilterHelpers.Filter_Supported_EVR())
            {
                VideoCapture1.Video_Renderer.VideoRenderer = VideoRendererMode.EVR;
            }
            else if (FilterHelpers.Filter_Supported_VMR9())
            {
                VideoCapture1.Video_Renderer.VideoRenderer = VideoRendererMode.VMR9;
            }
            else
            {
                VideoCapture1.Video_Renderer.VideoRenderer = VideoRendererMode.VideoRenderer;
            }
        }