Esempio n. 1
0
        void CreateVideoStream(int Width, int Height)
        {
            // Select encoder type based on FOURCC of codec
            if (_codec == AviCodec.Uncompressed)
            {
                _videoStream = _writer.AddUncompressedVideoStream(Width, Height);
            }
            else if (_codec == AviCodec.MotionJpeg)
            {
                _videoStream = _writer.AddMotionJpegVideoStream(Width, Height, _codec.Quality);
            }
            else
            {
                _videoStream = _writer.AddMpeg4VideoStream(Width, Height,
                                                           (double)_writer.FramesPerSecond,
                                                           // It seems that all tested MPEG-4 VfW codecs ignore the quality affecting parameters passed through VfW API
                                                           // They only respect the settings from their own configuration dialogs, and Mpeg4VideoEncoder currently has no support for this
                                                           0,
                                                           _codec.Quality,
                                                           // Most of VfW codecs expect single-threaded use, so we wrap this encoder to special wrapper
                                                           // Thus all calls to the encoder (including its instantiation) will be invoked on a single thread although encoding (and writing) is performed asynchronously
                                                           _codec.FourCC,
                                                           true);
            }

            _videoStream.Name = "ScrenaVideo";
        }
Esempio n. 2
0
        private void CreateVideoStream(int width, int height)
        {
            // Select encoder type based on FOURCC of codec
            if (_codec == AviCodec.Uncompressed)
            {
                _videoStream = _writer.AddUncompressedVideoStream(width, height);
            }
            else if (_codec == AviCodec.MotionJpeg)
            {
                // MotionJpegVideoStream implementation allocates multiple WriteableBitmap for every thread
                // Use SingleThreadWrapper to reduce allocation
                var encoderFactory = new Func <IVideoEncoder>(() => new MotionJpegVideoEncoderWpf(width, height, _codec.Quality));
                var encoder        = new SingleThreadedVideoEncoderWrapper(encoderFactory);

                _videoStream = _writer.AddEncodingVideoStream(encoder, true, width, height);
            }
            else
            {
                _videoStream = _writer.AddMpeg4VideoStream(width, height,
                                                           (double)_writer.FramesPerSecond,
                                                           // It seems that all tested MPEG-4 VfW codecs ignore the quality affecting parameters passed through VfW API
                                                           // They only respect the settings from their own configuration dialogs, and Mpeg4VideoEncoder currently has no support for this
                                                           0,
                                                           _codec.Quality,
                                                           // Most of VfW codecs expect single-threaded use, so we wrap this encoder to special wrapper
                                                           // Thus all calls to the encoder (including its instantiation) will be invoked on a single thread although encoding (and writing) is performed asynchronously
                                                           _codec.FourCC,
                                                           true);
            }

            _videoStream.Name = "Video";
        }