I make a frame from the camera using avicap32 ... In the CALLBACK frame capture function, I get a pointer to the VIDEOHDR structure. Now you need to take lpVHDR->lpData and somehow make it a buffer with compressed JPEG.

When I captured a frame in a browser using JS (getUserMedia), then from a canvas, base64-jpeg of ~ 13 Kb was obtained (at a compression of 50% at a resolution of 320x240). It is necessary to somehow make such compression in C ++, since the current raw binary weighs ~ 200 Kb, which is a bit too much for the tasks.

Can you please tell lpVHDR->lpData how to make a JPEG from lpVHDR->lpData and compress it? It is desirable, of course, without third-party libraries (probably using GDI +), but if I can’t do without them, I’ll figure it out. Just give direction please))

PS: it is not necessary to save the file, since the "communication" with the hard disk will affect the speed of the application. JPEG is needed in the buffer for later sending to the server.

Initialization of format and resolution after calling capDriverConnect :

 capGetVideoFormat(HStream, &BitmapInfo, sizeof(BitmapInfo)); BitmapInfo.bmiHeader.biWidth = 320; BitmapInfo.bmiHeader.biHeight = 240; BitmapInfo.bmiHeader.biCompression = 0x32595559; BitmapInfo.bmiHeader.biSizeImage = 153600; capSetVideoFormat(HStream, &BitmapInfo, sizeof(BitmapInfo)); 

If you set BI_JPEG in biCompression , then capSetVideoFormat returns FALSE for some reason.

  • Here is an example of how to load a picture using GDI +, if the pointer contains a valid JPG. If it contains a JPG chunk (For example, the compressed data without a header), then you will have to first make a memory-jpg with a JFIF signature, and then call GdipCreateBitmapFromStream . - nick_n_a
  • Well thank you. But what does "valid JPG" mean? I added a bitmap header code, there only YUY2 is installed. It does not hurt? - Iceman
  • Valid - meaning such a “packet” byte, which, if saved to disk as 1.jpg and opened, you will see a picture. The package usually contains a JFIF (4A 46 49 46) -signature. - nick_n_a
  • one
    I do not see what you have in lpData. Three options. 1. The simplest is bitmap or another format that sees GDI + - we just load into GDI, we can even position your HStream to 0 and send to GdipCreateBitmapFromStream. 2. this is just a set of bytes RGB - convert to a bitmap and load into GDI or the GdipCreateBitmapFromScan0 . 3. If this is a compressed stream - we are looking for how to compress and do 1 or 2. Link to msdn GDI + - nick_n_a
  • one
    Hardly. It is easier for you to read about YUY2 and convert it into an RGB cycle, and there already getting almost bmp to compress as needed. - nick_n_a

0