void _CaptureOpeningScenes(Action onComplete)
        {
            var data = iRacing.GetDataFeed().First();
            var session = data.SessionData.SessionInfo.Sessions.Qualifying();
            if (session == null || session.ResultsPositions == null)
                return;

            if (!iRacing.Replay.AttempToMoveToQualifyingSection())
                return;
            
            data = iRacing.GetDataFeed().First();
            var f = data.Telemetry.ReplayFrameNum;
            iRacing.Replay.MoveToFrame(f + 60 * 4, ReplayPositionMode.Begin, 100);
            iRacing.Replay.SetSpeed(1);

            var camera = data.SessionData.CameraInfo.Groups.FirstOrDefault( c => c.GroupName == "Scenic");
            if( camera == null )
                camera = data.SessionData.CameraInfo.Groups.FirstOrDefault( c => c.GroupName == "Pit Lane 2");
            if( camera == null )
                camera = data.SessionData.CameraInfo.Groups.FirstOrDefault( c => c.GroupName == "Chopper");
            if( camera == null)
                camera = data.SessionData.CameraInfo.Groups.FirstOrDefault( c => c.GroupName == "TV3");
            if( camera == null)
                throw new Exception("Cant find a camera to use for pre-race capture");

            var scenicCameras = camera.GroupNum;
            var aCar = data.SessionData.DriverInfo.CompetingDrivers[1].CarNumberRaw;
            iRacing.Replay.CameraOnDriver((short)aCar, (short)scenicCameras);

            var videoCapture = new VideoCapture();

            videoCapture.Activate(workingFolder);

            Thread.Sleep(shortTestOnly ? 5000 : 20000);

            var fileNames = videoCapture.Deactivate();
            if( fileNames.Count == 0)
                return;

            TraceInfo.WriteLine("Captured intro video into file {0}", fileNames[0]);
            _WithIntroVideo(fileNames[0].FileName);
        }
        void RunTest(string workingFolder, SynchronizationContext context)
        {
            try
            {
                TraceInfo.WriteLine("Switching to iRacing ....");
                 
                var hwnd = Win32.Messages.FindWindow(null, "iRacing.com Simulator");
                Win32.Messages.ShowWindow(hwnd, Win32.Messages.SW_SHOWNORMAL);
                Win32.Messages.SetForegroundWindow(hwnd);
                Thread.Sleep(2000);

                TraceInfo.WriteLine("Begining Test....");
                var videoCapture = new VideoCapture();

                TraceInfo.WriteLine("Broadcasting keypress ALT+F9 to activate your video capture software");
                videoCapture.Activate(workingFolder);

                TraceInfo.WriteLine("Expecting video file to be written in folder: {0}", workingFolder);

                TraceInfo.WriteLine("Waiting for 5 seconds");

                for (var i = 5; i >= 0; i--)
                {
                    Thread.Sleep(1.Seconds());
                    TraceInfo.WriteLine("{0} Seconds...", i);
                }

                TraceInfo.WriteLine("Broadcasting keypress ALT+F9 to deactivate your video capture software");
                var filenames = videoCapture.Deactivate();


                TraceInfo.WriteLine("Minimising iRacing");

                AltTabBackToApp();

                if (filenames.Count == 0)
                {
                    TraceInfo.WriteLine("\nFailure - Did not find any video files");
                    return;
                }

                if (filenames.Count != 1)
                {
                    TraceInfo.WriteLine("\nFailure - Found more than 1 video file!");
                    return;
                }

                var filename = filenames[0];

                if (filename != null)
                {
                    TraceInfo.WriteLine("");
                    TraceInfo.WriteLine("Found your video file {0}.", filename);

                    TranscodeVideoTest(filename.FileName);
                }
                else
                {
                    TraceInfo.WriteLine("");
                    TraceInfo.WriteLine("Failure!");
                }
            }
            catch(Exception e)
            {
                TraceInfo.WriteLine(e.Message);
                Trace.WriteLine(e.StackTrace, "DEBUG");
            }
            finally
            {
                context.Post(ignored => testVideoCaptureButton.Enabled = true, null);
            }
        }
        internal void _CaptureRaceTest(Action<string> onComplete, IEnumerable<DataSample> samples)
        {
            var overlayData = new OverlayData();
            var removalEdits = new RemovalEdits(overlayData.RaceEvents);
            var commentaryMessages = new CommentaryMessages(overlayData);
            var videoCapture = new VideoCapture();
            var recordPitStop = new RecordPitStop(commentaryMessages);
            var fastestLaps = new RecordFastestLaps(overlayData);
            var replayControl = new ReplayControl(samples.First().SessionData, incidents, removalEdits, TrackCameras);
            var sessionDataCapture = new SessionDataCapture(overlayData);
            var captureLeaderBoardEveryHalfSecond = new SampleFilter(TimeSpan.FromSeconds(0.5),
                new CaptureLeaderBoard(overlayData, commentaryMessages, removalEdits).Process);
            var captureCamDriverEveryQuaterSecond = new SampleFilter(TimeSpan.FromSeconds(0.25),
                 new CaptureCamDriver(overlayData).Process);

            ApplyFirstLapCameraDirection(samples, replayControl);

            samples = samples
                .VerifyReplayFrames()
                .WithCorrectedPercentages()
                .WithCorrectedDistances()
                .WithFastestLaps()
                .WithFinishingStatus()
                .WithPitStopCounts()
                .TakeUntil(3.Seconds()).After(d => d.Telemetry.RaceCars.All(c => c.HasSeenCheckeredFlag || c.HasRetired || c.TrackSurface != TrackLocation.OnTrack))
                .TakeUntil(3.Seconds()).AfterReplayPaused();
            
            if (shortTestOnly)
            {
                samples = samples.AtSpeed(Settings.Default.TimingFactorForShortTest);
                Settings.AppliedTimingFactor = 1.0 / Settings.Default.TimingFactorForShortTest;
            }

            videoCapture.Activate(workingFolder);
            var startTime = DateTime.Now;

            foreach (var data in samples)
            {
                var relativeTime = DateTime.Now - startTime;

                replayControl.Process(data);
                sessionDataCapture.Process(data);
                captureLeaderBoardEveryHalfSecond.Process(data, relativeTime);
                captureCamDriverEveryQuaterSecond.Process(data, relativeTime);
                recordPitStop.Process(data, relativeTime);
                fastestLaps.Process(data, relativeTime);
                removalEdits.Process(data, relativeTime);
            }

            var files = videoCapture.Deactivate();

            removalEdits.Stop();

            var overlayFile = SaveOverlayData(overlayData, files);

            iRacing.Replay.SetSpeed(0);

            AltTabBackToApp();

            if (files.Count == 0)
                throw new Exception("Unable to find video files in '{0}' - possible wrong working folder".F(workingFolder));
            
            _WithOverlayFile(overlayFile);

            onComplete(overlayFile);
        }