0

I am facing an issue with the AviManager library. I want to create an AVI file to store a video, but I keep getting an error on this line:

_aviManager = new AviManager(@"c:\\Recordings\\test.avi", false);

Looking into the library, this method looks like this:

public AviManager(String fileName, bool open){
        Avi.AVIFileInit();
        int result;
        if(open){ //open existing file

            result = Avi.AVIFileOpen(
                ref aviFile, fileName,
                Avi.OF_READWRITE, 0);
        }else{ //create empty file

            result = Avi.AVIFileOpen(
                ref aviFile, fileName,
                Avi.OF_WRITE | Avi.OF_CREATE, 0);

        }
        if(result != 0) {
            throw new Exception("Exception in AVIFileOpen: "+result.ToString());
        }
    }

Because the file currently does not exist, it should enter the else part and create a new file. It creates the file but then it crashes because the result took the value -2147205009. My question is, why does it do this?

LaCartouche
  • 121
  • 1
  • 11

2 Answers2

0

I had the same issue and this was caused in my case by a stream not being properly disposed (so once opened the "*.avi" file became locked and then every next opening attempt ended up with this error).

To avoid that please ensure that you close/dispose all the AVI objects in the correct order: CORRECT:

aviManager.Close();
newStream.GetFrameClose();

and also remove all the "nulling" like aviManager=null; etc. from the end of code (it caused some random issues on my machine).

Hope that helps.

kleopatra
  • 51,061
  • 28
  • 99
  • 211
Pete Kozak
  • 493
  • 1
  • 4
  • 21
0

The problem probably is in the path. Is the folder C:\Recordings created before creating the test.avi file? Try to create the path in the system first:

if(!Directory.Exists(path))
   Directory.CreateDirectory(path);

Where

path = @"c:\Recordings"

(Using "\\" together with "@" is unnecessary, because backslash is escaped in either way.)

ZimaXXX
  • 1,255
  • 11
  • 11