The setCapturer method configures how K21 captures screen content. It allows you to control parameters like frame rate, duration, and where to save the captured content.

Usage

const k21 = new K21();

// Use default settings
k21.setCapturer();

// Custom configuration
k21.setCapturer({
  fps: 2,
  duration: 30,
  saveVideoTo: '/path/to/videos',
  videoChunkDuration: 30
});

CaptureConfig Interface

The configuration object accepts the following parameters:

ParameterTypeDefaultDescription
fpsnumber1Frames per second for capture
durationnumber10Total duration of capture in seconds
saveScreenshotTostringundefinedPath where screenshots should be saved. If not provided, screenshots won’t be saved
saveVideoTostringundefinedPath where video should be saved. If not provided, video won’t be saved
videoChunkDurationnumber60Duration of each video chunk in seconds

Default Values

If you call setCapturer() without any configuration, these default values will be used:

  • fps: 1
  • duration: 10
  • saveVideo: false
  • saveVideoTo: ”
  • videoChunkDuration: 60
  • saveScreenshot: false
  • saveScreenshotTo: ”

Examples

Basic Screen Capture

k21.setCapturer();
// Uses default settings: 1 fps for 10 seconds

High-Frame Rate Capture

k21.setCapturer({
  fps: 30,
  duration: 5
});
// Captures at 30 fps for 5 seconds

Save Video with Chunks

k21.setCapturer({
  fps: 1,
  duration: 3600, // 1 hour
  saveVideoTo: './captures',
  videoChunkDuration: 300 // 5-minute chunks
});
// Captures for 1 hour, saving video in 5-minute chunks

Save Screenshots Only

k21.setCapturer({
  fps: 0.2, // One frame every 5 seconds
  duration: 600,
  saveScreenshotTo: './screenshots'
});
// Takes a screenshot every 5 seconds for 10 minutes

Error Handling

The method will throw an error in these cases:

  • If a file capturer is already set
  • If the provided video or screenshot paths are invalid
  • If an uploader is already configured
try {
  k21.setCapturer({
    saveVideoTo: '/invalid/path'
  });
} catch (error) {
  console.error('Failed to set capturer:', error.message);
}