Avifileopen error codes

avifileopen error codes

Returns zero if successful or an error otherwise. Possible error values include the following. Return code, Description. AVIERR_BADFORMAT. The. Thanks //This is the code. I try to use the function: AviFileOpen, but I get the error '' 0x The AVIFileOpen function opens an AVI file and returns the address of a file The AVIFile library maintains a count of the number of times a file is.

Avifileopen error codes - magnificent

OF_CREATE, NULL); if (hr!=AVIERR_OK) {AVIFileExit(); return NULL;} TAviUtil *au = new TAviUtil; au->pfile = pfile; if (wfx==NULL) ZeroMemory(&au->wfx,sizeof(WAVEFORMATEX)); else CopyMemory(&au->wfx,wfx,sizeof(WAVEFORMATEX)); au->period = frameperiod; au->as=0; au->ps=0; au->psCompressed=0; au->nframe=0; au->nsamp=0; au->iserr=false; return (HAVI)au; } HRESULT CloseAvi(HAVI avi) { if (avi==NULL) return AVIERR_BADHANDLE; TAviUtil *au = (TAviUtil*)avi; if (au->as!=0) AVIStreamRelease(au->as); au->as=0; if (au->psCompressed!=0) AVIStreamRelease(au->psCompressed); au->psCompressed=0; if (au->ps!=0) AVIStreamRelease(au->ps); au->ps=0; if (au->pfile!=0) AVIFileRelease(au->pfile); au->pfile=0; AVIFileExit(); delete au; return S_OK; } HRESULT SetAviVideoCompression(HAVI avi, HBITMAP hbm, AVICOMPRESSOPTIONS *opts, bool ShowDialog, HWND hparent) { if (avi==NULL) return AVIERR_BADHANDLE; if (hbm==NULL) return AVIERR_BADPARAM; DIBSECTION dibs; int sbm = GetObject(hbm,sizeof(dibs),&dibs); if (sbm!=sizeof(DIBSECTION)) return AVIERR_BADPARAM; TAviUtil *au = (TAviUtil*)avi; if (au->iserr) return AVIERR_ERROR; if (au->psCompressed!=0) return AVIERR_COMPRESSOR; // if (au->ps==0) // create the stream, if it wasn't there before { AVISTREAMINFO strhdr; ZeroMemory(&strhdr,sizeof(strhdr)); sprers.eue = streamtypeVIDEO;// stream type sprers.eudler = 0; sprers.eue = au->period; sprers.eu = ; sprers.euestedBufferSize = sprers.euImage; SetRect(&sprers.eue, 0, 0, sprers.euh, sprers.euht); HRESULT hr=AVIFileCreateStream(au->pfile, &au->ps, &strhdr); if (hr!=AVIERR_OK) {au->iserr=true; return hr;} } // if (au->psCompressed==0) // set the compression, prompting dialog if necessary { AVICOMPRESSOPTIONS myopts; ZeroMemory(&myopts,sizeof(myopts)); AVICOMPRESSOPTIONS *aopts[1]; if (opts!=NULL) aopts[0]=opts; else aopts[0]=&myopts; if (ShowDialog) { BOOL res = (BOOL)AVISaveOptions(hparent,0,1,&au->ps,aopts); if (!res) {AVISaveOptionsFree(1,aopts); au->iserr=true; return AVIERR_USERABORT;} } HRESULT hr = AVIMakeCompressedStream(&au->psCompressed, au->ps, aopts[0], NULL); AVISaveOptionsFree(1,aopts); if (hr != AVIERR_OK) {au->iserr=true; return hr;} DIBSECTION dibs; GetObject(hbm,sizeof(dibs),&dibs); hr = AVIStreamSetFormat(au->psCompressed, 0, &sprers.eu, sprers.eu+sprers.eused*sizeof(RGBQUAD)); if (hr!=AVIERR_OK) {au->iserr=true; return hr;} } // return AVIERR_OK; } HRESULT AddAviFrame(HAVI avi, HBITMAP hbm) { if (avi==NULL) return AVIERR_BADHANDLE; if (hbm==NULL) return AVIERR_BADPARAM; DIBSECTION dibs; int sbm = GetObject(hbm,sizeof(dibs),&dibs); if (sbm!=sizeof(DIBSECTION)) return AVIERR_BADPARAM; TAviUtil *au = (TAviUtil*)avi; if (au->iserr) return AVIERR_ERROR; // if (au->ps==0) // create the stream, if it wasn't there before { AVISTREAMINFO strhdr; ZeroMemory(&strhdr,sizeof(strhdr)); sprers.eue = streamtypeVIDEO;// stream type sprers.eudler = 0; sprers.eue = au->period; sprers.eu = ; sprers.euestedBufferSize = sprers.euImage; SetRect(&sprers.eue, 0, 0, sprers.euh, sprers.euht); HRESULT hr=AVIFileCreateStream(au->pfile, &au->ps, &strhdr); if (hr!=AVIERR_OK) {au->iserr=true; return hr;} } //// create an empty compression, if the user hasn't set any if (au->psCompressed==0) { AVICOMPRESSOPTIONS opts; ZeroMemory(&opts,sizeof(opts)); sprers.eudler=mmioFOURCC('D','I','B',' '); HRESULT hr = AVIMakeCompressedStream(&au->psCompressed, au->ps, &opts, NULL); if (hr != AVIERR_OK) {au->iserr=true; return hr;} hr = AVIStreamSetFormat(au->psCompressed, 0, &sprers.eu, sprers.eu+sprers.eused*sizeof(RGBQUAD)); if (hr!=AVIERR_OK) {au->iserr=true; return hr;} } ////Now we can add the frame HRESULT hr = AVIStreamWrite(au->psCompressed, au->nframe, 1, sprers.eu, sprers.euImage, AVIIF_KEYFRAME, NULL, NULL); if (hr!=AVIERR_OK) {au->iserr=true; return hr;} au->nframe++; return S_OK; } HRESULT AddAviAudio(HAVI avi, void *dat, unsigned long numbytes) { if (avi==NULL) return AVIERR_BADHANDLE; if (dat==NULL

Thread: AviFileOpen

  1. December 11th, ,  AM#1

    AviFileOpen

    Hello,

    I try to use the function : AviFileOpen, but I get the error '' 0x

    Can you help me to solve this bug?
    Thanks



    //This is the code
    AVIFileInit();
    int ret =AVIFileOpen(&aviFile,(LPCWSTR) AVIFileName,OF_READ,NULL);
    if (ret!=0)
    exit(-1);


  2. Re: AviFileOpen

    Code:

    int ret =AVIFileOpen(&aviFile,(LPCWSTR) AVIFileName,OF_READ,NULL);
    What type is your AVIFileName? And why do you need to cast it to a LPCWSTR?

    - petter

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Forum Rules




LR_CREATEDIBSECTION); AddAviFrame(avi,hbm); DeleteObject(hbm); } AddAviWav(avi,"sprers.eu",SND_FILENAME);CloseAvi(avi);

