Skip to content

Commit

Permalink
feat!: pass custom ffmpeg path via argument (#63)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: passing ffmpeg path via env var is not supported
anymore
  • Loading branch information
phaux committed Jul 5, 2024
1 parent 4162fb3 commit af04d72
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@

Node bindings to ffmpeg command, exposing stream based API.

[CHANGELOG](CHANGELOG.md)

**Note:** ffmpeg must be installed and available in `PATH`.
You can set a custom ffmpeg path via `FFMPEG_PATH` environment variable (default is just `ffmpeg`).
> [!NOTE]
> FFmpeg must be installed and available in `PATH`.
> You can set a custom ffmpeg path via an argument (default is just `ffmpeg`).
## Examples

Expand Down
19 changes: 14 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { join } from "node:path"
import { PassThrough } from "node:stream"

const dbg = debug("ffmpeg-stream")
const { FFMPEG_PATH = "ffmpeg" } = process.env
const EXIT_CODES = [0, 255]

/**
Expand Down Expand Up @@ -100,8 +99,6 @@ function getArgs(options) {
/**
* A class which wraps a FFmpeg process.
*
* Remember to call {@link Converter.run} to start the conversion.
*
* @example
*
* ```js
Expand Down Expand Up @@ -139,6 +136,18 @@ export class Converter {
*/
killed = false

/**
* Initializes the converter.
*
* Remember to call {@link Converter.run} to actually start the FFmpeg process.
*
* @param {string} [ffmpegPath] Path to the FFmpeg executable. (default: `"ffmpeg"`)
*/
constructor(ffmpegPath = "ffmpeg") {
/** @private */
this.ffmpegPath = ffmpegPath
}

/**
* Defines an FFmpeg input file.
*
Expand Down Expand Up @@ -377,9 +386,9 @@ export class Converter {

const command = this.getSpawnArgs()
const stdio = this.getStdioArg()
dbg(`spawn: ${FFMPEG_PATH} ${command.join(" ")}`)
dbg(`spawn: ${this.ffmpegPath} ${command.join(" ")}`)
dbg(`spawn stdio: ${stdio.join(" ")}`)
this.process = spawn(FFMPEG_PATH, command, { stdio })
this.process = spawn(this.ffmpegPath, command, { stdio })
const finished = this.handleProcess()

for (const pipe of this.pipes) {
Expand Down

0 comments on commit af04d72

Please sign in to comment.