Mujoco KDL Wrapper  0.5.1
MuJoCo + KDL bridge for robot kinematics and dynamics
Loading...
Searching...
No Matches
Video Recording

Headless H.264 video recording via EGL offscreen rendering and ffmpeg. More...

Classes

struct  mj_kdl::CameraConf
class  mj_kdl::CameraRosPublisher
struct  mj_kdl::VideoRecorder

Enumerations

enum class  mj_kdl::VideoResolution {
  mj_kdl::VideoResolution::R360p = 360 , mj_kdl::VideoResolution::R480p = 480 , mj_kdl::VideoResolution::R720p = 720 , mj_kdl::VideoResolution::R1080p = 1080 ,
  mj_kdl::VideoResolution::R2K = 1440 , mj_kdl::VideoResolution::R4K = 2160
}

Functions

Status mj_kdl::init_video_recorder (VideoRecorder *vr, mjModel *model, const char *out_path, int width=1280, int height=720, int fps=60)
Status mj_kdl::init_video_recorder (VideoRecorder *vr, mjModel *model, const char *out_path, VideoResolution resolution, int fps=60)
bool mj_kdl::record_frame (VideoRecorder *vr, Env *env)
Status mj_kdl::init_offscreen (VideoRecorder *vr, mjModel *model, int width, int height)
bool mj_kdl::render_rgb (VideoRecorder *vr, Env *env, std::uint8_t *out)
bool mj_kdl::render_rgb (VideoRecorder *vr, Env *env, std::function< void(const std::uint8_t *rgb)> done)
void mj_kdl::cleanup (VideoRecorder *vr)

Detailed Description

Headless H.264 video recording via EGL offscreen rendering and ffmpeg.

No display or GLFW window is needed. Requires EGL (libegl-dev) and ffmpeg in PATH. Enable with -DBUILD_RECORDER=ON (default).

Enumeration Type Documentation

◆ VideoResolution

enum class mj_kdl::VideoResolution
strong

Standard output resolution presets for init_video_recorder(). Each maps to a 16:9 frame size at the named quality level.

Enumerator
R360p 
R480p 
R720p 
R1080p 
R2K 
R4K 

Definition at line 452 of file mj_kdl_wrapper.hpp.

Function Documentation

◆ cleanup()

void mj_kdl::cleanup ( VideoRecorder * vr)

Flush the ffmpeg pipe, finalise the MP4, and release all EGL resources. After this call vr->_impl is null and the VideoRecorder may be discarded.

Parameters
vrVideoRecorder to tear down.

◆ init_offscreen()

Status mj_kdl::init_offscreen ( VideoRecorder * vr,
mjModel * model,
int width,
int height )

Initialise offscreen rendering only: EGL context, no ffmpeg process and no output file. Use with render_rgb() to grab frames; the camera is vr->cam, as for a recording, and cleanup(VideoRecorder*) frees it. An open vr is freed first.

Parameters
vrVideoRecorder to initialise; freed by cleanup(VideoRecorder*).
modelMuJoCo model whose default free camera vr->cam starts from.
widthFrame width in pixels.
heightFrame height in pixels.
Returns
an error if EGL init fails.

Referenced by TEST().

◆ init_video_recorder() [1/2]

Status mj_kdl::init_video_recorder ( VideoRecorder * vr,
mjModel * model,
const char * out_path,
int width = 1280,
int height = 720,
int fps = 60 )

Initialise a headless EGL video recorder. Creates an EGL context and launches an ffmpeg process (H.264/MP4) via a pipe. The render context is made from the Env at its first frame and remade after the Env's model is rebuilt.

Parameters
vrVideoRecorder to initialise; freed by cleanup(VideoRecorder*).
modelMuJoCo model whose default free camera vr->cam starts from.
out_pathOutput MP4 path (e.g. "sim.mp4").
widthFrame width in pixels (default 1280).
heightFrame height in pixels (default 720).
fpsPlayback frame rate (default 60).
Returns
an error if EGL init or ffmpeg launch fails.

Referenced by main(), and TEST().

◆ init_video_recorder() [2/2]

Status mj_kdl::init_video_recorder ( VideoRecorder * vr,
mjModel * model,
const char * out_path,
VideoResolution resolution,
int fps = 60 )

Convenience overload: initialise a VideoRecorder using a named resolution preset. Frame width is derived from the preset at 16:9 aspect ratio.

Parameters
vrVideoRecorder to initialise.
modelMuJoCo model.
out_pathOutput MP4 path.
resolutionVideoResolution preset (e.g. VideoResolution::R1080p).
fpsPlayback frame rate (default 60).
Returns
an empty Status on success, else the error.

◆ record_frame()

bool mj_kdl::record_frame ( VideoRecorder * vr,
Env * env )

Snapshot env's current state as the next video frame; it is rendered and encoded on the recorder's thread. Waits only while the previous frame has not been picked up.

Parameters
vrVideoRecorder initialised by init_video_recorder().
envEnv to render.
Returns
false once rendering or the pipe to ffmpeg has failed; every frame is recorded.

Referenced by main(), and TEST().

◆ render_rgb() [1/2]

bool mj_kdl::render_rgb ( VideoRecorder * vr,
Env * env,
std::function< void(const std::uint8_t *rgb)> done )

Snapshot env's current state and return; done gets the top-down RGB8 frame on the recorder's thread, valid only during the call. Waits only while the previous frame has not been picked up.

Parameters
vrVideoRecorder initialised by init_offscreen() or init_video_recorder().
envEnv to render.
doneReceives width*height*3 bytes.
Returns
false once rendering has failed.

◆ render_rgb() [2/2]

bool mj_kdl::render_rgb ( VideoRecorder * vr,
Env * env,
std::uint8_t * out )

Render env's current state into a caller-owned top-down RGB8 buffer of width*height*3 bytes.

Parameters
vrVideoRecorder initialised by init_offscreen() or init_video_recorder().
envEnv to render.
outDestination buffer, width*height*3 bytes.
Returns
true on success.

Referenced by TEST().