public WebDriverRecorder(int fps) { this.fps = fps; if (Config.Settings.runTimeSettings.Browser == WebDriverBrowser.Browser.Android) { screensize = new Size(300, 500); } else { screensize = new Size(1024, 768); } frameDelayMs = 1000/fps; //Common.Log("The current dimensions are : " + screensize.Width + " x " + screensize.Height); video = new FlashScreenVideo(new FlashScreenVideoParameters(screensize.Width, screensize.Height, fps)); screenshotGetter = new BackgroundWorker(); screenshotGetter.DoWork += screenshotGetter_DoWork; screenshotGetter.WorkerSupportsCancellation = true; screenshotGetter.RunWorkerAsync(); videoBuilder = new BackgroundWorker(); videoBuilder.DoWork += videoBuilder_DoWork; videoBuilder.WorkerSupportsCancellation = true; videoBuilder.RunWorkerAsync(); }
public void CreateVideo() { const int width = 640; const int height = 480; const int frames = 30; Stopwatch stopwatch = Stopwatch.StartNew(); var parameters = new FlashScreenVideoParameters(width, height, 5) { BlockWidth = 256, BlockHeight = 256 }; video = new FlashScreenVideo(parameters); stopwatch.Stop(); Bitmap bitmap = new Bitmap(width, height); BitmapVideoFrame bitmapVideoFrame = new BitmapVideoFrame(bitmap); for (int frame = 0; frame < frames; frame++) { BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); try { int offset = 0; for (int y = 0; y < height; y++) { int scanOffset = offset; for (int x = 0; x < width; x++) { int color = (x * 255 / width) << 16 | (y * 255 / height) << 8 | frame * 255 / frames; Marshal.WriteInt32(bitmapData.Scan0, scanOffset, color); scanOffset += 4; } offset += bitmapData.Stride; } } finally { bitmap.UnlockBits(bitmapData); } stopwatch.Start(); video.AddFrame(bitmapVideoFrame); stopwatch.Stop(); } TestLog.WriteLine("Video encoding {2} frames at {0}x{1} took {3}s", width, height, frames, stopwatch.Elapsed.TotalSeconds); }