Question

I am using the Simple C# Wrapper for the AviFile Library, and the code snippet I found here in order create an avi file from Kinect's color frames.

And I get this exception: "Exception in AVIFileOpen: -2147205009"

        aviManager = new AviManager(@"C:\temp\temp.avi", false);
        aviStream = aviManager.AddVideoStream(false, 30, _firstBitmap);

Where the "_firstBitmap" is generated with the function mentioned above

Bitmap ImageToBitmap(ColorImageFrame Image)
{
     byte[] pixeldata = new byte[Image.PixelDataLength];
     Image.CopyPixelDataTo(pixeldata);
     Bitmap bmap = new Bitmap(Image.Width, Image.Height, PixelFormat.Format32bppRgb);
     BitmapData bmapdata = bmap.LockBits(
         new Rectangle(0, 0, Image.Width, Image.Height),
         ImageLockMode.WriteOnly, 
         bmap.PixelFormat);
     IntPtr ptr = bmapdata.Scan0;
     Marshal.Copy(pixeldata, 0, ptr, Image.PixelDataLength);
     bmap.UnlockBits(bmapdata);
     return bmap;
 }

And the Color frame image is provided from the Kinect SDK's ColorFrameReady delegate

private void SensorColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
{
    using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
    {
        if (colorFrame != null)
        {
            // Copy the pixel data from the image to a temporary array
            colorFrame.CopyPixelDataTo(this.colorPixels);

            // Write the pixel data into our bitmap
            this.colorBitmap.WritePixels(
                new Int32Rect(0, 0, this.colorBitmap.PixelWidth, this.colorBitmap.PixelHeight),
                this.colorPixels,
                this.colorBitmap.PixelWidth * sizeof(int),
                0);
            AviManager aviManager = new AviManager(@"C:\temp\temp.avi", false);
            VideoStream aviStream = aviManager.AddVideoStream(false, 30, bmp);

            Bitmap bitmap = ImageToBitmap(colorFrame);
            aviStream.AddFrame(bitmap);
            bitmap.Dispose();
            aviManager.Close();
        }
    }
}

Thank you !

Was it helpful?

Solution

The AForge.NET framework provides several functions that allow you to easily write AVI, or other, video files. It also provides direct support for the Kinect, allowing you to get access to the video camera.

However, per information on the website, it requires libfreenect. I am unaware if libfreenect and the office Kinect SDK can live in harmony with each other in the same application.

The AVIWriter class is pretty straight forward and would not necessarily require you to use AForge.NET's Kinect access. You could just as easily get the latest color frame from the official Kinect SDK, convert it to a Bitmap and output it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top