/* finish writing the AVI file - filling in the header */ public void avi_end(int width, int height, int fps) { this.width = width; this.height = height; lock (locker) { targetfps = fps; } riff_head rh = new riff_head { riff = "RIFF".ToCharArray(), size = 0, avistr = "AVI ".ToCharArray() }; list_head lh1 = new list_head { list = "LIST".ToCharArray(), size = 0, type = "hdrl".ToCharArray() }; avi_head ah = new avi_head(); list_head lh2 = new list_head { list = "LIST".ToCharArray(), size = 0, type = "strl".ToCharArray() }; stream_head sh = new stream_head(); frame_head fh = new frame_head(); list_head junk = new list_head() { list = "JUNK".ToCharArray(), size = 0 }; list_head lh3 = new list_head { list = "LIST".ToCharArray(), size = 0, type = "movi".ToCharArray() }; //bzero(&ah, sizeof(ah)); strcpy(ref ah.avih, "avih"); ah.time = (u32)(1e6 / fps); ah.numstreams = 1; //ah.scale = (u32)(1e6 / fps); //ah.rate = (u32)fps; //ah.length = (u32)(nframes); ah.nframes = (u32)(nframes); ah.width = (u32)width; ah.height = (u32)height; ah.flags = 0x10; ah.suggested_bufsize = 0; ah.maxbytespersec = (u32)(3 * width * height * fps); //bzero(&sh, sizeof(sh)); strcpy(ref sh.strh, "strh"); strcpy(ref sh.vids, "vids"); strcpy(ref sh.codec, "MJPG"); sh.scale = (u32)1; sh.rate = (u32)fps; sh.length = (u32)(nframes); sh.suggested_bufsize = (u32)(3 * width * height * fps); unchecked { sh.quality = (uint)-1; } sh.r = (short)width; sh.b = (short)height; //bzero(&fh, sizeof(fh)); strcpy(ref fh.strf, "strf"); fh.width = width; fh.height = height; fh.planes = 1; fh.bitcount = 24; strcpy(ref fh.codec, "MJPG"); fh.unpackedsize = (u32)(3 * width * height); uint indexlength = (uint)(indexs.Count * 16) + 8; // header as well rh.size = (u32)(Marshal.SizeOf(lh1) + Marshal.SizeOf(ah) + Marshal.SizeOf(lh2) + Marshal.SizeOf(sh) + Marshal.SizeOf(fh) + Marshal.SizeOf(lh3) + //); // 212 nframes * Marshal.SizeOf((new db_head())) + totalsize + indexlength + 7980); // needs junk length + list movi header lh1.size = (u32)(4 + Marshal.SizeOf(ah) + Marshal.SizeOf(lh2) + Marshal.SizeOf(sh) + Marshal.SizeOf(fh)); ah.size = (u32)(Marshal.SizeOf(ah) - 8); lh2.size = (u32)(4 + Marshal.SizeOf(sh) + Marshal.SizeOf(fh)); sh.size = (u32)(Marshal.SizeOf(sh) - 8); fh.size = (u32)(Marshal.SizeOf(fh) - 8); fh.size2 = fh.size; lh3.size = (u32)(4 + nframes * Marshal.SizeOf((new db_head())) + totalsize); junk.size = 8204 - lh1.size - 12 - 12 - 12 - 4; // junk head, list head, rif head , 4 long pos = fd.Position; fd.Seek(0, SeekOrigin.Begin); fd.Write(StructureToByteArray(rh), 0, Marshal.SizeOf(rh)); fd.Write(StructureToByteArray(lh1), 0, Marshal.SizeOf(lh1)); fd.Write(StructureToByteArray(ah), 0, Marshal.SizeOf(ah)); fd.Write(StructureToByteArray(lh2), 0, Marshal.SizeOf(lh2)); fd.Write(StructureToByteArray(sh), 0, Marshal.SizeOf(sh)); fd.Write(StructureToByteArray(fh), 0, Marshal.SizeOf(fh)); fd.Write(StructureToByteArray(junk), 0, Marshal.SizeOf(junk)); fd.Seek(8192, SeekOrigin.Begin); fd.Write(StructureToByteArray(lh3), 0, Marshal.SizeOf(lh3)); fd.Seek(pos, SeekOrigin.Begin); }
/* finish writing the AVI file - filling in the header */ public void avi_end(int width, int height, int fps) { riff_head rh = new riff_head { riff = "RIFF".ToCharArray(), size = 0, avistr = "AVI ".ToCharArray() }; list_head lh1 = new list_head { list = "LIST".ToCharArray(), size = 0, type = "hdrl".ToCharArray() }; avi_head ah = new avi_head(); list_head lh2 = new list_head { list = "LIST".ToCharArray(), size = 0, type = "strl".ToCharArray() }; stream_head sh = new stream_head(); frame_head fh = new frame_head(); list_head junk = new list_head() { list = "JUNK".ToCharArray(), size = 0 }; list_head lh3 = new list_head { list = "LIST".ToCharArray(), size = 0, type = "movi".ToCharArray() }; //bzero(&ah, sizeof(ah)); strcpy(ref ah.avih, "avih"); ah.time = (u32)(1e6 / fps); ah.numstreams = 1; //ah.scale = (u32)(1e6 / fps); //ah.rate = (u32)fps; //ah.length = (u32)(nframes); ah.nframes = (u32)(nframes); ah.width = (u32)width; ah.height = (u32)height; ah.flags = 0; ah.suggested_bufsize = (u32)(3 * width * height * fps); ah.maxbytespersec = (u32)(3 * width * height * fps); //bzero(&sh, sizeof(sh)); strcpy(ref sh.strh, "strh"); strcpy(ref sh.vids, "vids"); strcpy(ref sh.codec, "MJPG"); sh.scale = (u32)(1e6 / fps); sh.rate = (u32)1000000; sh.length = (u32)(nframes); sh.suggested_bufsize = (u32)(3 * width * height * fps); unchecked { sh.quality = (uint)-1; } //bzero(&fh, sizeof(fh)); strcpy(ref fh.strf, "strf"); fh.width = width; fh.height = height; fh.planes = 1; fh.bitcount = 24; strcpy(ref fh.codec, "MJPG"); fh.unpackedsize = (u32)(3 * width * height); rh.size = (u32)(Marshal.SizeOf(lh1) + Marshal.SizeOf(ah) + Marshal.SizeOf(lh2) + Marshal.SizeOf(sh) + Marshal.SizeOf(fh) + Marshal.SizeOf(lh3) + nframes * Marshal.SizeOf((new db_head())) + totalsize); lh1.size = (u32)(4 + Marshal.SizeOf(ah) + Marshal.SizeOf(lh2) + Marshal.SizeOf(sh) + Marshal.SizeOf(fh)); ah.size = (u32)(Marshal.SizeOf(ah) - 8); lh2.size = (u32)(4 + Marshal.SizeOf(sh) + Marshal.SizeOf(fh)); sh.size = (u32)(Marshal.SizeOf(sh) - 8); fh.size = (u32)(Marshal.SizeOf(fh) - 8); fh.size2 = fh.size; lh3.size = (u32)(4 + nframes * Marshal.SizeOf((new db_head())) + totalsize); junk.size = 2048 - lh1.size - 12 - 12 - 12 - 4; // junk head, list head, rif head , 4 long pos = fd.Position; fd.Seek(0, SeekOrigin.Begin); fd.Write(StructureToByteArray(rh),0, Marshal.SizeOf(rh)); fd.Write(StructureToByteArray(lh1), 0, Marshal.SizeOf(lh1)); fd.Write(StructureToByteArray(ah), 0, Marshal.SizeOf(ah)); fd.Write(StructureToByteArray(lh2), 0, Marshal.SizeOf(lh2)); fd.Write(StructureToByteArray(sh), 0, Marshal.SizeOf(sh)); fd.Write(StructureToByteArray(fh), 0, Marshal.SizeOf(fh)); fd.Write(StructureToByteArray(junk), 0, Marshal.SizeOf(junk)); fd.Seek(2036, SeekOrigin.Begin); fd.Write(StructureToByteArray(lh3), 0, Marshal.SizeOf(lh3)); fd.Seek(pos, SeekOrigin.Begin); }
/* finish writing the AVI file - filling in the header */ public void avi_end(int width, int height, int fps) { riff_head rh = new riff_head { riff = "RIFF".ToCharArray(), size = 0, avistr = "AVI ".ToCharArray() }; list_head lh1 = new list_head { list = "LIST".ToCharArray(), size = 0, type = "hdrl".ToCharArray() }; avi_head ah = new avi_head(); list_head lh2 = new list_head { list = "LIST".ToCharArray(), size = 0, type = "strl".ToCharArray() }; stream_head sh = new stream_head(); frame_head fh = new frame_head(); list_head lh3 = new list_head { list = "LIST".ToCharArray(), size = 0, type = "movi".ToCharArray() }; if (fps <= 0) { fps = (int)(nframes / ((float)(DateTime.Now.Ticks - start_timestamp) / TimeSpan.TicksPerSecond)); } //bzero(&ah, sizeof(ah)); strcpy(ref ah.avih, "avih"); ah.time = (u32)(1e6 / fps); ah.numstreams = 1; //ah.scale = (u32)(1e6 / fps); //ah.rate = (u32)fps; //ah.length = (u32)(nframes); ah.nframes = (u32)(nframes); ah.width = (u32)width; ah.height = (u32)height; ah.flags = 0; ah.suggested_bufsize = (u32)max_buff_size;// Rafa (u32)(3 * width * height * fps); ah.maxbytespersec = (u32)0; // Rafa (3 * width * height * fps); //bzero(&sh, sizeof(sh)); strcpy(ref sh.strh, "strh"); strcpy(ref sh.vids, "vids"); strcpy(ref sh.codec, "MJPG"); sh.scale = (u32)1; //Rafa (1e6 / fps); sh.rate = (u32)fps; // RAFA fps 1000000; sh.length = (u32)(nframes); sh.suggested_bufsize = max_buff_size;// Rafa (u32)(3 * width * height * fps); sh.r = (short)width; sh.b = (short)height; unchecked { sh.quality = (uint)-1; } //bzero(&fh, sizeof(fh)); strcpy(ref fh.strf, "strf"); fh.width = width; fh.height = height; fh.planes = 1; fh.bitcount = 24; strcpy(ref fh.codec, "MJPG"); fh.unpackedsize = (u32)(3 * width * height); /* rh.size = (u32)(Marshal.SizeOf(lh1) + Marshal.SizeOf(ah) + Marshal.SizeOf(lh2) + Marshal.SizeOf(sh) + Marshal.SizeOf(fh) + Marshal.SizeOf(lh3) + nframes * Marshal.SizeOf((new db_head())) + 4 + //rafa +4 totalsize); */ rh.size = 240 + totalsize; lh1.size = (u32)(4 + Marshal.SizeOf(ah) + Marshal.SizeOf(lh2) + Marshal.SizeOf(sh) + Marshal.SizeOf(fh)); ah.size = (u32)(Marshal.SizeOf(ah) - 8); lh2.size = (u32)(4 + Marshal.SizeOf(sh) + Marshal.SizeOf(fh)); sh.size = (u32)(Marshal.SizeOf(sh) - 8); fh.size = (u32)(Marshal.SizeOf(fh) - 8); fh.size2 = fh.size; lh3.size = (u32)(4 + nframes * Marshal.SizeOf((new db_head())) + totalsize); long pos = fd.Position; current_lenght = pos; fd.Seek(0, SeekOrigin.Begin); fd.Write(StructureToByteArray(rh), 0, Marshal.SizeOf(rh)); fd.Write(StructureToByteArray(lh1), 0, Marshal.SizeOf(lh1)); fd.Write(StructureToByteArray(ah), 0, Marshal.SizeOf(ah)); fd.Write(StructureToByteArray(lh2), 0, Marshal.SizeOf(lh2)); fd.Write(StructureToByteArray(sh), 0, Marshal.SizeOf(sh)); fd.Write(StructureToByteArray(fh), 0, Marshal.SizeOf(fh)); fd.Seek(224-12, SeekOrigin.Begin); fd.Write(StructureToByteArray(lh3), 0, Marshal.SizeOf(lh3)); fd.Seek(pos, SeekOrigin.Begin); }
/* finish writing the AVI file - filling in the header */ public void avi_end(int width, int height, int fps) { riff_head rh = new riff_head { riff = "RIFF".ToCharArray(), size = 0, avistr = "AVI ".ToCharArray() }; list_head lh1 = new list_head { list = "LIST".ToCharArray(), size = 0, type = "hdrl".ToCharArray() }; avi_head ah = new avi_head(); list_head lh2 = new list_head { list = "LIST".ToCharArray(), size = 0, type = "strl".ToCharArray() }; stream_head sh = new stream_head(); frame_head fh = new frame_head(); list_head lh3 = new list_head { list = "LIST".ToCharArray(), size = 0, type = "movi".ToCharArray() }; if (fps <= 0) { fps = (int)(nframes / ((float)(DateTime.Now.Ticks - start_timestamp) / TimeSpan.TicksPerSecond)); } //bzero(&ah, sizeof(ah)); strcpy(ref ah.avih, "avih"); ah.time = (u32)(1e6 / fps); ah.numstreams = 1; //ah.scale = (u32)(1e6 / fps); //ah.rate = (u32)fps; //ah.length = (u32)(nframes); ah.nframes = (u32)(nframes); ah.width = (u32)width; ah.height = (u32)height; ah.flags = 0; ah.suggested_bufsize = (u32)max_buff_size; // Rafa (u32)(3 * width * height * fps); ah.maxbytespersec = (u32)0; // Rafa (3 * width * height * fps); //bzero(&sh, sizeof(sh)); strcpy(ref sh.strh, "strh"); strcpy(ref sh.vids, "vids"); strcpy(ref sh.codec, "MJPG"); sh.scale = (u32)1; //Rafa (1e6 / fps); sh.rate = (u32)fps; // RAFA fps 1000000; sh.length = (u32)(nframes); sh.suggested_bufsize = max_buff_size; // Rafa (u32)(3 * width * height * fps); sh.r = (short)width; sh.b = (short)height; unchecked { sh.quality = (uint)-1; } //bzero(&fh, sizeof(fh)); strcpy(ref fh.strf, "strf"); fh.width = width; fh.height = height; fh.planes = 1; fh.bitcount = 24; strcpy(ref fh.codec, "MJPG"); fh.unpackedsize = (u32)(3 * width * height); /* * rh.size = (u32)(Marshal.SizeOf(lh1) + Marshal.SizeOf(ah) + Marshal.SizeOf(lh2) + Marshal.SizeOf(sh) + * Marshal.SizeOf(fh) + Marshal.SizeOf(lh3) + * nframes * Marshal.SizeOf((new db_head())) + 4 + //rafa +4 * totalsize); */ rh.size = 240 + totalsize; lh1.size = (u32)(4 + Marshal.SizeOf(ah) + Marshal.SizeOf(lh2) + Marshal.SizeOf(sh) + Marshal.SizeOf(fh)); ah.size = (u32)(Marshal.SizeOf(ah) - 8); lh2.size = (u32)(4 + Marshal.SizeOf(sh) + Marshal.SizeOf(fh)); sh.size = (u32)(Marshal.SizeOf(sh) - 8); fh.size = (u32)(Marshal.SizeOf(fh) - 8); fh.size2 = fh.size; lh3.size = (u32)(4 + nframes * Marshal.SizeOf((new db_head())) + totalsize); long pos = fd.Position; current_lenght = pos; fd.Seek(0, SeekOrigin.Begin); fd.Write(StructureToByteArray(rh), 0, Marshal.SizeOf(rh)); fd.Write(StructureToByteArray(lh1), 0, Marshal.SizeOf(lh1)); fd.Write(StructureToByteArray(ah), 0, Marshal.SizeOf(ah)); fd.Write(StructureToByteArray(lh2), 0, Marshal.SizeOf(lh2)); fd.Write(StructureToByteArray(sh), 0, Marshal.SizeOf(sh)); fd.Write(StructureToByteArray(fh), 0, Marshal.SizeOf(fh)); fd.Seek(224 - 12, SeekOrigin.Begin); fd.Write(StructureToByteArray(lh3), 0, Marshal.SizeOf(lh3)); fd.Seek(pos, SeekOrigin.Begin); }