Handbrake-js on Heroku doesn't work. Everything works well for http://localhost

250 views Asked by At

Using the npm install handbrake-js --save command, I installed handbrake-js as a library, and after some tweaking, handbrake-js started to do the job perfectly. And here's the problem. On the local computer everything works well, videos are decoded, etc. BUT (!) When I upload my application to Heroku, handbrake-js stops working.

HandBrake version: 5.0.2

Operating system and version: macOS 10.15 Catalina

My application uses node js

Error message text:

Here is what information Heroku gives when deploy an application on Heroku:

Linux users

  • handbrake-cli must be installed separately as the root user.

Ubuntu users can do this using the following commands:

  • add-apt-repository --yes ppa: stebbins / handbrake-releases
  • apt-get update -qq
  • apt-get install -qq handbrake-cli

Heroku Log:

Here's what happens when you try to decode:

2020-12-02T18:34:14.124945+00:00 app[web.1]: Error: Command failed: "HandBrakeCLI" --input "public/images/02122020-123404_338-test.mov" --output "public/images/02122020-123404_338-test.mp4" --preset "Gmail Medium 5 Minutes 480p30"
2020-12-02T18:34:14.124948+00:00 app[web.1]: /bin/sh: 1: HandBrakeCLI: not found
2020-12-02T18:34:14.124948+00:00 app[web.1]: 
2020-12-02T18:34:14.124949+00:00 app[web.1]: at ChildProcess.exithandler (child_process.js:308:12)
2020-12-02T18:34:14.124950+00:00 app[web.1]: at ChildProcess.emit (events.js:314:20)
2020-12-02T18:34:14.124950+00:00 app[web.1]: at maybeClose (internal/child_process.js:1022:16)
2020-12-02T18:34:14.124951+00:00 app[web.1]: at Socket.<anonymous> (internal/child_process.js:444:11)
2020-12-02T18:34:14.124951+00:00 app[web.1]: at Socket.emit (events.js:314:20)
2020-12-02T18:34:14.124951+00:00 app[web.1]: at Pipe.<anonymous> (net.js:675:12) {
2020-12-02T18:34:14.124952+00:00 app[web.1]: killed: false,
2020-12-02T18:34:14.124952+00:00 app[web.1]: code: 127,
2020-12-02T18:34:14.124953+00:00 app[web.1]: signal: null,
2020-12-02T18:34:14.124954+00:00 app[web.1]: cmd: '"HandBrakeCLI" --input "public/images/02122020-123404_338-test.mov" --output "public/images/02122020-123404_338-test.mp4" --preset "Gmail Medium 5 Minutes 480p30"'
2020-12-02T18:34:14.124954+00:00 app[web.1]: }

Here is the code used to set up and start decoding:

const options = {
        input: req.files.video ? req.files.video[0].path : '',
        output: newPathVideo,
        preset: 'Gmail Medium 5 Minutes 480p30',
    }
    async function startEncoding () {
        console.log('Start decoding video')
        const result = await hbjs.run(options)
        console.log(`${result.stdout}End decoding video`)
    }
    await startEncoding()
1

There are 1 answers

0
Александр Ищенко On BEST ANSWER

For handbrake-js to work correctly, you need to globally install handbrake-cli on the heroku side. For this you need to use a third-party buildpack such as the heroku-buildpack-apt. To add this buildpack to your application you can use the command

heroku buildpacks:add --index 1 heroku-community/apt -a your-app

Make sure Heroku is installed globally on your computer!

You would need to also create a file named Aptfile on your project root that contains the list of apt packages to be installed such as handbrake-cli.