VideoHelp Forum




+ Reply to Thread
Results 1 to 4 of 4
  1. I have written a program that reads frames from an avi, manipulates them, and then writes them to an output avi. Everything works fine for 73 frames, but on frame 74 AVIStreamGetFrameOpen returns nothing rather than a pointer to a getframe object. Anyone know what I am doing wrong? Here is the main code of my program:

    Code:
    avi_stat=AVIFileOpen(&InFile,InName,OF_SHARE_DENY_WRITE,NULL);
    
    avi_stat=AVIFileInfo(InFile,&InFileInfo,sizeof(InFileInfo));
    
    FrameWidth=InFileInfo.dwWidth;
    
    FrameHeight=InFileInfo.dwHeight;
    
    avi_stat = AVIStreamOpenFromFile(&InStream,
              InName,streamtypeVIDEO,0,OF_SHARE_DENY_WRITE,NULL);
    
    avi_stat=AVIStreamInfo(InStream,&InStreamInfo,sizeof(InStreamInfo));
    
    CurrFrame=AVIStreamStart(InStream);
    
    LastFrame=AVIStreamEnd(InStream)-CurrFrame;
    
    avi_stat=AVIStreamFormatSize(InStream, 0, &lStreamSize);
    
    hr=AVIStreamReadFormat(InStream,0,&InBmp,&lStreamSize);
    
    OutBmp=InBmp;
    
    OutBmp.biCompression=0;
    
    OutBmp.biSizeImage=(OutBmp.biWidth * OutBmp.biHeight *3);
    
    avi_stat=AVIFileOpen(&OutFile,OutName,OF_WRITE|OF_CREATE,NULL);
    
    _fmemset(&OutStreamInfo,0,sizeof(OutStreamInfo));
    
    OutStreamInfo.fccType=streamtypeVIDEO;
    
    OutStreamInfo.fccHandler=0;
    
    OutStreamInfo.dwScale=1;
    
    OutStreamInfo.dwRate=InStreamInfo.dwRate;
    
    OutStreamInfo.dwSuggestedBufferSize=
                  (InBmp.biWidth*InBmp.biHeight*6);
    
    OutStreamInfo.dwLength=InStreamInfo.dwLength;
    
    SetRect(&OutStreamInfo.rcFrame,0,0,FrameWidth,FrameHeight);
    
    fbuff=new unsigned char[OutStreamInfo.dwSuggestedBufferSize * sizeof
                   (char )];
    
    hr=AVIFileCreateStream(OutFile,&OutStream,&OutStreamInfo);
    
    _fmemset(&opts, 0, sizeof(opts));
    
    if (!AVISaveOptions(NULL, 0, 1, &OutStream, (LPAVICOMPRESSOPTIONS
             FAR *) &aopts)){}
    
    hr=AVIMakeCompressedStream(&CompressedStream,
                     OutStream,&opts,NULL);
    
    hr=AVIStreamSetFormat(CompressedStream,0,&OutBmp,
                    OutBmp.biSize+OutBmp.biClrUsed*sizeof(RGBQUAD));
    
    for(CurrFrame=0;CurrFrame<LastFrame;CurrFrame++)
    {
    	pgf=AVIStreamGetFrameOpen(InStream,&OutBmp);
    
    	fbuff=(unsigned char*)AVIStreamGetFrame(pgf,CurrFrame);
    
                 avi_stat=AVIStreamWrite(CompressedStream,CurrFrame,1,fbuff,
                               InBmp.biSizeImage,AVIIF_KEYFRAME,NULL,NULL);
    }
    AVIStreamRelease(InStream);
    
    AVIStreamRelease(OutStream);
    
    AVIStreamRelease(CompressedStream);
    
    AVIFileRelease(OutFile);
    
    AVIFileRelease(inFile);
    Quote Quote  
  2. Member
    Join Date
    Aug 2002
    Location
    cleveland, oh
    Search Comp PM
    I would take a careful look at AVIStreamGetFrameOpen().
    What happens at frame 74, exception, crash, ect.
    What happens if you start at frame 75.
    Quote Quote  
  3. After frame 73, pgf shows a member IUknown, which has a member _vfptr which has 3 entries( [0] , [1], [2] ). Each of these shows a valid memory location. At frame 74, however, pgf show 0x00000000, a member IUnknown which shows: CXX0030: Error: Expression cannot be evaluated. If I put the following statement to just skip any frames like that:

    Code:
    if(!pgf)
    {
       SkipFrame();
    }
    I see that the same thing occurs on every frame after that. When I use an uncompressed input avi, however, everything runs fine. The input compressed files have only one video stream, so it isn't that the video is split between streams. Do the compressed files use some kind of different chunk, where I am hitting the end of one and somehow have to move on to the beginning of another chunk in the same stream? and if so, how? I appreciate any help you might be able to provide!

    Steve Sherrin
    Quote Quote  
  4. Hey. I got similar problems. God..! it was so hard to figure out.
    AviStreamGetFrame doesn't "tolerate" I would say custom written streams.
    F.ex written by VirtualDub. If u have long stream like 200000frames
    I guarantee AVIStr... will fail. It is better to write custom stream functions
    just like VirtualDub is using. Custom parsers and stream decompressors.
    It's all done under IUnknown class level. Microsoft has to fix something there I think. My movies were stopping after strange but CONSTANT number of frames unless written by other program than VDub or similar.
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!