//public static CompressResult CompressIPframes(string iFreamFile, string pFrameFile, string outFile) //{ // var i = new Bitmap(iFreamFile); // var p = new Bitmap(pFrameFile); // var mpeg = new MPEG(i.Height, i.Width); // byte[][] ipframes = new byte[2][]; // ipframes[0] = mpeg.Compress(i, MPEG.FrameType.I); // ipframes[1] = mpeg.Compress(p, MPEG.FrameType.P); // // store to outFile // WriteCompressIPframes(outFile, new ImagesData(i.Height, i.Width, 1, ipframes)); // return new CompressResult(i.Height * i.Width * 6, ipframes[0].Length + ipframes[1].Length); //} //public static Bitmap[] DecompressIPframes(string inFile) //{ // ImagesData data = ReadCompressIPframes(inFile); // var mpeg = new MPEG(data.Height, data.Width); // var bms = new Bitmap[2]; // bms[0] = mpeg.Decompress(data.EncodedFrames[0], MPEG.FrameType.I); // bms[1] = mpeg.Decompress(data.EncodedFrames[1], MPEG.FrameType.P); // return bms; //} public static CompressResult CompressIPFrames(String[] framePaths, int iFrameGaps, String outPath) { if (framePaths == null || framePaths.Length < 1) { throw new Exception("must at least have 1 frame"); } int frameCount = framePaths.Length; Bitmap[] frames = new Bitmap[frameCount]; for (int i = 0; i < frameCount; ++i) { frames[i] = new Bitmap(framePaths[i]); } byte[][] encodedFrames = new byte[frameCount][]; int height = frames[0].Height, width = frames[0].Width; var mpeg = new MPEG(height, width); int compressSize = 0; for (int i = 0; i < frameCount; ++i) { if (i % iFrameGaps == 0) { encodedFrames[i] = mpeg.Compress(frames[i], MPEG.FrameType.I); } else { encodedFrames[i] = mpeg.Compress(frames[i], MPEG.FrameType.P); } compressSize += encodedFrames[i].Length; } WriteCompressIPframes(outPath, new ImagesData(height, width, iFrameGaps, encodedFrames)); return(new CompressResult(frames[0].Height * frames[0].Width * 3 * frames.Length, compressSize)); }
public static Bitmap[] DecompressIPFrames(string inFile) { ImagesData data = ReadCompressIPframes(inFile); int numOfFrames = data.EncodedFrames.Length; var bms = new Bitmap[numOfFrames]; var mpeg = new MPEG(data.Height, data.Width); for (int i = 0; i < numOfFrames; ++i) { if (i % data.IFrameGap == 0) { bms[i] = mpeg.Decompress(data.EncodedFrames[i], MPEG.FrameType.I); } else { bms[i] = mpeg.Decompress(data.EncodedFrames[i], MPEG.FrameType.P); } } return(bms); }