The OpenD Programming Language

arsd.pixmaprecorder

Pixmap Recorder is an auxiliary library for rendering video files from Pixmap frames by piping them to FFmpeg.

Members

Classes

PixmapRecorder
class PixmapRecorder

Video file encoder

Detailed Description

Tips and tricks

The FFmpeg binary to be used can be specified by the optional constructor parameter ffmpegExecutablePath.

It defaults to ffmpeg; this will trigger the usual lookup procedures of the system the application runs on. On POSIX this usually means searching for FFmpeg in the directories specified by the environment variable PATH. On Windows it will also look for an executable file with that name in the current working directory.

The value of the outputFormat parameter of various constructor overloads is passed to FFmpeg via the -f (“format”) option.

Run ffmpeg -formats to get a list of available formats.

To pass additional options to FFmpeg, use the additional-output-args property.
Combining this module with Pixmap Presenter is really straightforward.

In the most simplistic case, set up a PixmapRecorder before running the presenter. Then call pixmapRecorder.record(presenter.framebuffer)

at the end of the drawing callback in the eventloop.

auto recorder = new PixmapRecorder(60, /* … */);
scope(exit) {
	const recorderStatus = recorder.stopRecording();
}

return presenter.eventLoop(delegate() {
	// […]
	recorder.record(presenter.framebuffer);
	return LoopCtrl.redrawIn(16);
});
To use this module with arsd.color (which includes the image file loading functionality provided by other arsd modules), convert the TrueColorImage or MemoryImage to a Pixmap first by calling Pixmap.fromTrueColorImage()

or Pixmap.fromMemoryImage()

respectively.

Examples

Getting started

  1. Install FFmpeg (the CLI version).
    • Debian derivatives (with FFmpeg in their repos): apt install ffmpeg
    • Homebew: brew install ffmpeg
    • Chocolatey: choco install ffmpeg
    • Links to pre-built binaries can be found on <https://ffmpeg.org/download.html>.
  2. Determine where you’ve installed FFmpeg to. Ideally, it’s somewhere within “PATH” so it can be run from the command-line by just doing ffmpeg. Otherwise, you’ll need the specific path to the executable to pass it to the constructor of PixmapRecorder.
import arsd.pixmaprecorder;
import arsd.pixmappaint;

/++
	This demo renders a 1280×720 video at 30 FPS
	fading from white (#FFF) to blue (#00F).
 +/
int main() {
	// Instantiate a recorder.
	auto recorder = new PixmapRecorder(
		30,        // Video framerate [=FPS]
		"out.mkv", // Output path to write the video file to.
	);

	// We will use this framebuffer later on to provide image data
	// to the encoder.
	auto frame = Pixmap(1280, 720);

	for (int light = 0xFF; light >= 0; --light) {
		auto color = Color(light, light, 0xFF);
		frame.clear(color);

		// Record the current frame.
		// The video resolution to use is derived from the first frame.
		recorder.put(frame);
	}

	// End and finalize the recording process.
	return recorder.stopRecording();
}

Meta