public void Open(string fileName, DisplayFormat videoFormat, int fps, VideoCompressor compressor, SoundFormat audioFormat, AcmEncoder audioEncoder) { if (this.opened) { throw new InvalidOperationException(); } if (string.IsNullOrEmpty(fileName)) { throw new ArgumentNullException("fileName"); } this.video = videoFormat != null; this.audio = audioFormat != null; if (!this.audio && !this.video) { // There is nothing to do! throw new InvalidOperationException(); } // Open AVI File int hr = Avi32Interop.AVIFileOpen(out this.pAviFile, fileName, Avi32Interop.OF_CREATE, IntPtr.Zero); if (hr != 0) { throw new AviException("AVIFileOpen", hr); } try { if (this.video) { this.SetupVideo(videoFormat, compressor, fps); } if (this.audio) { this.SetupAudio(audioFormat, audioEncoder); } this.opened = true; } finally { if (!this.opened) { this.Close(); } } }