Image

Imager3code wrote in Imagecpp

Save avi video stream in separate file (vfw.h)

I've done some code, but extracted video stream is very large (15mb->1GB) and won't play in media players. But in properties all looks good the same time resolution ...

There is my try:


void SaveStream(PAVISTREAM ps, LPSTR lpFilename)
{
PAVIFILE pf;
PAVISTREAM psAvi;
HRESULT hr;
AVISTREAMINFO strhdr;
BITMAPINFOHEADER bi,
biNew;
LONG lStreamSize;
LPVOID lpOld,
lpNew;

// AVIStreamFormatSize.
AVIStreamFormatSize(ps, 0, &lStreamSize);
if (lStreamSize > sizeof(bi)) // Format too large?
return;

lStreamSize = sizeof(bi);
hr = AVIStreamReadFormat(ps, 0, &bi, &lStreamSize); //

String msg = "";
switch (bi.biCompression)
{
case BI_RGB: msg = "Uncompressed";
case BI_RLE8: msg = "RLE 8 ";
case BI_RLE4: msg = "RLE 4 ";
case BI_BITFIELDS: msg = "16,32-uncompr";
case BI_JPEG: msg = "JPEG";
case BI_PNG: msg = "PNG";
default: msg = "Unknown!";
}
ShowMessage(msg);

hr = AVIStreamInfo(ps, &strhdr, sizeof(strhdr)); //

// AVIFileOpen.
hr = AVIFileOpen(&pf, lpFilename, OF_WRITE | OF_CREATE, NULL);
if (hr != 0)
return;

//
biNew = bi;
biNew.biCompression = 0; //
// AVIFileCreateStream.
hr = AVIFileCreateStream(pf, &psAvi, &strhdr);
if (hr != 0) { //
AVIFileRelease(pf);
return;
}

// AVIStreamSetFormat.
hr = AVIStreamSetFormat(psAvi, 0, &biNew, sizeof(biNew));
if (hr != 0) { //
AVIStreamRelease(psAvi);
AVIFileRelease(pf);
return;
}

//
lpOld = GlobalAllocPtr(GMEM_MOVEABLE, bi.biSizeImage);
lpNew = GlobalAllocPtr(GMEM_MOVEABLE, biNew.biSizeImage);

// Read the stream data using AVIStreamRead.
for (lStreamSize = AVIStreamStart(ps); lStreamSize <
AVIStreamEnd(ps); lStreamSize++) {
hr = AVIStreamRead(ps, lStreamSize, 1, lpOld, bi.biSizeImage,
NULL, NULL);
if (hr != 0) { // н
AVIStreamRelease(psAvi);
AVIFileRelease(pf);
return;
}

// AVIStreamWrite.
hr = AVIStreamWrite(psAvi, lStreamSize, 1, lpNew,
biNew.biSizeImage, AVIIF_KEYFRAME, NULL, NULL);
}

//
AVIStreamRelease(psAvi);
AVIFileRelease(pf);
}


void __fastcall TForm1::FormCreate(TObject *Sender)
{
PAVISTREAM pVideoStream;

bool bFileOpen;
if(OpenDialog1->Execute()) {

long r, fmtlen;
AVIFileInit();
r = AVIStreamOpenFromFile(&pVideoStream, OpenDialog1->FileName.c_str(),
streamtypeVIDEO, 0, OF_READ | OF_SHARE_EXCLUSIVE, 0);
if(r!=0) ShowMessage("Cant load file stream!");


SaveStream(pVideoStream, "out.avi");

AVIFileExit();
ShowMessage("Done!");
}//if openD
}


On open it always shows "Unknown". I think it's some other compression with codec...

Can any one show me how to do it?