|
JNGL
Easy to use cross-platform 2D game library
|
Records video and audio output to a file. More...
#include <jngl/record/VideoRecorder.hpp>
Public Member Functions | |
| VideoRecorder (std::string_view filename, bool lossless=false) | |
| 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 | |
| VideoRecorder & | operator= (const VideoRecorder &)=delete |
| VideoRecorder (VideoRecorder &&)=delete | |
| VideoRecorder & | operator= (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. | |
| Job & | operator= (const Job &)=default |
| Copy assignment. | |
| Job (Job &&)=default | |
| Move constructor. | |
| Job & | operator= (Job &&)=default |
| Move assignment. | |
| virtual | ~Job () |
| Does nothing. | |
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.
The recorder captures:
-DJNGL_RECORD=1 to CMake during configuration. On macOS, install FFmpeg with brew install ffmpeg.Example usage:
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.
The video container is chosen based on the file extension you provide. For example:
.mkv: Matroska container.mp4: MP4 containerBy default, lossy codecs are used (H.264 for video, AAC for audio) to produce reasonably sized files. If you want lossless quality, pass true for the lossless parameter when creating the VideoRecorder.
If you chose to use lossless, you would probably convert the resulting .mkv file to a compressed format later so you can upload it to Google Play or the Apple App Store. Use ffmpeg on the command line for that:
This command converts foo.mkv to output.mp4 using H.264 video codec and AAC audio codec.
Definition at line 78 of file VideoRecorder.hpp.
|
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 common settings:
| filename | Path to the output video file. Use appropriate file extension (e.g., .mkv, .mp4) to select the container format. |
| lossless | If true, uses lossless codecs (FFV1 for video, FLAC for audio). If false, uses lossy codecs (H.264 for video, AAC for audio). Default is false. |
| std::runtime_error | if video encoding setup fails (e.g., codecs not found, file cannot be opened) |
|
override |
Finalizes and closes the video file.
Flushes any remaining frames and audio data, writes the container trailer, and releases all encoding resources.
|
overridevirtual |
Advance the game logic.
This function gets called 60 times per second or whatever has been set by setStepsPerSecond().
Implements Job.
|
overridevirtual |