JNGL
Easy to use cross-platform 2D game library
Loading...
Searching...
No Matches
Public Member Functions | List of all members
VideoRecorder Class Reference

Records video and audio output to a file. More...

#include <jngl/record/VideoRecorder.hpp>

Public Member Functions

 VideoRecorder (std::string_view filename)
 Creates a new video recorder that writes to the specified file (saved in your data/ directory).
 
 ~VideoRecorder () override
 Finalizes and closes the video file.
 
 VideoRecorder (const VideoRecorder &)=delete
 
VideoRecorderoperator= (const VideoRecorder &)=delete
 
 VideoRecorder (VideoRecorder &&)=delete
 
VideoRecorderoperator= (VideoRecorder &&)=delete
 
void fillAudioBuffer (std::unique_ptr< float[]> samples)
 Assumes 44.1 kHz, stereo audio input and getting called exactly getStepsPerSecond() times per second.
 
void step () override
 Advance the game logic.
 
void draw () const override
 Draw the game state.
 
- Public Member Functions inherited from Job
virtual void onFileDrop (const std::filesystem::path &)
 Called when a file has been dropped onto the window.
 
virtual void onControllersChanged ()
 Whenever the return value of jngl::getConnectedControllers would change, this method gets called.
 
 Job ()=default
 Does nothing.
 
 Job (const Job &)=default
 Copy constructor.
 
Joboperator= (const Job &)=default
 Copy assignment.
 
 Job (Job &&)=default
 Move constructor.
 
Joboperator= (Job &&)=default
 Move assignment.
 
virtual ~Job ()
 Does nothing.
 

Detailed Description

Records video and audio output to a file.

VideoRecorder is a background job that captures the rendered frames and audio samples to create a video file. It uses FFV1 codec for lossless video compression and FLAC for lossless audio compression, packaged in a Matroska container.

The recorder captures:

Note
Recording requires JNGL to be compiled with JNGL_RECORD enabled and FFmpeg libraries available.

Example usage:

#include <jngl.hpp>
#include <jngl/init.hpp>
#include <jngl/record/VideoRecorder.hpp>
params.start = []() {
// Start recording to output.mkv
jngl::addJob<jngl::VideoRecorder>("output.mkv");
// Your scene setup here...
};
return params;
}
Include this file only once, as it defines the main function.
jngl::AppParameters jnglInit()
Implement this function and set AppParameters::start.
Includes all JNGL headers except for init.hpp.
Parameters used to initialize the main window.
std::function< std::shared_ptr< jngl::Work >()> start
A factory function which creates the first jngl::Work.

The VideoRecorder will automatically capture frames and audio as your application runs. Remove the job or let it go out of scope to finalize and close the video file.

Warning
During recording, the game will run at a slower wall-clock speed to ensure no frames are dropped. The video encoding is synchronous and the application waits for each frame to be encoded before proceeding. This means the game runs slower in real-time but produces a smooth video at the target frame rate. Audio playback is muted during recording since the game is not running at normal speed.

Definition at line 48 of file VideoRecorder.hpp.

Inheritance diagram for VideoRecorder:
[legend]
Collaboration diagram for VideoRecorder:
[legend]

Constructor & Destructor Documentation

◆ VideoRecorder()

VideoRecorder ( std::string_view filename)
explicit

Creates a new video recorder that writes to the specified file (saved in your data/ directory).

Initializes video and audio encoding with the following settings:

Parameters
filenamePath to the output video file (typically with .mkv extension)
Exceptions
std::runtime_errorif video encoding setup fails (e.g., codecs not found, file cannot be opened)

◆ ~VideoRecorder()

~VideoRecorder ( )
override

Finalizes and closes the video file.

Flushes any remaining frames and audio data, writes the container trailer, and releases all encoding resources.

Member Function Documentation

◆ step()

void step ( )
overridevirtual

Advance the game logic.

This function gets called 60 times per second or whatever has been set by setStepsPerSecond().

Note
JNGL's main loop calls all Jobs' step() functions before the active Scene's step()

Implements Job.

◆ draw()

void draw ( ) const
overridevirtual

Draw the game state.

As it isn't garuanteed that this function is called as often as Job::step, you shouldn't change any game state in it.

Note
JNGL's main loop calls all Jobs' draw() functions after the active Scene's draw()

Implements Job.


The documentation for this class was generated from the following file: