none
What is wrong with my video recording codes? Anyone can help RRS feed

  • Question

  • Hi All,

        I am using the Emgu library to write down a function to record the video stream to a 'AVI' file, but there is no file saved. Can anyone help me out? Here is the code:

       void sensor_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
            {
                using (var image = e.OpenColorImageFrame())
                {
                    if (image == null)
                        return;

                    if (colorBytes == null ||
                        colorBytes.Length != image.PixelDataLength)
                    {
                        colorBytes = new byte[image.PixelDataLength];
                    }

                    image.CopyPixelDataTo(colorBytes);

                    int length = colorBytes.Length;
                    for (int i = 0; i < length; i += 4)
                    {
                        colorBytes[i + 3] = 255;
                    }

                    BitmapSource source = BitmapSource.Create(image.Width,
                        image.Height,
                        96,
                        96,
                        PixelFormats.Bgra32,
                        null,
                        colorBytes,
                        image.Width * image.BytesPerPixel);
                    videoImage.Source = source;
                    //source.Save("foo.jpg", ImageFormat.Jpeg);
     
                    Record(image);
                
                }
            }
            //recording the video
            bool _isRecording = false;
            string _baseDirectory = @"d:\vids\";
            string _fileName;
            List<Image<Emgu.CV.Structure.Rgb, Byte>> _videoArray = new List<Image<Emgu.CV.Structure.Rgb, Byte>>();
            void Record(ColorImageFrame image)
            {
                if (!_isRecording)
                {
                    _fileName = string.Format("{0}{1}{2}", _baseDirectory
                    , DateTime.Now.ToString("MMddyyyyHmmss"), ".avi");
                    _isRecording = true;
                }
                _videoArray.Add(image.ToOpenCVImage<Emgu.CV.Structure.Rgb, Byte>());
            }

    Thank you very much.

    Tuesday, May 8, 2012 2:47 AM

All replies

  • I'll preface this reply by saying I know nothing about the Emgu library.

    That said, I don't see any code in your sample that I'd expect to actually create a file. I see that you're using string.Format to initialize the _fileName string, and you're capturing each frame to the _videoArray list. But you have no code that actually writes the contents of _videoArray to a file using the name _fileName.

    John
    K4W Dev

    Tuesday, May 8, 2012 10:33 PM