0

I use Kinect SDK 2, C#. I want to save color stream with .AVI format. I get every frame and save them in .jpeg format with a serial number. I am not sure is it better to do it with .png or .jpeg. I need to turn these images into .AVI file in my code.

Here is how I save the images of the color stream. Could you please give me any advice about it?

private void Reader_ColorFrameArrived(object sender, 
ColorFrameArrivedEventArgs e)
        {
            // ColorFrame is IDisposable
            using (ColorFrame colorFrame = e.FrameReference.AcquireFrame())
            {
                if (colorFrame != null)
                {
                    var bytesPerPixel = (PixelFormats.Bgr32.BitsPerPixel) / 8;
                    var stride = bytesPerPixel * 
colorFrame.FrameDescription.Width;
                    if (colorRecord == 1)
                    {
                        colorFrame.CopyConvertedFrameDataToArray(colorData, format);
                        var fd = colorFrame.FrameDescription;

                        // Creating BitmapSource                      
                        bmpSource = BitmapSource.Create(fd.Width, fd.Height, 96.0, 96.0, PixelFormats.Bgr32, null, colorData, stride);

                        // WritableBitmap to show on UI
                        kinectImage.Source = bmpSource;
                        kinectImage.Source = colorBitmap;

                        // JpegBitmapEncoder to save BitmapSource to file
                        // imageSerial is the serial of the sequential image
                        JpegBitmapEncoder encoder = new JpegBitmapEncoder();
                        encoder.Frames.Add(BitmapFrame.Create(bmpSource));
                        using (var fs = new FileStream("img" + (imageSerial++) + ".jpeg", FileMode.Create, FileAccess.Write))
                        {
                            encoder.Save(fs);
                        }
                    }
                }

I found some info about ffmpeg on one of the posts but I couldn't understand how to use it in c#.

1 Answers1

0

Okey I found the answer.

The example I found my answer = https://github.com/rafaftahsin/Kinect-v2-Color-Frame-Recorder

I just put ffmpeg.exe file to the folder. Then run the code = Process.Start("ffmpeg.exe", "-framerate 10 -i img%d.jpeg -c:v libx264 -r 30 -pix_fmt yuv420p kinect_video.mp4");