Board index » cppbuilder » AVI->BMPs

AVI->BMPs

I want to take an AVI file and extract individual bitmaps.  Can someone
please tell me how to go about this in BCB4?  TIA
 

Re:AVI->BMPs


Quote
"Mark Dutch" <ma...@intermtech.com.au> wrote in message

news:3A762C47.2F2ED221@intermtech.com.au...

Quote
> I want to take an AVI file and extract individual bitmaps.  Can someone
> please tell me how to go about this in BCB4?  TIA

    You may try the following code:

// -------------------------------------------------------------------------
--
#include
#include
#include
#include
#pragma hdrstop
#include "Unit1.h"
int bmpsave(const char *fname, LPBITMAPINFOHEADER pbmih);
// -------------------------------------------------------------------------
--
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
// -------------------------------------------------------------------------
--
__fastcall TForm1::TForm1(TComponent* Owner)
  : TForm(Owner)
{

Quote
}

// ------------------------------------------------------------------------------
int bmpsave(const char *fname, LPBITMAPINFOHEADER pbmih)
{
  int s, x, y;
  BITMAPFILEHEADER bmfh;
  FILE *fp;

  x = pbmih->biWidth;
  y = abs(pbmih->biHeight);

  bmfh.bfType = 0x4d42;
  bmfh.bfReserved1 = bmfh.bfReserved2 = 0;

  if (pbmih->biClrUsed == 0)
  {
    ShowMessage("Usando todas cores");
    switch (pbmih->biBitCount)
    {
      case 1:
        bmfh.bfOffBits = 8;
      break;

      case 4:
        bmfh.bfOffBits = 64;
      break;

      case 8:
        bmfh.bfOffBits = 1024;
      break;

      case 24:
        bmfh.bfOffBits = 0;
      break;

      case 16:
      case 32:
        bmfh.bfOffBits = pbmih->biCompression == BI_RGB ? 12 : 0;
      break;
    }
  }
  else
  {
    bmfh.bfOffBits = pbmih->biClrUsed * 4;
  }

  bmfh.bfOffBits += sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
  if (pbmih->biSizeImage == 0)
  {
    switch (pbmih->biBitCount)
    {
      case 1:
        s = (x + 7) / 8;
      break;

      case 4:
        s = (x + 1) / 2;
      break;

      case 8:
        s =
x;
      break;

      case 16:
        s = x * 2;
      break;

      case 24:
        s = x * 3;
      break;

      case 32:
        s = x * 4;
      break;
    }

    bmfh.bfSize = bmfh.bfOffBits + (s + 3) / 4 * 4 * y;
  }
  else

    bmfh.bfSize = bmfh.bfOffBits+pbmih->biSizeImage;
  }

  if ((fp = fopen(fname, "wb")) == NULL)
    ShowMessage("Arquivo n?o pode ser criado");
    return -1;
  }
  if (fwrite(&bmfh, sizeof(BITMAPFILEHEADER), 1, fp) != 1
      || fwrite(pbmih, bmfh.bfSize - sizeof(BITMAPFILEHEADER), 1, fp) != 1)
    return -1;

  return fclose(fp);

Quote
}

// -------------------------------------------------------------------------
-----
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  LPBITMAPINFOHEADER pbmih;
  PAVIFILE pavi;
  PAVISTREAM pstm;
  PGETFRAME pfrm;

  AVIFileInit();
  if (AVIFileOpen(&pavi, "TEST.AVI", OF_READ | OF_SHARE_DENY_NONE, NULL) != 0)
  {
    ShowMessage("Arquivo n?o encontrado!");
    return;
  }

  if (AVIFileGetStream(pavi, &pstm, 0, 0) != 0)
  {
    ShowMessage("Este arquivo n?o parece ser um AVI vlido!");
    return;
  }

  if ((pfrm = AVIStreamGetFrameOpen(pstm, NULL)) == NULL)
  {
    ShowMessage("Formato de compress?o invlido!");
    return;
  }

  if ((pbmih = (LPBITMAPINFOHEADER)AVIStreamGetFrame(pfrm, 7)) == NULL)
  {
    ShowMessage("Frame inexistente!");
    return;
  }

  if (bmpsave("TEST01.BMP", pbmih) != 0)
    return;

  if (AVIStreamGetFrameClose(pfrm) != 0)
    return;

  AVIStreamRelease(pstm);
  AVIFileRelease(pavi);
  AVIFileExit();
  return;

Quote
}

// ------------------------------------------------------------------------------

Re:AVI->BMPs


Thanks Wenderson.  I'll try your code.
Regards,
Mark.

Re:AVI->BMPs


Quote
Wenderson Teixeira wrote:
> >     You may try the following code:

> // -------------------------------------------------------------------------
> --
> #include
> #include
> #include
> #include
> #pragma hdrstop
> #include "Unit1.h"
> int bmpsave(const char *fname, LPBITMAPINFOHEADER pbmih);
> // -------------------------------------------------------------------------
> --
> #pragma package(smart_init)
> #pragma resource "*.dfm"
> TForm1 *Form1;
> // -------------------------------------------------------------------------
> --
> __fastcall TForm1::TForm1(TComponent* Owner)
>   : TForm(Owner)

-------------------------- SNIP --------------------------------

Wenderson, I have tried to use your code but get many errors.
Undefined symbol PAVIFILE, PAVISTREAM, PGETFRAME...
Undefined function AVIFileInit, AVIFileopen, AVIFileGetStream...
Am I missing some include files or did you forget to include them in the
snippet  you supplied.

Kind Regards,
Mark.

Re:AVI->BMPs


Quote
> Wenderson, I have tried to use your code but get many errors.
> Undefined symbol PAVIFILE, PAVISTREAM, PGETFRAME...
> Undefined function AVIFileInit, AVIFileopen, AVIFileGetStream...
> Am I missing some include files or did you forget to include them in the
> snippet  you supplied.

> Kind Regards,
> Mark.

Hi Mark,

Try to include

#include <vfw.h>

Regards

Christophe

Re:AVI->BMPs


Quote
Christophe Minetti wrote:
> Hi Mark,

> Try to include

> #include <vfw.h>

> Regards

> Christophe

Thanks Christophe.  That was the problem all right.
Kind Regards,
Mark Dutch

Re:AVI->BMPs


By the way Christophe, where do I find help on the VFW stuff??  The code
snippet Wenderson provided definitely extracted a bitmap, but I want to
break down the whole avi into bitmaps.  For this I need more info on the
individual functions called.
Regards,
Mark Dutch

Re:AVI->BMPs


It's included with BCB3 Pro, you can also look on the Microsoft msdn site
for information.

Regards,

Stuart

Quote
"Mark Dutch" <ma...@intermtech.com.au> wrote in message

news:3A8471C4.216801C2@intermtech.com.au...
Quote
> By the way Christophe, where do I find help on the VFW stuff??  The code
> snippet Wenderson provided definitely extracted a bitmap, but I want to
> break down the whole avi into bitmaps.  For this I need more info on the
> individual functions called.
> Regards,
> Mark Dutch

Other Threads