public static byte[] ToI420(int width, int height, byte[] sample, VideoPixelFormatsEnum pixelFormat)
        {
            byte[] i420Buffer = null;

            switch (pixelFormat)
            {
            case VideoPixelFormatsEnum.I420:
                // No conversion needed.
                i420Buffer = sample;
                break;

            case VideoPixelFormatsEnum.Bgra:
                i420Buffer = PixelConverter.RGBAtoI420(sample, width, height);
                break;

            case VideoPixelFormatsEnum.Bgr:
                i420Buffer = PixelConverter.BGRtoI420(sample, width, height);
                break;

            case VideoPixelFormatsEnum.Rgb:
                i420Buffer = PixelConverter.RGBtoI420(sample, width, height);
                break;

            default:
                throw new ApplicationException($"Pixel format {pixelFormat} does not have an I420 conversion implemented.");
            }

            return(i420Buffer);
        }
        public static byte[] ToI420(int width, int height, byte[] sample, VideoPixelFormatsEnum pixelFormat)
        {
            switch (pixelFormat)
            {
            case VideoPixelFormatsEnum.I420:
                return(sample);

            case VideoPixelFormatsEnum.Bgra:
                return(PixelConverter.RGBAtoI420(sample, width, height, width * 4));

            case VideoPixelFormatsEnum.Bgr:
                return(PixelConverter.BGRtoI420(sample, width, height, width * 3));

            case VideoPixelFormatsEnum.Rgb:
                return(PixelConverter.RGBtoI420(sample, width, height, width * 3));

            default:
                throw new ApplicationException($"Pixel format {pixelFormat} does not have an I420 conversion implemented.");
            }
        }