ScreenCapture is a being built as a replacement for screenshot-basic in FiveM.
I'll explain this later, but breifly - Screenshot-Basic is no longer maintained, has it's issues. It's a nightmare for almost everyone to get up and running for some reason (blame FXServer yarn) and it's not up-to-date with anything.
Note that there's only server-side exports at the moment. I might add client exports, but only if there's enough requests for it. There will also be an export that will upload through NUI, even though this might be redundant - we'll see.
Converting Base64 to Blob/Buffer is easy enough with Node, but Lua ScRT in FiveM doesn't really offer that functionality, so if you wish to use the serverCapture
export, you'll need to use Base64. More on that later.
Parameter | Type | Description |
---|---|---|
source |
string | Player to capture |
options |
object/table | Configuration options for the capture |
callback |
function | A function invoked with the captured data |
dataType |
string (default: base64) | What data should be returned through the callback: 'base64' or 'blob' |
The options
argument accepts an object with the following fields:
Field | Type | Default | Description |
---|---|---|---|
headers |
object/table |
null |
Optional HTTP headers to include in the capture request. |
formField |
string |
null |
The form field name to be used when uploading the captured data. |
filename |
string |
null |
Specifies the name of the file when saving or transmitting captured data. |
encoding |
string |
'webp' |
Specifies the encoding format for the captured image (e.g., 'webp' ). |
RegisterCommand(
'capture',
(_: string, args: string[]) => {
exp.screencapture.serverCapture(
args[0],
{ encoding: 'webp' },
(data: string | Buffer<ArrayBuffer>) => {
data = Buffer.from(data as ArrayBuffer);
fs.writeFileSync('./blob_image.webp', data);
console.log(`File saved`);
},
'blob',
);
},
false,
);
Parameter | Type | Description |
---|---|---|
source |
string | Player to capture |
url |
string | The upload URL |
options |
object/table | Configuration options for the capture |
callback |
function | Callback returning the HTTP response in JSON |
dataType |
string (default: base64) | What data type should be used to upload the file: 'base64' or 'blob' |
The options
argument accepts an object with the following fields:
Field | Type | Default | Description |
---|---|---|---|
headers |
object/table |
null |
Optional HTTP headers to include in the capture request. |
formField |
string |
null |
The form field name to be used when uploading the captured data. |
filename |
string |
null |
Specifies the name of the file when saving or transmitting captured data. |
encoding |
string |
'webp' |
Specifies the encoding format for the captured image (e.g., 'webp' ). |
RegisterCommand("remoteCapture", (_: string, args: string[]) => {
exp.screencapture.remoteUpload(args[0], "https://api.fivemanage.com/api/image", {
encoding: "webp",
headers: {
"Authorization": "",
}
}, (data: any) => {
console.log(data);
}, "blob")
}, false);
exports.screencapture:remoteUpload(args[1], "https://api.fivemanage.com/api/image", {
encoding = "webp",
headers = {
["Authorization"] = ""
}
}, function(data)
print(data.url)
end, "blob")
- Server exports both for getting image data and uploading images/videos from the server
- Client exports (maybe)
- Upload images or videos from NUI, just more secure.
- React, Svelt and Vue packages + publishing all internal packages like @screencapture/gameview (SoonTM)