Exemplo n.º 1
0
        /// <summary>
        /// Save a stream of image frames as an AVI video file.
        /// </summary>
        /// <param name="frames">Ordered list of frames at 30 fps.</param>
        /// <param name="width">Frame width.</param>
        /// <param name="height">Frame height.</param>
        /// <param name="file">Output filename.</param>
        public static void SaveAsAvi(List <Color[]> frames, int width, int height, string file)
        {
            if (frames.Count == 0)
            {
                return;
            }

            using (VideoWriter writer = new VideoWriter(file, new Size(width, height),
                                                        30, true, VideoCodec.FromName("MJPG"))) {
                writer.Open();

                foreach (Color[] frame in frames)
                {
                    Bgr <byte>[,] bitmap = new Bgr <byte> [height, width];

                    int h = 0;
                    for (int k = 0; k < height; k++)
                    {
                        for (int i = 0; i < width; i++)
                        {
                            bitmap[k, i] = new Bgr <byte>(frame[h].B, frame[h].G, frame[h].R);
                            h++;
                        }
                    }

                    writer.Write(bitmap.Lock());
                }

                writer.Close();
            }
        }