Skip to content

Commit

Permalink
Add support for the HANDBRAKECLI_PATH environment variable.
Browse files Browse the repository at this point in the history
  • Loading branch information
75lb committed Jul 20, 2024
1 parent 3620a33 commit 91d8ab4
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 20 deletions.
10 changes: 10 additions & 0 deletions README.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ Task % done FPS Avg FPS ETA
Encoding 1.07 131.76 158.12 00h21m11s
```

## HandbrakeCLI Path

In some situations or environments (e.g. Docker) you may need to specify a custom HandbrakeCLI path. You can either specify the path in an environment variable:

```sh
HANDBRAKECLI_PATH="./example/HandbrakeCLI"
```

..or pass `HandbrakeCLIPath` as an option, programmatically. See the API documentation below for instructions. Also, see the [examples folder] for example code.

# API Reference
{{#module name="handbrake-js"}}
{{>body~}}
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ Task % done FPS Avg FPS ETA
Encoding 1.07 131.76 158.12 00h21m11s
```

## HandbrakeCLI Path

In some situations or environments (e.g. Docker) you may need to specify a custom HandbrakeCLI path. You can either specify the path in an environment variable:

```sh
HANDBRAKECLI_PATH="./example/HandbrakeCLI"
```

..or pass `HandbrakeCLIPath` as an option, programmatically. See the API documentation below for instructions. Also, see the [examples folder] for example code.

# API Reference
Handbrake for node.js.

Expand Down
24 changes: 14 additions & 10 deletions dist/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@ const { __dirname: __dirname$1 } = getModulePaths((typeof document === 'undefine
/* path to the HandbrakeCLI executable downloaded by the install script */
let HandbrakeCLIPath = null;

switch (process.platform) {
case 'darwin':
HandbrakeCLIPath = path.join(__dirname$1, '..', 'bin', 'HandbrakeCLI');
break
case 'win32':
HandbrakeCLIPath = path.join(__dirname$1, '..', 'bin', 'HandbrakeCLI.exe');
break
case 'linux':
HandbrakeCLIPath = 'HandBrakeCLI';
break
if (process.env.HANDBRAKECLI_PATH) {
HandbrakeCLIPath = process.env.HANDBRAKECLI_PATH;
} else {
switch (process.platform) {
case 'darwin':
HandbrakeCLIPath = path.join(__dirname$1, '..', 'bin', 'HandbrakeCLI');
break
case 'win32':
HandbrakeCLIPath = path.join(__dirname$1, '..', 'bin', 'HandbrakeCLI.exe');
break
case 'linux':
HandbrakeCLIPath = 'HandBrakeCLI';
break
}
}

let last = null;
Expand Down
25 changes: 25 additions & 0 deletions examples/handbrakecli-path-env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import hbjs from 'handbrake-js'
import path from 'path'
import currentModulePaths from 'current-module-paths'
const { __dirname } = currentModulePaths(import.meta.url)

async function start () {
const options = {
input: path.resolve(__dirname, '../test/video/demo.mkv'),
output: './tmp/output.mp4',
preset: 'Very Fast 480p30'
}

const result = await hbjs.run(options)
console.log(result)
}

start().catch(console.error)

/*
Run this example with the `HANDBRAKECLI_PATH` environment variable set, e.g.:
$ HANDBRAKECLI_PATH=./tmp/HandbrakeCLI node examples/handbrakecli-path-env.js
*/
24 changes: 14 additions & 10 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ const { __dirname } = currentModulePaths(import.meta.url)
/* path to the HandbrakeCLI executable downloaded by the install script */
let HandbrakeCLIPath = null

switch (process.platform) {
case 'darwin':
HandbrakeCLIPath = path.join(__dirname, '..', 'bin', 'HandbrakeCLI')
break
case 'win32':
HandbrakeCLIPath = path.join(__dirname, '..', 'bin', 'HandbrakeCLI.exe')
break
case 'linux':
HandbrakeCLIPath = 'HandBrakeCLI'
break
if (process.env.HANDBRAKECLI_PATH) {
HandbrakeCLIPath = process.env.HANDBRAKECLI_PATH
} else {
switch (process.platform) {
case 'darwin':
HandbrakeCLIPath = path.join(__dirname, '..', 'bin', 'HandbrakeCLI')
break
case 'win32':
HandbrakeCLIPath = path.join(__dirname, '..', 'bin', 'HandbrakeCLI.exe')
break
case 'linux':
HandbrakeCLIPath = 'HandBrakeCLI'
break
}
}

export { HandbrakeCLIPath }

0 comments on commit 91d8ab4

Please sign in to comment.