public void Write(string path) { if (!_ranPreview) { Preview(); } _aviWriter = new AVIWriter(path); // Set up the streams for the new file _needsTwoCC = new bool[_aviReader.StreamCount]; for (int i = 0; i < _aviReader.StreamCount; i++) { AVIStreamType streamType = _aviReader.GetStreamType(i); _aviWriter.AddStream(streamType); _aviWriter.SetStreamHeader(i, _aviReader.GetStreamHeader(i)); if (streamType == AVIStreamType.Video) { _aviWriter.SetStreamFormat(i, _aviReader.GetVideoStreamFormat(i)); } else if (streamType == AVIStreamType.Audio) { _aviWriter.SetStreamFormat(i, _aviReader.GetAudioStreamFormat(i)); } _aviWriter.SetStreamFormatExtra(i, _aviReader.GetStreamFormatExtra(i)); _aviWriter.SetStreamName(i, _aviReader.GetStreamName(i)); _needsTwoCC[i] = true; } try { Run(true); } catch { _aviWriter.Close(); File.Delete(path); throw; } _aviWriter.Close(); if (_wasStopped) { File.Delete(path); } }
private AVIWriter(string path, int codecID, List<string> warnings, bool isAlphaWriter) { if ((codecID != 2) && (codecID != 4) && (codecID != 5)) { throw new Exception("Unsupported video codec."); } FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read); _path = path; _bw = new BinaryWriter(fs); _codecID = codecID; _warnings = warnings; _isAlphaWriter = isAlphaWriter; if ((codecID == 5) && !_isAlphaWriter) { _alphaWriter = new AVIWriter(path.Substring(0, path.Length - 4) + ".alpha.avi", codecID, warnings, true); } WriteFourCC("RIFF"); _bw.Write((uint)0); // chunk size WriteFourCC("AVI "); WriteFourCC("LIST"); _bw.Write((uint)192); WriteFourCC("hdrl"); WriteFourCC("avih"); _bw.Write((uint)56); _bw.Write((uint)0); _bw.Write((uint)0); _bw.Write((uint)0); _bw.Write((uint)0x10); _bw.Write((uint)0); // frame count _bw.Write((uint)0); _bw.Write((uint)1); _bw.Write((uint)0); _bw.Write((uint)0); // width _bw.Write((uint)0); // height _bw.Write((uint)0); _bw.Write((uint)0); _bw.Write((uint)0); _bw.Write((uint)0); WriteFourCC("LIST"); _bw.Write((uint)116); WriteFourCC("strl"); WriteFourCC("strh"); _bw.Write((uint)56); WriteFourCC("vids"); WriteFourCC(CodecFourCC); _bw.Write((uint)0); _bw.Write((uint)0); _bw.Write((uint)0); _bw.Write((uint)0); // frame rate denominator _bw.Write((uint)0); // frame rate numerator _bw.Write((uint)0); _bw.Write((uint)0); // frame count _bw.Write((uint)0); _bw.Write((int)-1); _bw.Write((uint)0); _bw.Write((ushort)0); _bw.Write((ushort)0); _bw.Write((ushort)0); // width _bw.Write((ushort)0); // height WriteFourCC("strf"); _bw.Write((uint)40); _bw.Write((uint)40); _bw.Write((uint)0); // width _bw.Write((uint)0); // height _bw.Write((ushort)1); _bw.Write((ushort)24); WriteFourCC(CodecFourCC); _bw.Write((uint)0); // biSizeImage _bw.Write((uint)0); _bw.Write((uint)0); _bw.Write((uint)0); _bw.Write((uint)0); WriteFourCC("LIST"); _bw.Write((uint)0); // chunk size WriteFourCC("movi"); _index = new List<uint>(); }