FFMPEG Edit Video File

Hey everyone,

i created a confluence global page custom ui and wanted to edit a video with “@ffmpeg/ffmpeg” but whenever i try to edit a video i get the error:

Error: There was an error invoking the function - fetch is not defined

Even though my function doesnt use fetch (though it uses fetchFile from FFMPEG but i’ve read thats not the same) I added to my manifest i think all the necessary permissions:

permissions:
  external:
    fetch:
      backend:
        - "*.unpkg.com"
        - "https://unpkg.com/@ffmpeg/core@0.11.0/dist/ffmpeg-core.js"
      client:
        - "*.unpkg.com"
        - "https://unpkg.com/@ffmpeg/core@0.11.0/dist/ffmpeg-core.js"
  content:
    scripts:
      - unsafe-inline
      - "blob:"

Any help would be appreciated.

Welcome to the Atlassian developer community @MingHaoBobbyWu,

From ffmpeg on npm, I read:

This library provides a set of functions and utilities to abstract commands-line usage of ffmpeg. To use this library requires that ffmpeg is already installed (including all necessary encoding libraries like libmp3lame or libx264)

That means it won’t work in a browser because JavaScript is sandboxed. And it won’t work a Forge function back-end where the Forge runtime (currently an Atlassian approximation of Node) also severely limits access to the OS. I doubt ffmpeg and the libraries are in the machine image.

That doesn’t explain the error message but I’m pretty sure this library is not going to work.

Hi @ibuchanan

thanks for you reply, as i understood it @ffmpeg/ffmpeg is a complete JS port of FFMPEG. Is it possible to utilize this library then?
If not could you suggest another method to edit a video File, if possible i would like to do it without utilizing an external backend

Best Regards

Bobby

@MingHaoBobbyWu,

Thanks for correcting me with the correct link.

It won’t be possible on the backend because the library depends on node-fetch. In the Forge runtime, system calls are limited for customer security. That will change some in near future with native Node.js runtime, hopefully before the end of this year. While that would unblock system calls and libraries that use them like node-fetch, where that library needs to call might still be a problem.

I’m less clear on the front-end. However, the docs read:

SharedArrayBuffer is only available to pages that are cross-origin isolated. So you need to host your own server with Cross-Origin-Embedder-Policy: require-corp and Cross-Origin-Opener-Policy: same-origin headers to use ffmpeg.wasm.

Since you can’t control those header policies for the Atlassian products, I don’t think it’s going to work.

@ibuchanan

Thanks for your help, so it aint possible yet (or at all) to integrate video editing with Forge in the Frontend.

Would you happen to know if its possible achieve my goal with a backend that supports file upload to get a respone that contains a file?

Best Regards

Bobby

Yes, this “remote” backend approach would be the only remaining option. My belief in the possibility is bolstered by a recent collaboration with AWS to build their Service Management Connect, which effectively integrates JSM with multiple AWS services on the back-end. All without the need for Forge Remote.

That said, if you are not a company that routinely builds your own cloud services, like AWS, then the burden of not having the auth patterns provided by Forge Remote could make the back-end quite a burden. You’ll use Forge fetch to talk to your back-end, but you are still responsible for providing an appropriate auth model to make sure customer/user data remains secure.

In short, possible but non-trivial.