From 5e47c018b2f8ea5dacb42a0bc3fdbabca361e5d2 Mon Sep 17 00:00:00 2001 From: Johxz Date: Sun, 1 Jan 2017 21:40:41 -0600 Subject: [PATCH] enable video recording --- .../game/core/scripts/client/screenshot.cs | 15 +++++++ .../Empty/game/scripts/client/default.bind.cs | 43 +++++++++++++++++++ .../game/core/scripts/client/screenshot.cs | 15 +++++++ .../Full/game/scripts/client/default.bind.cs | 43 +++++++++++++++++++ 4 files changed, 116 insertions(+) diff --git a/Templates/Empty/game/core/scripts/client/screenshot.cs b/Templates/Empty/game/core/scripts/client/screenshot.cs index 897325a1a..3c78aa2cd 100644 --- a/Templates/Empty/game/core/scripts/client/screenshot.cs +++ b/Templates/Empty/game/core/scripts/client/screenshot.cs @@ -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 @@ -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 diff --git a/Templates/Empty/game/scripts/client/default.bind.cs b/Templates/Empty/game/scripts/client/default.bind.cs index 51dc53d4b..b4216a33d 100644 --- a/Templates/Empty/game/scripts/client/default.bind.cs +++ b/Templates/Empty/game/scripts/client/default.bind.cs @@ -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 diff --git a/Templates/Full/game/core/scripts/client/screenshot.cs b/Templates/Full/game/core/scripts/client/screenshot.cs index 897325a1a..3c78aa2cd 100644 --- a/Templates/Full/game/core/scripts/client/screenshot.cs +++ b/Templates/Full/game/core/scripts/client/screenshot.cs @@ -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 @@ -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 diff --git a/Templates/Full/game/scripts/client/default.bind.cs b/Templates/Full/game/scripts/client/default.bind.cs index 1af881a81..ed804bbb2 100644 --- a/Templates/Full/game/scripts/client/default.bind.cs +++ b/Templates/Full/game/scripts/client/default.bind.cs @@ -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