Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitk::VideoRecorder Class Reference

Record the contents of a render window as video using FFmpeg as external command-line application. More...

#include <mitkVideoRecorder.h>

Public Types

enum class  OutputFormat { WebM_VP9 , MP4_H264 }
 

Public Member Functions

 VideoRecorder ()
 
 ~VideoRecorder ()
 
 VideoRecorder (const VideoRecorder &)=delete
 
VideoRecorder & operator= (const VideoRecorder &)=delete
 
fs::path GetFFmpegPath () const
 Get the path to the FFmpeg executable. More...
 
void SetFFmpegPath (const fs::path &path)
 Set the path to the FFmpeg executable. More...
 
fs::path GetOutputPath () const
 Get the path to the output video file. More...
 
void SetOutputPath (const fs::path &path)
 Set the path for the output video file. More...
 
OutputFormat GetOutputFormat () const
 Get the output format (codec/container). More...
 
void SetOutputFormat (OutputFormat format)
 Set the output format (codec/container). More...
 
std::string GetRenderWindowName () const
 Get the name of the render window being recorded. More...
 
void SetRenderWindowName (const std::string &renderWindowName)
 Set the name of the render window to record. More...
 
int GetFrameRate () const
 Get the recording frame rate. More...
 
void SetFrameRate (unsigned int fps)
 Set the recording frame rate. More...
 
void StartRecording ()
 Begin a recording session. More...
 
void RecordFrame () const
 Record the current frame of the render window. More...
 
int StopRecording ()
 Stop the recording session and encode the video. More...
 

Static Public Member Functions

static std::string GetFileExtension (OutputFormat format)
 Get the file extension corresponding to the specified video output format. More...
 

Detailed Description

Record the contents of a render window as video using FFmpeg as external command-line application.

Before recording, set the render window, the path to FFmpeg, the path to the video output file, its format/codec, and frame rate.

Most settings have decent defaults, e.g., the royalty-free and open VP9 video codec in a WebM container as output format and a frame rate of 30 frames per second.

If not set explicitly, the FFmpeg path and output format are queried from the preferences, if available.

Call StartRecording() to begin a recording session, record each frame with RecordFrame(), and end the recording session with a call to StopRecording(). StopRecording() is a blocking call that may take a long time to return since it calls FFmpeg to encode the recorded frames into a video. Consider calling it from a separate thread.

The VideoRecorder throws an Exception on any error. It is advised to use it within a try/catch block.

Definition at line 40 of file mitkVideoRecorder.h.

Member Enumeration Documentation

◆ OutputFormat

Enumerator
WebM_VP9 
MP4_H264 

Definition at line 43 of file mitkVideoRecorder.h.

Constructor & Destructor Documentation

◆ VideoRecorder() [1/2]

mitk::VideoRecorder::VideoRecorder ( )

◆ ~VideoRecorder()

mitk::VideoRecorder::~VideoRecorder ( )

◆ VideoRecorder() [2/2]

mitk::VideoRecorder::VideoRecorder ( const VideoRecorder &  )
delete

Member Function Documentation

◆ GetFFmpegPath()

fs::path mitk::VideoRecorder::GetFFmpegPath ( ) const

Get the path to the FFmpeg executable.

If not set explicitly, the path is read from the user preferences.

Returns
The path to FFmpeg, or an empty path if not configured.

◆ GetFileExtension()

static std::string mitk::VideoRecorder::GetFileExtension ( OutputFormat  format)
static

Get the file extension corresponding to the specified video output format.

Returns
A file extension string like ".webm" or ".mp4".

◆ GetFrameRate()

int mitk::VideoRecorder::GetFrameRate ( ) const

Get the recording frame rate.

Returns
The frame rate in frames per second.

◆ GetOutputFormat()

OutputFormat mitk::VideoRecorder::GetOutputFormat ( ) const

Get the output format (codec/container).

If not set explicitly, the format is read from the user preferences. Defaults to WebM_VP9.

Returns
The current output format.

◆ GetOutputPath()

fs::path mitk::VideoRecorder::GetOutputPath ( ) const

Get the path to the output video file.

Returns
The output file path.

◆ GetRenderWindowName()

std::string mitk::VideoRecorder::GetRenderWindowName ( ) const

Get the name of the render window being recorded.

Returns
The render window name.

◆ operator=()

VideoRecorder& mitk::VideoRecorder::operator= ( const VideoRecorder &  )
delete

◆ RecordFrame()

void mitk::VideoRecorder::RecordFrame ( ) const

Record the current frame of the render window.

Captures the current contents of the render window and stores them as a PNG file in a temporary directory.

Precondition
A recording session must be active (StartRecording() must have been called).
Exceptions
mitk::Exceptionif no recording session is running.

◆ SetFFmpegPath()

void mitk::VideoRecorder::SetFFmpegPath ( const fs::path &  path)

Set the path to the FFmpeg executable.

Parameters
[in]pathThe filesystem path to the FFmpeg binary.

◆ SetFrameRate()

void mitk::VideoRecorder::SetFrameRate ( unsigned int  fps)

Set the recording frame rate.

Parameters
[in]fpsThe desired frame rate in frames per second.

◆ SetOutputFormat()

void mitk::VideoRecorder::SetOutputFormat ( OutputFormat  format)

Set the output format (codec/container).

Parameters
[in]formatThe desired output format.

◆ SetOutputPath()

void mitk::VideoRecorder::SetOutputPath ( const fs::path &  path)

Set the path for the output video file.

Parameters
[in]pathThe filesystem path for the output video.

◆ SetRenderWindowName()

void mitk::VideoRecorder::SetRenderWindowName ( const std::string &  renderWindowName)

Set the name of the render window to record.

Parameters
[in]renderWindowNameThe name of the MITK render window.

◆ StartRecording()

void mitk::VideoRecorder::StartRecording ( )

Begin a recording session.

Precondition
A render window name must have been set.
Exceptions
mitk::Exceptionif already recording, or if no valid render window is found.

◆ StopRecording()

int mitk::VideoRecorder::StopRecording ( )

Stop the recording session and encode the video.

This is a blocking call that invokes FFmpeg to encode all captured frames into the output video file. It may take a long time to return. Consider calling from a separate thread.

Precondition
A recording session must be active.
FFmpeg path and output path must be set.
Returns
The FFmpeg process exit code (0 on success).
Exceptions
mitk::Exceptionif no session is running, or paths are not set.

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