To create an AVI with DivX compression. This code creates the same AVI, with DivX compression for the video, and without the audio. The code actually just suggests DivX and pops up a dialog to let the user control more details (hwnd is some window to be used as the parent for that dialog). You might keep a copy of the opts structure so as to give the same defaults to the user next time. Or you can pass false to the SetAviVideoCompression function to suppress the user-interface dialog, if the opts structure is already filled out correctly.

const char *fns[] = {"sprers.eu","sprers.eu","sprers.eu","sprers.eu","sprers.eu"}; HAVI avi = CreateAvi("sprers.eu",,NULL); for (int i=0; i<sizeof(fns)/sizeof(fns[0]); i++) { HBITMAP hbm=(HBITMAP)LoadImage(NULL,fns[i],IMAGE_BITMAP,0,0,LR_LOADFROMFILE
extract a frame from a AVI file?
Autor: Thomas Stutz
[ Print tip ]  


uses
 
VfW { from download };

function GrabAVIFrame(avifn: string; iFrameNumber: Integer; ToFileName: TFileName): Boolean;
var
  
Error: Integer;
  pFile: PAVIFile;
  AVIStream: PAVIStream;
  gapgf: PGETFRAME;
  lpbi: PBITMAPINFOHEADER;
  bits: PChar;
  hBmp: HBITMAP;
  AviInfo: TAVIFILEINFOW;
  sError: string;
  TmpBmp: TBitmap;
  DC_Handle: HDC;
begin
  
Result := False;
  // Initialize the AVIFile library.
  
AVIFileInit;

  // The AVIFileOpen function opens an AVI file
  
Error := AVIFileOpen(pFile, PChar(avifn), 0, nil);
  if Error <> 0 then
  begin
    
AVIFileExit;
    case Error of
      
AVIERR_BADFORMAT: sError := 'The file couldn''t be read';
      AVIERR_MEMORY: sError := 'The file could not be opened because of insufficient memory.';
      AVIERR_FILEREAD: sError := 'A disk error occurred while reading the file.';
      AVIERR_FILEOPEN: sError := 'A disk error occurred while opening the file.';
    end;
    ShowMessage(sError);
    Exit;
  end;

  // AVIFileInfo obtains information about an AVI file
  
if AVIFileInfo(pFile, @AVIINFO, SizeOf(AVIINFO)) <> AVIERR_OK then
  begin
    
// Clean up and exit
    
AVIFileRelease(pFile);
    AVIFileExit;
    Exit;
  end;

  // Show some information about the AVI
  
sprers.eu('AVI Width : ' + IntToStr(sprers.euh));
  sprers.eu('AVI Height : ' + IntToStr(sprers.euht));
  sprers.eu('AVI Length : ' + IntToStr(sprers.euth));

  // Open a Stream from the file
  
Error := AVIFileGetStream(pFile, AVIStream, streamtypeVIDEO, 0);
  if Error <> AVIERR_OK then
  begin
    
// Clean up and exit
    
AVIFileRelease(pFile);
    AVIFileExit;
    Exit;
  end;

  // Prepares to decompress video frames
  
gapgf := AVIStreamGetFrameOpen(AVIStream, nil);
  if gapgf = nil then
  begin
    
AVIStreamRelease(AVIStream);
    AVIFileRelease(pFile);
    AVIFileExit;
    Exit;
  end;

  // Read current Frame
  // AVIStreamGetFrame Returns the address of a decompressed video frame
  
lpbi := AVIStreamGetFrame(gapgf, iFrameNumber);
  if lpbi = nil then
  begin
    
AVIStreamGetFrameClose(gapgf);
    AVIStreamRelease(AVIStream);
    AVIFileRelease(pFile);
    AVIFileExit;
    Exit;
  end;

  // Show number of frames:
  
sprers.eu(Format('Framstart: %d FrameEnd: %d',
    [AVIStreamStart(AVIStream), AVIStreamEnd(AVIStream)]));

  TmpBmp := sprers.eu;
  try
    
sprers.eu := sprers.euht;
    sprers.eu  := sprers.euh;
    bits := Pointer(Integer(lpbi) + SizeOf(TBITMAPINFOHEADER));

    DC_Handle := CreateDC('Display', nilnilnil);
    try
      
hBmp := CreateDIBitmap(DC_Handle, // handle of device context
        
lpbi^, // address of bitmap size and format data
        
CBM_INIT, // initialization flag
        
bits, // address of initialization data
        
PBITMAPINFO(lpbi)^, // address of bitmap color-format data
        
DIB_RGB_COLORS); // color-data usage
    
finally
      
DeleteDC(DC_Handle);
    end;

    sprers.eu := hBmp;
    AVIStreamGetFrameClose(gapgf);
    AVIStreamRelease(AVIStream);
    AVIFileRelease(pfile);
    AVIFileExit;
    try
      
sprers.euFile(ToFileName);
      Result := True;
    except
    end
;
  finally
    
sprers.eu;
  end;
end;

procedure sprers.eu1Click(Sender: TObject);
begin
  
// Extract Frame 3 from AVI file
  
GrabAVIFrame('C:\sprers.eu', 3, 'c:\sprers.eu');
end;


 

numbytes==0) return AVIERR_BADPARAM; TAviUtil *au = (TAviUtil*)avi; if (au->iserr) return AVIERR_ERROR; if (au->sprers.euels==0) return AVIERR_BADFORMAT; unsigned long numsamps = numbytes*8 / au->sprers.euerSample; if ((numsamps*au->sprers.euerSample/8)!=numbytes) return AVIERR_BADPARAM; // if (au->as==0) // create the stream if necessary { AVISTREAMINFO ahdr; ZeroMemory(&ahdr,sizeof(ahdr)); sprers.eue=streamtypeAUDIO; sprers.eue=au->sprers.euAlign; sprers.eu=au->sprers.euesPerSec*au->sprers.euAlign; sprers.euleSize=au->sprers.euAlign; sprers.euity=(DWORD)-1; HRESULT hr = AVIFileCreateStream(au->pfile, &au->as, &ahdr); if (hr!=AVIERR_OK) {au->iserr=true; return hr;} hr = AVIStreamSetFormat(au->as,0,&au->wfx,sizeof(WAVEFORMATEX)); if (hr!=AVIERR_OK) {au->iserr=true; return hr;} } //// now we can write the data HRESULT hr = AVIStreamWrite(au->as,au->nsamp,numsamps,dat,numbytes,0,NULL,NULL); if (hr!=AVIERR_OK) {au->iserr=true; return hr;} au->nsamp+=numsamps; return S_OK; } HRESULT AddAviWav(HAVI avi, const char *src, DWORD flags) { if (avi==NULL) return AVIERR_BADHANDLE; if (flags!=SND_MEMORY && flags!=SND_FILENAME) return AVIERR_BADFLAGS; if (src==0) return AVIERR_BADPARAM; TAviUtil *au = (TAviUtil*)avi; if (au->iserr) return AVIERR_ERROR; // char *buf=0; WavChunk *wav = (WavChunk*)src; if (flags==SND_FILENAME) { HANDLE hf=CreateFile(src,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,0,NULL); if (hf==INVALID_HANDLE_VALUE) {au->iserr=true; return AVIERR_FILEOPEN;} DWORD size = GetFileSize(hf,NULL); buf = new char[size]; DWORD red; ReadFile(hf,buf,size,&red,NULL); CloseHandle(hf); wav = (WavChunk*)buf; } //// check that format doesn't clash bool badformat=false; if (au->sprers.euels==0) { au->sprers.eutTag=wav->sprers.eutTag; au->sprers.eu=0; au->sprers.eutesPerSec=wav->sprers.euytesPerSec; au->sprers.euAlign=wav->sprers.euAlign; au->sprers.euels=wav->sprers.euels; au->sprers.euesPerSec=wav->sprers.eulesPerSec; au->sprers.euerSample=wav->sprers.euerSample; } else { if (au->sprers.eutTag!=wav->sprers.eutTag) badformat=true; if (au->sprers.eutesPerSec!=wav->sprers.euytesPerSec) badformat=true; if (au->sprers.euAlign!=wav->sprers.euAlign) badformat=true; if (au->sprers.euels!=wav->sprers.euels) badformat=true; if (au->sprers.euesPerSec!=wav->sprers.eulesPerSec) badformat=true; if (au->sprers.euerSample!=wav->sprers.euerSample) badformat=true; } if (badformat) {if (buf!=0) delete[] buf; return AVIERR_BADFORMAT;} // if (au->as==0) // create the stream if necessary { AVISTREAMINFO ahdr; ZeroMemory(&ahdr,sizeof(ahdr)); sprers.eue=streamtypeAUDIO; sprers.eue=au->sprers.euAlign; sprers.eu=au->sprers.euesPerSec*au->sprers.euAlign; sprers.euleSize=au->sprers.euAlign; sprers.euity=(DWORD)-1; HRESULT hr = AVIFileCreateStream(au->pfile, &au->as, &ahdr); if (hr!=AVIERR_OK) {if (buf!=0) delete[] buf; au->iserr=true; return hr;} hr = AVIStreamSetFormat(au->as,0,&au->wfx,sizeof(WAVEFORMATEX)); if (hr!=AVIERR_OK) {if (buf!=0) delete[] buf; au->iserr=true; return hr;} } //// now we can write the data unsigned long numbytes = wav->sprers.eu; unsigned long numsamps = numbytes*8 / au->sprers.euerSample; HRESULT hr = AVIStreamWrite(au->as,au->nsamp,numsamps,wav->sprers.eu,numbytes,0,NULL,NULL); if (buf!=0) delete[] buf; if (hr!

Keywords

The code on this page demonstrates the following functions and data structures:

WAV file format, RIFF file, Chunk, WAVE_FORMAT_PCM, IAVIFile, PAVIFile, WAVEFORMAT, WAVEFORMATEX, IAVIStream, PAVIStream, AVIFileInit, AVIFileOpen, AVIFileExit, AVIStreamRelease, AVIStreamClose, AVIFileRelease, DIBSECTION, GetObject, device independent bitmap, AVISTREAMINFO, streamtypeVIDEO, streamtypeAUDIO, AVIFileCreateStream, AVICOMPRESSOPTIONS, AVIMakeCompressedStream, AVIStreamSetFormat, mmioFOURCC, AVIStreamWrite.