Non-realtime FFmpeg video recorder for offline rendering that accepts every frame immediately without time-based throttling.
README
ofxFfmpegRecorder2
Overview
Non-realtime video recorder using FFmpeg.
This addon is designed for offline/non-realtime rendering where frames are generated faster than realtime. Unlike ofxFFmpegRecorder, this class accepts every frame immediately without time-based throttling.
Key Differences from ofxFFmpegRecorder
1. NO TIME-BASED THROTTLING
- ofxFFmpegRecorder uses real-time clock to limit frame rate (lines 550-559)
- FfmpegRecorder accepts every frame immediately, allowing faster-than-realtime rendering
2. SIMPLIFIED API
- Focused on video-only recording (no audio support)
- Removed pause/resume functionality
- Cleaner setup with fewer parameters
3. BOUNDED QUEUE
- Uses a bounded queue (MAX_QUEUE_SIZE) to prevent memory overflow
- If queue fills up, frames are dropped with a warning
- ofxFFmpegRecorder uses an unbounded lock-free queue
4. EXPLICIT START/STOP
setup()configures parametersstart()begins recording and spawns writer threadstop()finalizes video and joins thread- ofxFFmpegRecorder starts the thread on first addFrame() call
Usage Example
ofPixels pixels;
pixels.allocate(1920, 1080, OF_PIXELS_RGBA);
FfmpegRecorder recorder;
recorder.setup(glm::vec2(1920, 1080), 30.0f, 8000, "/opt/homebrew/bin/ffmpeg");
recorder.setOutputPath("output.mp4");
recorder.setOverWrite(true);
recorder.start();
for (int i = 0; i < 300; i++) {
// Render frame as fast as possible
fbo.begin();
// ... draw content ...
fbo.end();
fbo.readToPixels(pixels);
recorder.addFrame(pixels); // Pixel format auto-detected from ofPixels type
}
recorder.stop(); // Finalizes the videoPixel Format Auto-Detection
The input pixel format is automatically detected based on the channel count:
OF_PIXELS_MONO(1 channel) โ "gray"OF_PIXELS_RGB(3 channels) โ "rgb24"OF_PIXELS_RGBA(4 channels) โ "rgba"
addFrame() call. You can still manually override it by calling setInputPixelFormat() before start() if needed.API Reference
Setup & Control
setup(glm::vec2 videoSize, float fps, unsigned int bitrate = 8000, const std::string &ffmpegPath = "ffmpeg", size_t maxQueueSize = 120)- Configure the recorderstart()- Start recordingstop()- Stop recording and finalize the video fileaddFrame(const ofPixels &pixels)- Add a frame to the recording queue
Setters
setOutputPath(const std::string &path)- Set the output file pathsetOverWrite(bool overwrite)- Enable/disable file overwritingsetVideoCodec(const std::string &codec)- Set the video codecsetInputPixelFormat(const std::string &format)- Manually set input pixel formatsetOutputPixelFormat(const std::string &format)- Set output pixel format
Getters
isRecording()- Check if currently recordinggetFramesQueued()- Get the number of frames that have been queuedgetFramesWritten()- Get the number of frames that have been written to diskgetQueueSize()- Get the current queue sizehasError()- Check if there was an error during recordinggetErrorMessage()- Get the last error messagegetOutputPath()- Get the output file pathgetVideoCodec()- Get the video codecgetFps()- Get the frame rategetVideoSize()- Get the video resolution
Requirements
- FFmpeg must be installed on your system
- Provide the path to the FFmpeg executable in the
setup()call
ofxAddons