XVID codec via vfw: creating greyscale 8 bit video fails

1k views Asked by At

I have written an application that records XVID movies from a live camera image using Video for Windows (VFW). This works fine if the camera is set to colour. When I switch it to a b&w mode (ie 8 bit greyscale) the function AVIStreamSetFormat returns AVIERR_BADFORMAT.

Excerpt from my code:

BITMAPINFO *bmi = image->bitmapInfo();

AVISTREAMINFO info;
::ZeroMemory(&info,sizeof(AVISTREAMINFO));
info.fccType               = streamtypeVIDEO;
info.dwScale               = 1000;
info.dwRate                = int(framesPerSecond * 1000);
info.dwSuggestedBufferSize = image->bufferSize();
SetRect(&info.rcFrame, 0, 0, image->width(), image->height());

AVICOMPRESSOPTIONS options;
::ZeroMemory(&options, sizeof(options))
options.fccType = streamtypeVIDEO;
options.fccHandler = mmioFOURCC('X','V','I','D');
options.dwFlags = AVICOMPRESSF_VALID | AVICOMPRESSF_KEYFRAMES;

info.fccHandler = options.fccHandler;
AVIFileCreateStream(pfile, &pavi, &info);

options.dwKeyFrameEvery = 1;
options.dwQuality = -1;
options.dwInterleaveEvery = 0;

HRESULT result = AVIMakeCompressedStream(&pcompressed, pavi, &options, NULL);

size_t bmisize = bmi->bmiHeader.biSize + bmi->bmiHeader.biClrUsed*sizeof(RGBQUAD);
result = AVIStreamSetFormat(pcompressed, 0, &bmi->bmiHeader, bmisize);

As stated above, this code works for 24-bit DIBs, but not for 8-bit indexed DIBs. The 8-bit DIBs can be displayed without problems.

Any ideas?

cheers Hendrik

1

There are 1 answers

0
Hendrik On BEST ANSWER

I've done some more research and looked into the xvidcore source code, which unfortunately makes it very clear that 8 bit greyscale sources are not supported. Function get_colorspace() in vfw/src/codec.c only recognizes RGB and YUV modes.

The situation is probably the same with the divx codec, although I haven't studied the sources.

So the answer is: choose a different codec or be restricted to colour video.