void IAviStreamWriteHandler.WriteStreamFormat(AviVideoStream videoStream) { fileWriter.Write(40U); // size of structure fileWriter.Write(videoStream.Width); fileWriter.Write(videoStream.Height); fileWriter.Write((short)1); // planes fileWriter.Write((ushort)videoStream.BitsPerPixel); // bits per pixel fileWriter.Write((uint)videoStream.Codec); // compression (codec FOURCC) var sizeInBytes = videoStream.Width * videoStream.Height * (((int)videoStream.BitsPerPixel) / 8); fileWriter.Write((uint)sizeInBytes); // image size in bytes fileWriter.Write(0); // X pixels per meter fileWriter.Write(0); // Y pixels per meter // Writing grayscale palette for 8-bit uncompressed stream // Otherwise, no palette if (videoStream.BitsPerPixel == BitsPerPixel.Bpp8 && videoStream.Codec == KnownFourCC.Codecs.Uncompressed) { fileWriter.Write(256U); // palette colors used fileWriter.Write(0U); // palette colors important for (int i = 0; i < 256; i++) { fileWriter.Write((byte)i); fileWriter.Write((byte)i); fileWriter.Write((byte)i); fileWriter.Write((byte)0); } } else { fileWriter.Write(0U); // palette colors used fileWriter.Write(0U); // palette colors important } }
public IAviVideoStream AddEncodingVideoStream(IVideoEncoder encoder, int width, int height, bool ownsEncoder) { return(AddStream <IAviVideoStreamInternal>(index => { var stream = new AviVideoStream(index, this, width, height, BitsPerPixel.Bpp32); var encodingStream = new EncodingVideoStreamWrapper(stream, encoder, ownsEncoder); var asyncStream = new AsyncVideoStreamWrapper(encodingStream); return asyncStream; })); }
void IAviStreamWriteHandler.WriteStreamHeader(AviVideoStream videoStream) { // See AVISTREAMHEADER structure fileWriter.Write((uint)videoStream.StreamType); fileWriter.Write((uint)videoStream.Codec); fileWriter.Write(0U); // StreamHeaderFlags fileWriter.Write((ushort)0); // priority fileWriter.Write((ushort)0); // language fileWriter.Write(0U); // initial frames fileWriter.Write(frameRateDenominator); // scale (frame rate denominator) fileWriter.Write(frameRateNumerator); // rate (frame rate numerator) fileWriter.Write(0U); // start fileWriter.Write((uint)streamsInfo[videoStream.Index].FrameCount); // length fileWriter.Write((uint)streamsInfo[videoStream.Index].MaxChunkDataSize); // suggested buffer size fileWriter.Write(0U); // quality fileWriter.Write(0U); // sample size fileWriter.Write((short)0); // rectangle left fileWriter.Write((short)0); // rectangle top short right = (short)(videoStream != null ? videoStream.Width : 0); short bottom = (short)(videoStream != null ? videoStream.Height : 0); fileWriter.Write(right); // rectangle right fileWriter.Write(bottom); // rectangle bottom }
void IAviStreamWriteHandler.WriteVideoFrame(AviVideoStream stream, bool isKeyFrame, byte[] frameData, int startIndex, int count) { WriteStreamFrame(stream, isKeyFrame, frameData, startIndex, count); }