A FiveM resource for capturing screenshots and recording videos from a player's game view, built as a modern replacement for screenshot-basic.
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' |
| 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',
);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' |
| 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 |
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',
);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.
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 |
| 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}`);
},
);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 |
local captureId = exports.screencapture:startVideoCapture(source, {}, function(result)
print(result.filePath)
end)
-- Stop later.
exports.screencapture:stopVideoCapture(captureId)Starts a video recording for a player, uploads the resulting WebM to a remote URL when finalized, deletes the temp file, and returns a captureId. The callback receives a structured result object with the remote response.
| Parameter | Type | Description |
|---|---|---|
source |
number |
Player source to record |
url |
string |
Remote upload URL |
options |
object |
Upload and capture options |
callback |
function |
Called with the finalized capture result |
| Field | Type | Default | Description |
|---|---|---|---|
duration |
number |
Optional recording duration in seconds | |
headers |
object |
{} |
HTTP headers included in the upload request |
formField |
string |
'file' |
FormData field name for the uploaded file |
filename |
string |
'recording' |
File name in the FormData (.webm is appended) |
maxWidth |
number |
1920 |
Maximum capture width in pixels |
maxHeight |
number |
1080 |
Maximum capture height in pixels |
local captureId = exports.screencapture:startVideoCaptureUpload(source, 'https://api.fivemanage.com/api/v3/file', {
duration = 15,
headers = { ['Authorization'] = 'your-api-key' },
filename = 'gameplay',
}, function(result)
if result.status ~= 'success' then
print(('Upload failed: %s'):format(result.error or 'unknown error'))
return
end
print(('Uploaded capture %s'):format(result.captureId))
print(result.response.data.url)
end)Returns whether a capture ID is currently active.
if exports.screencapture:isVideoCaptureActive(captureId) then
exports.screencapture:stopVideoCapture(captureId)
endserverCaptureStream, remoteUploadStream, INTERNAL_stopServerCaptureStream, and stopStream are still available for existing callers. The stream start exports now return a captureId, but their callbacks keep the old payloads: local captures receive the WebM file path, and remote captures receive the remote API response.
local captureId = exports.screencapture:serverCaptureStream(source, { duration = 10 }, function(filePath)
print(filePath)
end)
exports.screencapture:INTERNAL_stopServerCaptureStream(source)Not recommended. Upload tokens are exposed to the client.
exports['screencapture']:requestScreenshotUpload('https://api.fivemanage.com/api/v3/file', 'file', {
headers = { ['Authorization'] = 'your-api-key' },
encoding = 'webp',
}, function(data)
local resp = json.decode(data)
print(resp.url)
end)Returns a base64 data URI of the screenshot directly to the callback without uploading.
exports['screencapture']:requestScreenshot({ encoding = 'jpg' }, function(data)
-- data is a base64-encoded image data URI
print(data)
end)