1

How can I playback and save selected raw video frames from raw video data (in .rgb or .raw).

Raw uncompressed video data is 320 x 240 in grayscale format with 1 byte/pixel and just 30 fps.

But how can I view multiple the frames in 30 FPS? Can I use DirectShow or a similar API? And what is the best resource to get started? I looked at FFPMEG but I want to avoid showing compressed frames as this it is for scientific application.

So far I have been able to view one frame from a raw video data (in .rgb) using this code in C# .NET for Win Forms using a Picture Box control. But not sure how to do multiple frames and perhaps have a seeking control.

byte[] imageData = File.ReadAllBytes("output.rgb");
        Console.WriteLine("imageDataLen=" + imageData.Length);
        int width = 320;
        int height = 240;

        var bmp = new Bitmap(width, height, PixelFormat.Format8bppIndexed);
        //bmp = (Bitmap) ConvertToGrayScale(bmp);
        ColorPalette pal = bmp.Palette;
        for (int i = 0; i <= 255; i++)
        {
            // create greyscale color table
            pal.Entries[i] = Color.FromArgb(i, i, i);
        }
        bmp.Palette = pal;
        BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0,
                                                        bmp.Width,
                                                        bmp.Height),
                                                        ImageLockMode.WriteOnly,
                                                        bmp.PixelFormat);
        Marshal.Copy(imageData, 0, bmpData.Scan0, width * height);
        bmp.UnlockBits(bmpData);
        pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
        pictureBox1.Image = bmp;
Qwerty
  • 323
  • 1
  • 6
  • 33
  • You can simply transfer the video frame bytes to a directx surface and display it using DirectX APIs. As for the seeking: you might need to write a custom source filter (for directshow) or custom media source for Media Foundation. – VuVirt Mar 26 '17 at 15:36
  • Thanks! So should I transfer the video frame bytes to DirectX surface using the details here https://msdn.microsoft.com/en-us/library/windows/desktop/aa473821(v=vs.85).aspx. This seems to be a C++ implementation, can this be done with C#? Also do I use the DirectX API in conjunction with DirectShow to write a custom source filter (for the seeking etc)? – Qwerty Mar 27 '17 at 08:55
  • DirectShow provides hardware accelerated video renderers like VMR9 and EVR which you can use directly in your app. You just need to provide a custom source for raw uncompressed video data. You can check the PushSource DirectShow filter examples: https://msdn.microsoft.com/en-us/library/windows/desktop/dd375468(v=vs.85).aspx – VuVirt Mar 27 '17 at 10:24
  • You can take a look here for .NET implementation: http://directshownet.sourceforge.net/ – VuVirt Mar 27 '17 at 11:36

0 Answers0