ScreenCapture - A replacement for screenshot-basic [OPEN-SOURCE]

ScreenCapture

Repository: GitHub - itschip/screencapture: Screen capture for FiveM. A successor for screenshot-basic.

Download: Release v0.0.3 · itschip/screencapture · GitHub

ScreenCapture is a being built as a replacement for screenshot-basic in FiveM.

Why build something new?

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.

How to use

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.

JavaScript / TypeScript

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.

serverCapture (server-side export)

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'

Options

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,
);

remoteUpload (server-side export)

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'

Options

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);

Lua example with remoteUpload

exports.screencapture:remoteUpload(args[1], "https://api.fivemanage.com/api/image", {
    encoding = "webp",
    headers = {
        ["Authorization"] = ""
    }
}, function(data)
    print(data.url)
end, "blob")

What will this include?

  1. Server exports both for getting image data and uploading images/videos from the server
  2. Client exports (maybe)
  3. Upload images or videos from NUI, just more secure.
  4. React, Svelte and Vue packages + publishing all internal packages like @screencapture/gameview (SoonTM)
32 Likes

Nice work Chip :smiley:

1 Like

Amazing work :cowboy_hat_face:
Waiting for NPWD V4 patiently as well :heart_eyes:

1 Like

Will there be some sort of backwards compat for this for scripting that may use the aforementioned resource?

Depends, but most likely not. We’ll so many actually would want it. For now, my focus is moving forward and away from screenshot-basic.

Backwards support for screenshot-basic exports/events would be great!

6 Likes

Great work my love :heart_eyes:

Amazing, what a treat! Thank you for sharing. Hope there will be backwards comp so I can replace it fully :heart_eyes:

@gr.zzy, @iSentrie, @AdvancedTeam

What exports are you currently using from screenshot-basic? And are you calling these exports from the server or client?

I am not very eager to create client exports, as it opens up for security concerns when you end up exposing secrets or tokens to the client + I don’t want to enable poor practices.

Backwards compat for server exports would be fine.

How to capture video with this?

That’ll be added shortly!

Hey i recommend to use this to have backwards compatibility with screenshot-basic

local function exportHandler(exportName, func)
    AddEventHandler(('__cfx_export_screenshot-basic_%s'):format(exportName), function(setCB)
        setCB(func)
    end)
end

exportHandler('requestScreenshot',function(data,cb)
  -- code
end)

so you can still use old exports like this

exports['screenshot-basic']:requestScreenshot(function(data)
    TriggerEvent('chat:addMessage', { template = '<img src="{0}" style="max-width: 300px;" />', args = { data } })
end)
2 Likes

Example

exports['screenshot-basic']:requestScreenshotUpload('https://wew.wtf/upload.php', 'files[]', function(data)
    local resp = json.decode(data)
    TriggerEvent('chat:addMessage', { template = '<img src="{0}" style="max-width: 300px;" />', args = { resp.files[1].url } })
end)

Why would you want to upload from the client? What’s the use-case and why would you not use the server-side exports? So I can understand better :smiley:

i could be wrong but because of JD-logs v3 it uses ss basics client side export

1 Like

v0.0.4

Bug Fixes

  • game/server: correct encoding ext for filename (itschip)

I’m not sure, most of the resources that we use in our server that use screenshot basic are escrowed, so I can’t see what they are calling/using.

2 Likes

Esperando pacientemente a NPWD V4 también :heart_eyes:

v0.1.0

Updates

  • Initial screenhost-basic backwards compatibility
  • Support for form-data to the http handler.

screenhost-basic compatibility example:

exports['screencapture']:requestScreenshotUpload('https://api.fivemanage.com/api/image', 'file', {
        headers = {
            ["Authorization"] = API_TOKEN
        },
        encoding = "webp"
    }, function(data)
        local resp = json.decode(data)
        print(resp.url);
        TriggerEvent('chat:addMessage', { template = '<img src="{0}" style="max-width: 300px;" />', args = { resp.url } })
    end)

Available now: Release v0.1.0 · itschip/screencapture · GitHub