81 online 3 members  + Join RP Base  +
FreeScript

screencapture

by itschip  ·  version 0.17.2  ·  updated 5 days ago

No reviews yet

Downloads
0
Reviews
0
Size
295 KB
Code check
Clean
Licence
AGPL-3.0
Released
Nov 2026

Screen capture for FiveM. A successor for screenshot-basic. Supports both images and videos.

screencapture
ScreenCapture
A FiveM resource for capturing screenshots and recording videos from a player's game view, built as a modern replacement for screenshot-basic.

Screenshots**serverCapture — server-side export**
Captures a screenshot for a player and returns the image data to your callback.

Parameter, Type, Description

source, number, Player source to capture
options, object, Capture options (see below)
callback, function, Called with the captured image data
dataType, 'base64' \, 'blob', Format of the data passed to the callback. Default: 'base64'
Options
Field, Type, Default, Description

encoding, string, 'webp', Image encoding format: 'webp', 'jpg', or 'png'
maxWidth, number, 1920, Maximum capture width in pixels
maxHeight, number, 1080, Maximum capture height in pixels

exports.screencapture:serverCapture(source, { encoding = 'webp' }, function(data)
    -- data is a base64 data URI string
    print(data)
end)

exports.screencapture.serverCapture(
  source,
  { encoding: 'webp' },
  (data: Buffer) => {
    fs.writeFileSync('./screenshot.webp', data);
  },
  'blob',
);

**remoteUpload — server-side export**
Captures a screenshot and uploads it directly to a remote URL. The callback receives the remote API's JSON response.

Parameter, Type, Description

source, number, Player source to capture
url, string, Remote upload URL
options, object, Capture options (see below)
callback, function, Called with the remote API's JSON response
dataType, 'base64' \, 'blob', Upload format. Default: 'base64'
Options
Field, Type, Default, Description

encoding, string, 'webp', Image encoding format: 'webp', 'jpg', or 'png'
headers, object, {}, HTTP headers included in the upload request
formField, string, 'file', FormData field name for the uploaded file
filename, string, File name used in the FormData (without extension)
maxWidth, number, 1920, Maximum capture width in pixels
maxHeight, number, 1080, Maximum capture height in pixels

Remote uploads include server identity headers by default: User-Agent, X-Screencapture-Server-Name, X-Screencapture-Upload-Host, and X-Screencapture-Resource. These expose the FiveM server name and resource name to the upload provider. Set screencapture_upload_identity_headers false in your server config to disable them. User-provided headers override the defaults.

For servers with unreliable IPv6 connectivity, add set screencapture_upload_ipv4 true to server.cfg to force IPv4 for remote screenshot and video uploads. The default is false, which keeps Node.js address selection. The setting is read for each upload.

exports.screencapture:remoteUpload(source, 'https://api.fivemanage.com/api/v3/file', {
    encoding = 'webp',
    headers = { ['Authorization'] = 'your-api-key' },
}, function(response)
    print(response.data.url)
end, 'blob')

exports.screencapture.remoteUpload(
  source,
  'https://api.fivemanage.com/api/v3/file',
  {
    encoding: 'webp',
    headers: { Authorization: 'your-api-key' },
  },
  (response: any) => {
    console.log(response.data.url);
  },
  'blob',
);

Video capture
Experimental. Video capture is functional but has not been extensively tested across different hardware, FiveM builds, or CEF versions. The API may change. VP9 encoding relies on the WebCodecs API being available in FiveM's bundled Chromium — if encoding silently produces no frames, the resulting file will contain only the container header. Please report any issues.

Video is recorded as WebM (VP9) via the player's NUI. Chunks are streamed to the server as they are produced, assembled on disk, and the callback is fired when the recording is finalized.

Every video capture returns a public captureId. Use it to stop the recording, check whether it is active, and correlate callback results. Internal upload tokens are not part of the public API.

**startVideoCapture — server-side export**
Starts a video recording for a player and returns a captureId. If duration is provided, the recording stops automatically after that many seconds. The callback receives a structured result object when the WebM file is finalized. The file lives in screencapture/tmp/ and the caller is responsible for it.

Parameter, Type, Description

source, number, Player source to record
options, object, Capture options (see below)
callback, function, Called with the finalized capture result
Options
Field, Type, Default, Description

duration, number, Optional recording duration in seconds
maxWidth, number, 1920, Maximum capture width in pixels
maxHeight, number, 1080, Maximum capture height in pixels

local captureId = exports.screencapture:startVideoCapture(source, {
    duration = 10,
    maxWidth = 1280,
    maxHeight = 720,
}, function(result)
    if result.status ~= 'success' then
        print(('Video capture failed: %s'):format(result.error or 'unknown error'))
        return
    end

    print(('Capture %s saved to %s'):format(result.captureId, result.filePath))
    print(('Bytes received: %d'):format(result.bytesReceived or 0))
end)

print(('Started video capture: %s'):format(captureId))

const captureId = exports.screencapture.startVideoCapture(
  source,
  { duration: 10, maxWidth: 1280, maxHeight: 720 },
  (result: any) => {
    if (result.status !== 'success') {
      console.error('Video capture failed:', result.error);
      return;
    }

    console.log(`Capture ${result.captureId} saved to ${result.filePath}`);
  },
);

**stopVideoCapture — server-side export**
Stops an active recording by captureId. This triggers output.finalize() in the NUI, flushes remaining encoded frames, and fires the callback registered by startVideoCapture or startVideoCaptureUpload.

Parameter, Type, Description

captureId, string, Capture ID to stop

`

…