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); var captureCamDriverEvery4Seconds = new SampleFilter(TimeSpan.FromSeconds(4), new LogCamDriver().Process); TraceDebug.WriteLine("Cameras:"); TraceDebug.WriteLine(TrackCameras.ToString()); ApplyFirstLapCameraDirection(samples, replayControl); samples = samples .VerifyReplayFrames() .WithCorrectedPercentages() .WithCorrectedDistances() .WithFastestLaps() .WithFinishingStatus() .WithPitStopCounts() .TakeUntil(3.Seconds()).Of(d => d.Telemetry.LeaderHasFinished && 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; overlayData.CapturedVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(); 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); captureCamDriverEvery4Seconds.Process(data, relativeTime); } var files = videoCapture.Deactivate(); removalEdits.Stop(); var overlayFile = SaveOverlayData(overlayData, files); //terminate iRacing after video capture completed try { //ToBe added: Option to select/deselect termination of iRacing after capturing video in new settings Dialog Process[] iRacingProc = Process.GetProcessesByName("iRacingSim64DX11"); iRacingProc[0].Kill(); } catch { throw new Exception("Could not terminate iRacing Simulator".F(workingFolder)); } 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); }
//Analyse race situations at maximum replay speed w/o recording. void AnalyseRaceSituations(IEnumerable <DataSample> samples) { int iReplaySpeedForAnalysis = (int)replaySpeeds.FF16x; //set speed for analysis phase to FF16x //Start iRacing Replay from the beginning with maximum speed (16x) iRacing.Replay.MoveToFrame(raceStartFrameNumber); //---------------------------- // copied from iRacing.Capturing because race events in app V1.0.x.x are identified during capturing the whole video. // necessity of classes in analysis phase to be reviewed //---------------------------- //var overlayData = new OverlayData(); removalEdits = new RemovalEdits(overlayData.RaceEvents); commentaryMessages = new CommentaryMessages(overlayData); recordPitStop = new RecordPitStop(commentaryMessages); fastestLaps = new RecordFastestLaps(overlayData); replayControl = new ReplayControl(samples.First().SessionData, incidents, removalEdits, TrackCameras); sessionDataCapture = new SessionDataCapture(overlayData); //CAPTURING LEADERBOARD, CAMERAS will be done at FF16x. TO BE DETERMINED WHETHER STANDARD INTERVALS HAVE TO BE REDUCED BY FACTOR OF 16?! captureLeaderBoardEveryHalfSecond = new SampleFilter(TimeSpan.FromSeconds(0.5), new CaptureLeaderBoard(overlayData, commentaryMessages, removalEdits).Process); captureCamDriverEveryQuaterSecond = new SampleFilter(TimeSpan.FromSeconds(0.25), new CaptureCamDriver(overlayData).Process); captureCamDriverEvery4Seconds = new SampleFilter(TimeSpan.FromSeconds(4), new LogCamDriver().Process); //---------------------------- //end copy / end review //---------------------------- ApplyFirstLapCameraDirection(samples, replayControl); samples = samples .VerifyReplayFrames() .WithCorrectedPercentages() .WithCorrectedDistances() .WithFastestLaps() .WithFinishingStatus() .WithPitStopCounts() .TakeUntil(3.Seconds()).Of(d => d.Telemetry.LeaderHasFinished && d.Telemetry.RaceCars.All(c => c.HasSeenCheckeredFlag || c.HasRetired || c.TrackSurface != TrackLocation.OnTrack)) .TakeUntil(3.Seconds()).AfterReplayPaused(); samples = samples.AtSpeed(iReplaySpeedForAnalysis); overlayData.CapturedVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(); ulong numberOfDataProcessed = 0; var startTime = DateTime.Now; foreach (var data in samples) { var relativeTime = (DateTime.Now - startTime).Multiply(iReplaySpeedForAnalysis); //calculate relative time in Replay taking into account replay speed (FF) 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); captureCamDriverEvery4Seconds.Process(data, relativeTime); numberOfDataProcessed += 1; } removalEdits.Stop(); TraceDebug.WriteLine("Race analysis phase completed. {0} data samples processed with replay speed {1}".F(numberOfDataProcessed, iReplaySpeedForAnalysis)); //save OverlayData into target folder for video ("working folder") SaveReplayScript(overlayData); TraceDebug.WriteLine("Replay Script saved to disk"); iRacing.Replay.SetSpeed(0); }
internal void _CaptureRaceTest(Action <string> onComplete, IEnumerable <DataSample> samples) { //identify wheather highlights video only is selected and OBS pause/resume can be used (to be implemented) if (bRecordUsingPauseResume) { //Retrieve list of raceEvents selected depending on the duration of the highlight video var totalRaceEvents = RaceEventExtension.GetInterestingRaceEvents(overlayData.RaceEvents.ToList()); ApplyFirstLapCameraDirection(samples, replayControl); //Record the selected race events into a highlight video raceVideo.Activate(workingFolder); //Active video-capturing and send start command to recording software. OverlayData.CamDriver curCamDriver = overlayData.CamDrivers.First(); //start thread to control / switch cameras while recording ReplayControl.cameraControl.ReplayCameraControlTask(overlayData); //ReplayControl.cameraControl.CameraOnDriver(short.Parse(curCamDriver.CurrentDriver.CarNumber), (short)curCamDriver.camGroupNumber); //cycle through all raceEvents selected for the highlight video and record them (REMARK: Camera switching not implemented yet) foreach (var raceEvent in totalRaceEvents) { TraceInfo.WriteLine("ADV_RECORDING: Type: {0} | Durations-Span: {1} | ".F(raceEvent.GetType(), raceEvent.Duration)); //jump to selected RaceEvent in iRacing Replay int framePositionInRace = raceStartFrameNumber + (int)Math.Round(raceEvent.StartTime * 60.0); iRacing.Replay.MoveToFrame(raceStartFrameNumber + (int)Math.Round(raceEvent.StartTime * 60.0)); iRacing.Replay.SetSpeed((int)replaySpeeds.normal); //start iRacing Replay at selected position raceVideo.Resume(); //resume recording TraceDebug.WriteLine("Recording Race-Event. Frame-Position: {0} | Duration: {1} ms".F(framePositionInRace, 1000 * raceEvent.Duration)); Thread.Sleep((int)(1000 * raceEvent.Duration)); //pause thread until scene is fully recorded. raceVideo.Pause(); //pause recording software before jumping to new position in iRacing Replay } TraceDebug.WriteLine("Video Capture of Race-Events completed"); raceVideo.Stop(); } else //Code to be removed after being able to implment working solution where analysis phase and replay-capture phase are distinct processes. //use local variables for original code instead of global variables introduced to support full analysis in analysis-phase { var overlayData = new OverlayData(); var removalEdits = new RemovalEdits(overlayData.RaceEvents); var commentaryMessages = new CommentaryMessages(overlayData); 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); var captureCamDriverEvery4Seconds = new SampleFilter(TimeSpan.FromSeconds(4), new LogCamDriver().Process); TraceDebug.WriteLine("Cameras:"); TraceDebug.WriteLine(TrackCameras.ToString()); var videoCapture = new VideoCapture(); ApplyFirstLapCameraDirection(samples, replayControl); samples = samples .VerifyReplayFrames() .WithCorrectedPercentages() .WithCorrectedDistances() .WithFastestLaps() .WithFinishingStatus() .WithPitStopCounts() .TakeUntil(3.Seconds()).Of(d => d.Telemetry.LeaderHasFinished && 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); //Start video capturing FileName will be given by recording software. var startTime = DateTime.Now; overlayData.CapturedVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(); foreach (var data in samples) { var relativeTime = DateTime.Now - startTime; TraceDebug.WriteLine("Recording at time: {0}", relativeTime); 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); captureCamDriverEvery4Seconds.Process(data, relativeTime); } var files = videoCapture.Deactivate(); //Stop video capturing - returns list with "guessed" filename. Filenmae being different from replay-script due to different time stamp. //investigate whether renaming of video file is necessary. 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); } //terminate iRacing after video capture completed to free up CPU resources if (bCloseiRacingAfterRecording) { try { //To be added: Option to select/deselect termination of iRacing after capturing video in new settings Dialog Process[] iRacingProc = Process.GetProcessesByName("iRacingSim64DX11"); iRacingProc[0].Kill(); } catch { throw new Exception("Could not terminate iRacing Simulator".F(workingFolder)); } } }