private IAviVideoStream CreateVideoStream(FourCC codec, int quality) { // Select encoder type based on FOURCC of codec if (codec == CodecIds.Uncompressed) { return(writer.AddUncompressedVideoStream(screenWidth, screenHeight)); } else if (codec == CodecIds.MotionJpeg) { // Use M-JPEG based on WPF (Windows only) return(writer.AddMJpegWpfVideoStream(screenWidth, screenHeight, quality)); } else if (codec == MJPEG_IMAGE_SHARP) { // Use M-JPEG based on the SixLabors.ImageSharp package (cross-platform) // Included in the SharpAvi.ImageSharp package return(writer.AddMJpegImageSharpVideoStream(screenWidth, screenHeight, quality)); } else { return(writer.AddMpeg4VcmVideoStream(screenWidth, screenHeight, (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 quality: quality, codec: codec, // 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 forceSingleThreadedAccess: true)); } }