Пример #1
0
        public Recorder(string fileName, 
            FourCC codec, int quality, 
            int audioSourceIndex, SupportedWaveFormat audioWaveFormat, bool encodeAudio, int audioBitRate)
        {
            System.Windows.Media.Matrix toDevice;
            using (var source = new HwndSource(new HwndSourceParameters()))
            {
                toDevice = source.CompositionTarget.TransformToDevice;
            }

            screenWidth = (int)Math.Round(SystemParameters.PrimaryScreenWidth * toDevice.M11);
            screenHeight = (int)Math.Round(SystemParameters.PrimaryScreenHeight * toDevice.M22);

            // Create AVI writer and specify FPS
            writer = new AviWriter(fileName)
            {
                FramesPerSecond = 10,
                EmitIndex1 = true,
            };

            // Create video stream
            videoStream = CreateVideoStream(codec, quality);
            // Set only name. Other properties were when creating stream,
            // either explicitly by arguments or implicitly by the encoder used
            videoStream.Name = "Screencast";

            if (audioSourceIndex >= 0)
            {
                var waveFormat = ToWaveFormat(audioWaveFormat);

                audioStream = CreateAudioStream(waveFormat, encodeAudio, audioBitRate);
                // Set only name. Other properties were when creating stream,
                // either explicitly by arguments or implicitly by the encoder used
                audioStream.Name = "Voice";

                audioSource = new WaveInEvent
                {
                    DeviceNumber = audioSourceIndex,
                    WaveFormat = waveFormat,
                    // Buffer size to store duration of 1 frame
                    BufferMilliseconds = (int)Math.Ceiling(1000 / writer.FramesPerSecond),
                    NumberOfBuffers = 3,
                };
                audioSource.DataAvailable += audioSource_DataAvailable;
            }

            screenThread = new Thread(RecordScreen)
            {
                Name = typeof(Recorder).Name + ".RecordScreen",
                IsBackground = true
            };

            if (audioSource != null)
            {
                videoFrameWritten.Set();
                audioBlockWritten.Reset();
                audioSource.StartRecording();
            }
            screenThread.Start();
        }
Пример #2
0
 /// <summary>
 /// Checks to see if a given SupportedWaveFormat is supported
 /// </summary>
 /// <param name="waveFormat">The SupportedWaveFormat</param>
 /// <returns>true if supported</returns>
 public bool SupportsWaveFormat(SupportedWaveFormat waveFormat)
 {
     return (supportedFormats & waveFormat) == waveFormat;
 }
Пример #3
0
 private static WaveFormat ToWaveFormat(SupportedWaveFormat waveFormat)
 {
     switch (waveFormat)
     {
         case SupportedWaveFormat.WAVE_FORMAT_44M16:
             return new WaveFormat(44100, 16, 1);
         case SupportedWaveFormat.WAVE_FORMAT_44S16:
             return new WaveFormat(44100, 16, 2);
         default:
             throw new NotSupportedException("Wave formats other than '16-bit 44.1kHz' are not currently supported.");
     }
 }
Пример #4
0
        private void ShowSettingsDialog()
        {
            var dlg = new SettingsWindow()
            {
                Owner = this,
                Folder = outputFolder,
                Encoder = encoder,
                Quality = encodingQuality,
                SelectedAudioSourceIndex = audioSourceIndex,
                AudioWaveFormat = audioWaveFormat,
                EncodeAudio = encodeAudio,
                AudioQuality = audioQuality,
                MinimizeOnStart = minimizeOnStart
            };

            if (dlg.ShowDialog() == true)
            {
                outputFolder = dlg.Folder;
                encoder = dlg.Encoder;
                encodingQuality = dlg.Quality;
                audioSourceIndex = dlg.SelectedAudioSourceIndex;
                audioWaveFormat = dlg.AudioWaveFormat;
                encodeAudio = dlg.EncodeAudio;
                audioQuality = dlg.AudioQuality;
                minimizeOnStart = dlg.MinimizeOnStart;
            }
        }
Пример #5
0
        private void InitDefaultSettings()
        {
            var exePath = new Uri(System.Reflection.Assembly.GetEntryAssembly().Location).LocalPath;
            outputFolder = System.IO.Path.GetDirectoryName(exePath);

            encoder = KnownFourCCs.Codecs.MotionJpeg;
            encodingQuality = 70;

            audioSourceIndex = -1;
            audioWaveFormat = SupportedWaveFormat.WAVE_FORMAT_44M16;
            encodeAudio = true;
            audioQuality = (Mp3AudioEncoderLame.SupportedBitRates.Length + 1) / 2;

            minimizeOnStart = true;
        }
Пример #6
0
 /// <summary>
 /// Checks to see if a given SupportedWaveFormat is supported
 /// </summary>
 /// <param name="waveFormat">The SupportedWaveFormat</param>
 /// <returns>true if supported</returns>
 public bool SupportsWaveFormat(SupportedWaveFormat waveFormat)
 {
     return((supportedFormats & waveFormat) == waveFormat);
 }
 /// <summary>
 /// Checks to see if a given SupportedWaveFormat is supported
 /// </summary>
 /// <param name="waveFormat">The SupportedWaveFormat</param>
 /// <returns>true if supported</returns>
 internal bool SupportsWaveFormat(SupportedWaveFormat waveFormat) => (supportedFormats & waveFormat) == waveFormat;
Пример #8
0
 public bool SupportsWaveFormat(SupportedWaveFormat WaveFormat) => WaveIn.GetCapabilities(DeviceNumber).SupportsWaveFormat(WaveFormat);