Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions desktop-src/Multimedia/compressing-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,49 @@ else

```

A detailed compress-image-data example, which explains how to write compressed data to the AVI file, can be found in
[**the SO post**](https://stackoverflow.com/questions/22765194/is-it-possible-to-encode-using-the-mrle-codec-on-video-for-windows-under-windows/79762695#79762695)
. A crucial point of this post states that, when writing the compressed data, we do still need to create the compressed stream, but we no longer write to it,
as we did it before Windows 8. Instead we write RLE8 encoded data to the raw stream. Also, we do not put the compress loop inside ICCompressBegin/ICCompressEnd
brackets, because AVIStreamSetFormat sends the ICM_COMPRESS_BEGIN message with lpInput and lpOutput parameters (as the ICCompressBegin macro does) and AVIStreamRelease sends the ICM_COMPRESS_END message (as the ICCompressEnd macro does in the code above):

```C
DWORD dwCkID;
DWORD dwCompFlags = AVIIF_KEYFRAME;
LONG lNumFrames, lFrameNum = 0;
LONG lSamplesWritten = 0;
LONG lBytesWritten = 0;
// Assume dwNumFrames is initialized to the total number of frames.
// Assume dwQuality holds the proper quality value (0-10000).
// Assume lpbiOut, lpOut, lpbiIn, and lpIn are initialized properly.

if (AVIStreamSetFormat(pCompressedStream, 0, lpbiIn, biSize) != 0)
{
std::cout << "AVIStreamSetFormat failed" << std::endl;
return 1;
}

for (int frame = 0; frame < nframes; frame++)
{
ICCompress(hIC, 0, lpbiOut, lpOutput, lpbiIn, lpInput,
&dwCkID, &dwCompFlags, frame, lpbiIn->biSizeImage, dwQuality, NULL, NULL);
hr = AVIStreamWrite(pStream, frame, 1, lpOutput, lpbiOut->biSizeImage,
AVIIF_KEYFRAME, &lSamplesWritten, &lBytesWritten);
if (hr != S_OK)
{
std::cout << "AVIStreamWrite failed" << std::endl;
return 1;
}
}

//GlobalUnlock(...),GlobalFree(...);

if (AVIStreamRelease(pCompressedStream) != 0 || AVIStreamRelease(pStream) != 0)
{
std::cout << "AVIStreamRelease failed" << std::endl;
return 1;
}
```



Expand Down