Skip to content

cf_video_encoder_update

Category: video
GitHub: cute_video.h


Records what was just rendered to a canvas, advancing the recording by an elapsed time.

int cf_video_encoder_update(CF_VideoEncoder* encoder, CF_Canvas canvas, float dt);
Parameters Description
encoder The encoder.
canvas The canvas to capture, sized exactly as the encoder was created with.
dt Seconds elapsed, usually CF_DELTA_TIME.

Return Value

Returns how many frames were compressed on this call, often 0 -- captures land a beat late because the pixels cross back from the GPU asynchronously.

Remarks

The recording twin of cf_video_update: call it once a frame, after cf_app_draw_onto_screen -- captures read whatever work the GPU has been handed, so the frame must be submitted first or the capture sees the canvas as it was a frame ago. From there it does the rest -- paces captures against dt so the file plays at the rate the encoder was created with no matter what the display is doing, keeps the GPU readback asynchronous so nothing stalls, and holds the recording to wall-clock time when the game runs slower than the recording rate by repeating frames, which P_Skip makes nearly free. A long stall drops frames rather than ballooning the catch-up, same as playback. cf_video_encoder_save collects any captures still in flight, so stopping is just save. The compression itself runs on this thread and is the expensive part; see cf_video_encoder_add_frame, which is also the way in for frames that are pixels rather than a canvas.

CF_VideoEncoder
cf_make_video_encoder
cf_video_encoder_add_frame
cf_video_encoder_save
cf_video_update