Exemplo n.º 1
0
 public AcmEncoder GetEncoder()
 {
     bool encoderNeeded;
      SoundFormat inputFormat = GetInputFormat(out encoderNeeded);
      if (!encoderNeeded) {
     return null;
      }
      AcmEncoder encoder = new AcmEncoder();
      encoder.InputFormat = inputFormat;
      encoder.OutputFormat = this.format;
      return encoder;
 }
Exemplo n.º 2
0
 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();
     }
      }
 }
Exemplo n.º 3
0
 private void SetupAudio(SoundFormat audioFormat, AcmEncoder audioEncoder)
 {
     IntPtr pwfx = audioFormat.ToPtr();
      try {
     Avi32Interop.AVISTREAMINFO asi = new Avi32Interop.AVISTREAMINFO();
     asi.fccType = Avi32Interop.streamtypeAUDIO;
     asi.dwScale = audioFormat.BlockAlign;
     asi.dwRate = audioFormat.AverageBytesPerSecond;
     asi.dwStart = 0;
     asi.dwLength = -1;
     asi.dwInitialFrames = 0;
     asi.dwSuggestedBufferSize = 0;
     asi.dwQuality = -1;
     asi.dwSampleSize = audioFormat.BlockAlign;
     int hr = Avi32Interop.AVIFileCreateStream(this.pAviFile, out this.pAudioStream, ref asi);
     if (hr != 0) {
        throw new AviException("AVIStreamSetFormat", hr);
     }
     hr = Avi32Interop.AVIStreamSetFormat(this.pAudioStream, 0, pwfx, audioFormat.ToalSize);
     if (hr != 0) {
        throw new AviException("AVIStreamSetFormat", hr);
     }
     if (audioEncoder != null) {
        audioEncoder.Open();
     }
     this.audioFormat = audioFormat;
     this.audioEncoder = audioEncoder;
      }
      finally {
     Marshal.FreeHGlobal(pwfx);
      }
 }
Exemplo n.º 4
0
 public void Close()
 {
     if (this.pAviCompressedStream != IntPtr.Zero) {
     Avi32Interop.AVIStreamRelease(this.pAviCompressedStream);
     this.pAviCompressedStream = IntPtr.Zero;
      }
      if (this.pVideoStream != IntPtr.Zero) {
     Avi32Interop.AVIStreamRelease(this.pVideoStream);
     this.pVideoStream = IntPtr.Zero;
      }
      if (this.pAudioStream != IntPtr.Zero) {
     Avi32Interop.AVIStreamRelease(this.pAudioStream);
     this.pAudioStream = IntPtr.Zero;
      }
      if (this.audioEncoder != null) {
     this.audioEncoder.Close();
     this.audioEncoder = null;
      }
      if (this.pAviFile != IntPtr.Zero) {
     Avi32Interop.AVIFileRelease(this.pAviFile);
     this.pAviFile = IntPtr.Zero;
      }
      this.opened = false;
 }