Skip to content

Commit

Permalink
Merge pull request GarageGames#1894 from John3/enableVideoRecording
Browse files Browse the repository at this point in the history
enable video recording
  • Loading branch information
Areloch committed Jan 31, 2017
2 parents ca4204b + 5e47c01 commit 8985cbb
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Templates/Empty/game/core/scripts/client/screenshot.cs
Expand Up @@ -55,6 +55,9 @@ function formatSessionNumber(%number)
// Records a movie file from the Canvas content using the specified fps.
// Possible encoder values are "PNG" and "THEORA" (default).
//---------------------------------------------------------------------------------------------

$RecordingMovie = false;

function recordMovie(%movieName, %fps, %encoder)
{
// If the canvas doesn't exist yet, setup a flag so it'll
Expand All @@ -65,12 +68,24 @@ function recordMovie(%movieName, %fps, %encoder)
if (%encoder $= "")
%encoder = "THEORA";
%resolution = Canvas.getVideoMode();

// Start the movie recording
ChatHud.AddLine( "\c4Recording movie file to [\c2" @ %movieName @ "\cr].ogv.");
echo("Recording movie to: " @ %movieName);
startVideoCapture(Canvas, %movieName, %encoder, %fps);

$RecordingMovie = true;
}

function stopMovie()
{
// Stop the current recording
ChatHud.AddLine( "\c4Recording movie file finished.");
echo("Stopped movie recording");

stopVideoCapture();

$RecordingMovie = false;
}

/// This is bound in initializeCommon() to take
Expand Down
43 changes: 43 additions & 0 deletions Templates/Empty/game/scripts/client/default.bind.cs
Expand Up @@ -409,6 +409,49 @@ function stopRecordingDemo( %val )
moveMap.bind( keyboard, F3, startRecordingDemo );
moveMap.bind( keyboard, F4, stopRecordingDemo );

//------------------------------------------------------------------------------
// Theora Video Capture (Records a movie file)
//------------------------------------------------------------------------------

function toggleMovieRecording(%val)
{
if (!%val)
return;

%movieEncodingType = "THEORA"; // Valid encoder values are "PNG" and "THEORA" (default).
%movieFPS = 30; // video capture frame rate.

if (!$RecordingMovie)
{
// locate a non-existent filename to use
for(%i = 0; %i < 1000; %i++)
{
%num = %i;
if(%num < 10)
%num = "0" @ %num;
if(%num < 100)
%num = "0" @ %num;

%filePath = "movies/movie" @ %num;
if(!isfile(%filePath))
break;
}
if(%i == 1000)
return;

// Start the movie recording
recordMovie(%filePath, %movieFPS, %movieEncodingType);

}
else
{
// Stop the current recording
stopMovie();
}
}

// Key binding works at any time and not just while in a game.
GlobalActionMap.bind(keyboard, "alt m", toggleMovieRecording);

//------------------------------------------------------------------------------
// Helper Functions
Expand Down
15 changes: 15 additions & 0 deletions Templates/Full/game/core/scripts/client/screenshot.cs
Expand Up @@ -55,6 +55,9 @@ function formatSessionNumber(%number)
// Records a movie file from the Canvas content using the specified fps.
// Possible encoder values are "PNG" and "THEORA" (default).
//---------------------------------------------------------------------------------------------

$RecordingMovie = false;

function recordMovie(%movieName, %fps, %encoder)
{
// If the canvas doesn't exist yet, setup a flag so it'll
Expand All @@ -65,12 +68,24 @@ function recordMovie(%movieName, %fps, %encoder)
if (%encoder $= "")
%encoder = "THEORA";
%resolution = Canvas.getVideoMode();

// Start the movie recording
ChatHud.AddLine( "\c4Recording movie file to [\c2" @ %movieName @ "\cr].ogv.");
echo("Recording movie to: " @ %movieName);
startVideoCapture(Canvas, %movieName, %encoder, %fps);

$RecordingMovie = true;
}

function stopMovie()
{
// Stop the current recording
ChatHud.AddLine( "\c4Recording movie file finished.");
echo("Stopped movie recording");

stopVideoCapture();

$RecordingMovie = false;
}

/// This is bound in initializeCommon() to take
Expand Down
43 changes: 43 additions & 0 deletions Templates/Full/game/scripts/client/default.bind.cs
Expand Up @@ -583,6 +583,49 @@ function stopRecordingDemo( %val )
moveMap.bind( keyboard, F3, startRecordingDemo );
moveMap.bind( keyboard, F4, stopRecordingDemo );

//------------------------------------------------------------------------------
// Theora Video Capture (Records a movie file)
//------------------------------------------------------------------------------

function toggleMovieRecording(%val)
{
if (!%val)
return;

%movieEncodingType = "THEORA"; // Valid encoder values are "PNG" and "THEORA" (default).
%movieFPS = 30; // video capture frame rate.

if (!$RecordingMovie)
{
// locate a non-existent filename to use
for(%i = 0; %i < 1000; %i++)
{
%num = %i;
if(%num < 10)
%num = "0" @ %num;
if(%num < 100)
%num = "0" @ %num;

%filePath = "movies/movie" @ %num;
if(!isfile(%filePath))
break;
}
if(%i == 1000)
return;

// Start the movie recording
recordMovie(%filePath, %movieFPS, %movieEncodingType);

}
else
{
// Stop the current recording
stopMovie();
}
}

// Key binding works at any time and not just while in a game.
GlobalActionMap.bind(keyboard, "alt m", toggleMovieRecording);

//------------------------------------------------------------------------------
// Helper Functions
Expand Down

0 comments on commit 8985cbb

Please sign in to comment.