Skip to content

Commit

Permalink
First implemenation of Video capturing of race-events with Pause/Resu…
Browse files Browse the repository at this point in the history
…me. No Camera control implemented yet.
  • Loading branch information
MerlinCooper committed Jun 6, 2020
1 parent 39ae01c commit cde6db0
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 19 deletions.
2 changes: 2 additions & 0 deletions ClassDiagram3.cd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<ClassDiagram />
12 changes: 9 additions & 3 deletions Phases/CaptureOpeningScenes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@ namespace iRacingReplayOverlay.Phases
{
public partial class IRacingReplay
{
static private VideoCapture raceVideo = new VideoCapture();

void _CaptureOpeningScenes(Action onComplete)
{
if (bRecordUsingPauseResume)
{

}
var data = iRacing.GetDataFeed().First();
var session = data.SessionData.SessionInfo.Sessions.Qualifying();
if (session == null || session.ResultsPositions == null)
Expand Down Expand Up @@ -57,13 +63,13 @@ void _CaptureOpeningScenes(Action onComplete)
var aCar = data.SessionData.DriverInfo.CompetingDrivers[1].CarNumberRaw;
iRacing.Replay.CameraOnDriver((short)aCar, (short)scenicCameras);

var videoCapture = new VideoCapture();
//var videoCapture = new VideoCapture();

videoCapture.Activate(workingFolder);
raceVideo.Activate(workingFolder);

Thread.Sleep(shortTestOnly ? 5000 : 20000);

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

Expand Down
27 changes: 15 additions & 12 deletions Phases/CaptureRace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public partial class IRacingReplay
string workingFolder;
string introVideo;


void _WithWorkingFolder(string workingFolder)
{
this.workingFolder = workingFolder;
Expand Down Expand Up @@ -70,30 +71,32 @@ internal void _CaptureRaceTest(Action<string> onComplete, IEnumerable<DataSample
iRacing.Replay.SetSpeed((int)replaySpeeds.normal); //set replay speed to normal*/

//Record the selected race events into a highlight video
var highligtVideoCapture = new VideoCapture(); //create instance to control by sending hot-keys to recording software (tested with OBS)
highligtVideoCapture.Activate(workingFolder); //Start video capturing FileName will be given by recording software.
//var highligtVideoCapture = new VideoCapture(); //create instance to control by sending hot-keys to recording software (tested with OBS)
raceVideo.Activate(workingFolder); //Active video-capturing and send start command to recording software.

//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.ToString()));
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));

Thread.Sleep((int)(1000 * raceEvent.Duration)); //pause thread until scene is fully recorded.
iRacing.Replay.SetSpeed((int)replaySpeeds.normal); //start iRacing Replay at selected position

//pause recording software before jumping to new position in iRacing Replay
highligtVideoCapture.Pause();
raceVideo.Resume(); //resume recording



TraceDebug.WriteLine("Recording Race-Event. Frame-Position: {0} | Duration: {1} ms".F(framePositionInRace, 1000 * raceEvent.Duration));

highligtVideoCapture.Resume(); //resume recording

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

Expand Down
13 changes: 9 additions & 4 deletions Phases/Direction/VideoCapture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ public void Activate(string workingFolder, bool bStartRecording = true)
timer.AutoReset = false;
timer.Enabled = true;

if (bStartRecording && (curVideoStatus != videoStatus.running))
if (bStartRecording && (curVideoStatus == videoStatus.stopped))
{
SendKeyStroke_StartStopp(); //Send hot-key to start recording
curVideoStatus = videoStatus.running;
}else if( curVideoStatus == videoStatus.paused){
Resume();
}
}

Expand Down Expand Up @@ -89,7 +91,7 @@ private void CaptureNewFileNames(object sender, ElapsedEventArgs e)
}
}

public List<CapturedVideoFile> Deactivate()
public List<CapturedVideoFile> Deactivate(bool bRecordUsingPauseResume=false)
{
if (timer != null)
{
Expand All @@ -100,12 +102,15 @@ public List<CapturedVideoFile> Deactivate()

}

if( curVideoStatus != videoStatus.stopped)
if (bRecordUsingPauseResume && curVideoStatus != videoStatus.paused)
{
Pause();
curVideoStatus = videoStatus.paused;
} else
{
SendKeyStroke_StartStopp();
curVideoStatus = videoStatus.stopped;
}


System.Threading.Thread.Sleep(2000);

Expand Down
1 change: 1 addition & 0 deletions iRacingReplayDirector.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@
<ItemGroup>
<None Include="App.config" />
<None Include="ClassDiagram2.cd" />
<None Include="ClassDiagram3.cd" />
<None Include="DeploymentSite\.gitignore" />
<None Include="DeploymentSite\main.jsx" />
<None Include="DeploymentSite\package.json" />
Expand Down

0 comments on commit cde6db0

Please sign in to comment.