public void VideoWriterTest_CreateTestMP4File_640x480_24fps_15s() { VideoWriter videoWriter = new VideoWriter(); string TestOutputDirectoryQualified = Directory.GetCurrentDirectory() + "\\" + TestOutputFilesPath; if (!Directory.Exists(TestOutputDirectoryQualified)) { Directory.CreateDirectory(TestOutputDirectoryQualified); } videoWriter.Init(TestOutputDirectoryQualified + "\\" + MP4_FILENAME, VIDEO_WIDTH, VIDEO_HEIGHT, (int)VIDEO_FPS, 1, (int)VIDEO_ENCODE_BITRATE); var filepaths = Directory.EnumerateFiles(Directory.GetCurrentDirectory() + "\\" + DataFilesPath, "*.jpg", SearchOption.TopDirectoryOnly); DateTime dateTimeNow = DateTime.Now; long startTimeTicks = dateTimeNow.Ticks; do { foreach (string filepath in filepaths) { byte[] imagebitArray = GetImageByteArray(filepath); MemoryStream stream = new MemoryStream(imagebitArray); Bitmap image = (Bitmap)Image.FromStream(stream); //lets check if the image is what we expect if (image.PixelFormat != PixelFormat.Format24bppRgb) { string message = String.Format("Image format from is not correct. PixelFormat: {1}", image.PixelFormat); throw new Exception(message); } // Lock the bitmap's bits. Rectangle rect = new Rectangle(0, 0, image.Width, image.Height); BitmapData bmpData = image.LockBits(rect, ImageLockMode.ReadOnly, image.PixelFormat); // Get the address of the first line. IntPtr ptr = bmpData.Scan0; unsafe { videoWriter.AddFrame((byte *)ptr, 3*VIDEO_WIDTH*VIDEO_HEIGHT, VIDEO_WIDTH, VIDEO_HEIGHT, DateTime.Now.Ticks - startTimeTicks); } Thread.Sleep(new TimeSpan(0, 0, 0, 0, (int)(1000.0 / VIDEO_FPS))); image.UnlockBits(bmpData); } } while (TimeSpan.Compare(new TimeSpan(DateTime.Now.Ticks - startTimeTicks), new TimeSpan(0, 0, (int)((double)VIDEO_DURATION_IN_100_NS/10000000.0))) < 0); videoWriter.Done(); ValidateMP4OutputFile(TestOutputDirectoryQualified + "\\" + MP4_FILENAME); }
public void VideoWriterTest_CreateTestMP4File_640x480_24fps_15s() { VideoWriter videoWriter = new VideoWriter(); string TestOutputDirectoryQualified = Directory.GetCurrentDirectory() + "\\" + TestOutputFilesPath; if (!Directory.Exists(TestOutputDirectoryQualified)) { Directory.CreateDirectory(TestOutputDirectoryQualified); } videoWriter.Init(TestOutputDirectoryQualified + "\\" + MP4_FILENAME, VIDEO_WIDTH, VIDEO_HEIGHT, (int)VIDEO_FPS, 1, (int)VIDEO_ENCODE_BITRATE); var filepaths = Directory.EnumerateFiles(Directory.GetCurrentDirectory() + "\\" + DataFilesPath, "*.jpg", SearchOption.TopDirectoryOnly); DateTime dateTimeNow = DateTime.Now; long startTimeTicks = dateTimeNow.Ticks; do { foreach (string filepath in filepaths) { byte[] imagebitArray = GetImageByteArray(filepath); MemoryStream stream = new MemoryStream(imagebitArray); Bitmap image = (Bitmap)Image.FromStream(stream); //lets check if the image is what we expect if (image.PixelFormat != PixelFormat.Format24bppRgb) { string message = String.Format("Image format from is not correct. PixelFormat: {1}", image.PixelFormat); throw new Exception(message); } // Lock the bitmap's bits. Rectangle rect = new Rectangle(0, 0, image.Width, image.Height); BitmapData bmpData = image.LockBits(rect, ImageLockMode.ReadOnly, image.PixelFormat); // Get the address of the first line. IntPtr ptr = bmpData.Scan0; unsafe { videoWriter.AddFrame((byte *)ptr, 3 * VIDEO_WIDTH * VIDEO_HEIGHT, VIDEO_WIDTH, VIDEO_HEIGHT, DateTime.Now.Ticks - startTimeTicks); } Thread.Sleep(new TimeSpan(0, 0, 0, 0, (int)(1000.0 / VIDEO_FPS))); image.UnlockBits(bmpData); } } while (TimeSpan.Compare(new TimeSpan(DateTime.Now.Ticks - startTimeTicks), new TimeSpan(0, 0, (int)((double)VIDEO_DURATION_IN_100_NS / 10000000.0))) < 0); videoWriter.Done(); ValidateMP4OutputFile(TestOutputDirectoryQualified + "\\" + MP4_FILENAME); }
private void StopRecordingHelper(VideoWriter VideoWriter, string cameraName) { DateTime startTime = DateTime.Now; int hresult = VideoWriter.Done(); logger.Log("Stopping took {0} ms", (DateTime.Now - startTime).TotalMilliseconds.ToString()); if (hresult != 0) { string message = String.Format("Failed to stop recording for {0} at {1}. Error code = {2:x}", cameraName, DateTime.Now, (uint)hresult); logger.Log(message); } logger.Log("stopped recording for {0}", cameraName); }