private void Worker() { foreach (var c in canvasConfigs) { //Compile canvas FfmpegOutputProvider output = new FfmpegOutputProvider(); var canvas = new SpectrumVideoCanvas(c, output); //Start timer Stopwatch timer = new Stopwatch(); timer.Start(); //Loop while (!abort && canvas.TickFrame()) { //Set UI Invoke((MethodInvoker) delegate { statusText.Text = $"Rendering \"{canvas.Label}\"... ({canvas.ComputedFrames} of {canvas.TotalFrames} frames)"; statusRight.Text = SpectrumVideoUtils.EstimateTime(timer.Elapsed.Seconds, canvas.Progress) + " remaining"; statusBar.Maximum = (int)canvas.TotalFrames; statusBar.Value = canvas.ComputedFrames; }); } //Clean up canvas.Close(); canvas.Dispose(); //Check if we should abort if (abort) { break; } } //Done Invoke((MethodInvoker) delegate { exiting = true; DialogResult = abort ? DialogResult.Cancel : DialogResult.OK; Close(); }); }
private void PreviewWorker() { SpectrumVideoCanvas canvas = null; int frames = 0; Stopwatch timer = new Stopwatch(); while (previewRunning) { //If the config is not yet set, abort if (config == null) { Thread.Sleep(100); continue; } //Process try { //Update preview if needed if (previewInvalidated) { //Dispose of old bits canvas?.Dispose(); //Create new canvas statusString = "Creating..."; canvas = new SpectrumVideoCanvas(source, config, this); //Set flag timer.Restart(); frames = 0; previewInvalidated = false; } //If the canvas has no components, stop if (config.components.Count == 0) { statusString = "No components! Add one in the \"components\" section."; Thread.Sleep(100); continue; } //Tick canvas if (!canvas.TickFrame()) { source.PositionSamples = 0; //Reached end. Rewind } frames++; //Create status double timeSinceStart = timer.Elapsed.TotalSeconds; double progress = (double)frames / canvas.TotalFrames; statusString = $"{imageWidth}x{imageHeight}, {(frames / timeSinceStart).ToString("0.00")} FPS, {((frames / timeSinceStart) / imageFrameRate).ToString("0.00")}x, {SpectrumVideoUtils.FormatTime((long)(timeSinceStart / progress))} estimated time"; } catch (Exception ex) { //Notify of the error MessageBox.Show($"There's a problem with the canvas using the settings you've given: {ex.Message}\n\nThis error was thrown {ex.StackTrace}", "Canvas Problem", MessageBoxButtons.OK, MessageBoxIcon.Error); statusString = "Error with the canvas settings"; //Set flags previewError = true; config = null; } } //Stop canvas?.Dispose(); Dispose(); }