Skip to content

Commit

Permalink
ff{mpeg,probe}-static subpackages: add tests ✅, example code & readme 📝
Browse files Browse the repository at this point in the history
fixes #19
closes #113

Co-Authored-By: Jannis R <mail@jannisr.de>
  • Loading branch information
derhuerst committed May 22, 2023
1 parent 741474e commit c90e794
Show file tree
Hide file tree
Showing 6 changed files with 236 additions and 60 deletions.
48 changes: 3 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,54 +1,12 @@
# ffmpeg-static
# static ffmpeg/ffprobe binaries

**[ffmpeg](https://ffmpeg.org) static binaries for Mac OSX, Linux, Windows.**
Static **[ffmpeg](https://ffmpeg.org)/ffprobe binaries for macOS, Linux, Windows.**

Supports macOS (64-bit and arm64), Linux (32 and 64-bit, armhf, arm64), Windows (32 and 64-bit). [The ffmpeg version currently used is `5.0.1`.](https://github.com/eugeneware/ffmpeg-static/releases/tag/b5.0.1)

[![npm version](https://img.shields.io/npm/v/ffmpeg-static.svg)](https://www.npmjs.com/package/ffmpeg-static)
![minimum Node.js version](https://img.shields.io/node/v/ffmpeg-static.svg)

*Note:* The version of `ffmpeg-static` follows [SemVer](http://semver.org). When releasing new versions, **we do *not* consider breaking changes in `ffmpeg` itself**, but only the JS interface (see below). For example, `ffmpeg-static@4.5.0` might download ffmpeg `5.0`. To prevent an `ffmpeg-static` upgrade downloading backwards-incompatible ffmpeg versions, [use a strict version range](https://docs.npmjs.com/files/package.json#dependencies) for it or use a [lockfile](https://docs.npmjs.com/files/package-lock.json).

Also check out [`node-ffmpeg-installer`](https://github.com/kribblo/node-ffmpeg-installer)!

## Installation

This module is installed via npm:

``` bash
$ npm install ffmpeg-static
```

*Note:* During installation, it will download the appropriate `ffmpeg` binary from the [`b5.0.1` GitHub release](https://github.com/eugeneware/ffmpeg-static/releases/tag/b5.0.1). Use and distribution of the binary releases of FFmpeg are covered by their respective license.

### Custom binaries url

By default, the `ffmpeg` binary will get downloaded from `https://github.com/eugeneware/ffmpeg-static/releases/download`. To customise this, e.g. when using a mirror, set the `FFMPEG_BINARIES_URL` environment variable.

```shell
export FFMPEG_BINARIES_URL=https://cdn.npmmirror.com/binaries/ffmpeg-static
npm install ffmpeg-static
```

### Electron & other cross-platform packaging tools

Because `ffmpeg-static` will download a binary specific to the OS/platform, you need to purge `node_modules` before (re-)packaging your app *for a different OS/platform* ([read more in #35](https://github.com/eugeneware/ffmpeg-static/issues/35#issuecomment-630225392)).

## Example Usage

Returns the path of a statically linked ffmpeg binary on the local filesystem.

``` js
var pathToFfmpeg = require('ffmpeg-static');
console.log(pathToFfmpeg);
```

```
/Users/j/playground/node_modules/ffmpeg-static/ffmpeg
```

Check the [example script](example.js) for a more thorough example.

## Sources of the binaries

[The binaries download script](download-binaries/index.sh) downloads binaries from these locations:
Expand All @@ -62,7 +20,7 @@ The script extracts build information and (when possible) the license file from

## Show your support

This npm package includes statically linked binaries that are produced by the following individuals. Please consider supporting and donating to them who have been providing quality binary builds for many years:
The npm packages include statically linked binaries that are produced by the following individuals, who have been doing this for many years. Please consider supporting and donating to them:

- **Linux builds**: [John Van Sickle](https://www.johnvansickle.com/ffmpeg/)
- **macOS builds**: [Helmut K. C. Tessarek](https://evermeet.cx/ffmpeg/#donations)
Expand Down
61 changes: 61 additions & 0 deletions packages/ffmpeg-static/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# ffmpeg-static

Static **[ffmpeg](https://ffmpeg.org) binaries for macOS, Linux, Windows.**

Supports macOS (64-bit and arm64), Linux (32 and 64-bit, armhf, arm64), Windows (32 and 64-bit). [The ffmpeg version currently used is `5.0.1`.](https://github.com/eugeneware/ffmpeg-static/releases/tag/b5.0.1)

[![npm version](https://img.shields.io/npm/v/ffmpeg-static.svg)](https://www.npmjs.com/package/ffmpeg-static)
![minimum Node.js version](https://img.shields.io/node/v/ffmpeg-static.svg)

*Note:* The version of `ffmpeg-static` follows [SemVer](http://semver.org). When releasing new versions, **we do *not* consider breaking changes in `ffmpeg` itself**, but only the JS interface (see below). For example, `ffmpeg-static@4.5.0` might download ffmpeg `5.0`. To prevent an `ffmpeg-static` upgrade downloading backwards-incompatible ffmpeg versions, [use a strict version range](https://docs.npmjs.com/files/package.json#dependencies) for it or use a [lockfile](https://docs.npmjs.com/files/package-lock.json).

Also check out [`node-ffmpeg-installer`](https://github.com/kribblo/node-ffmpeg-installer)!

## Installation

``` bash
$ npm install ffmpeg-static
```

*Note:* During installation, it will download the appropriate `ffmpeg` binary from the [`b5.0.1` GitHub release](https://github.com/eugeneware/ffmpeg-static/releases/tag/b5.0.1). Use and distribution of the binary releases of `ffmpeg` are covered by their respective license.

### Custom binaries url

By default, the `ffmpeg` binary will get downloaded from `https://github.com/eugeneware/ffmpeg-static/releases/download`. To customise this, e.g. when using a mirror, set the `FFMPEG_BINARIES_URL` environment variable.

```shell
export FFMPEG_BINARIES_URL=https://cdn.npmmirror.com/binaries/ffmpeg-static
npm install ffmpeg-static
```

### Electron & other cross-platform packaging tools

Because `ffmpeg-static` will download a binary specific to the OS/platform, you need to purge `node_modules` before (re-)packaging your app *for a different OS/platform* ([read more in #35](https://github.com/eugeneware/ffmpeg-static/issues/35#issuecomment-630225392)).

## Example Usage

Returns the path of a statically linked ffmpeg binary on the local filesystem.

``` js
const pathToFfmpeg = require('ffmpeg-static')
console.log(pathToFfmpeg)
// /Users/j/playground/node_modules/ffmpeg-static/ffmpeg
```

Check the [example script](example.js) for a more thorough example.

## Sources of the binaries

The binaries downloaded by `ffmpeg-static` are from these locations:

- [Windows x64 builds](https://www.gyan.dev/ffmpeg/builds/)
- [Windows x86 builds](https://github.com/sudo-nautilus/FFmpeg-Builds-Win32/)
- [Linux x64/x86/ARM/ARM64 builds](https://johnvansickle.com/ffmpeg/)
- macOS [x64 (Intel)](https://evermeet.cx/pub/ffmpeg/) & [ARM64 (Apple Silicon)](https://osxexperts.net/) builds

## Show your support

This npm package includes statically linked binaries that are produced by the following individuals. Please consider supporting and donating to them who have been providing quality binary builds for many years:

- **Linux builds**: [John Van Sickle](https://www.johnvansickle.com/ffmpeg/)
- **macOS builds**: [Helmut K. C. Tessarek](https://evermeet.cx/ffmpeg/#donations)
49 changes: 49 additions & 0 deletions packages/ffmpeg-static/example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env node
'use strict'

const {resolve} = require('path')
const shell = require('any-shell-escape')
const {exec} = require('child_process')
const pathToFfmpeg = require('.')

const argv = process.argv.slice(2)
if (argv.includes('-h') || argv.includes('--help')) {
console.info(`
This is just a simple CLI wrapper around the powerful ffmpeg CLI tool.
This script just showcases how to use ffmpeg-static; It wouldn't make
sense to hide a flexible tool behind a limited wrapper script.
Usage:
./example.js <src> <dest>
Example:
./example.js src-audio-file.m4a dest-audio-file.mp3
`)
process.exit(0)
}

const [src, dest] = argv
if (!src) {
console.error('Missing <src> positional argument.')
process.exit(1)
}
if (!dest) {
console.error('Missing <dest> positional argument.')
process.exit(1)
}

const makeMp3 = shell([
pathToFfmpeg,
'-y', '-v', 'error',
'-i', resolve(process.cwd(), src),
'-acodec', 'mp3',
'-format', 'mp3',
resolve(process.cwd(), dest),
])

exec(makeMp3, (err) => {
if (err) {
console.error(err)
process.exit(1)
} else {
console.info('done!')
}
})
59 changes: 59 additions & 0 deletions packages/ffprobe-static/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# ffprobe-static

Static **ffprobe (from the [ffmpeg](https://ffmpeg.org) project) binaries for macOS, Linux, Windows.**

Supports macOS (64-bit and arm64), Linux (32 and 64-bit, armhf, arm64), Windows (32 and 64-bit). [The ffmpeg version currently used is `5.0.1`.](https://github.com/eugeneware/ffprobe-static/releases/tag/b5.0.1)

[![npm version](https://img.shields.io/npm/v/ffprobe-static.svg)](https://www.npmjs.com/package/ffprobe-static)
![minimum Node.js version](https://img.shields.io/node/v/ffprobe-static.svg)

*Note:* The version of `ffprobe-static` follows [SemVer](http://semver.org). When releasing new versions, **we do *not* consider breaking changes in `ffprobe` itself**, but only the JS interface (see below). For example, `ffprobe-static@4.5.0` might download ffprobe `5.0`. To prevent an `ffprobe-static` upgrade downloading backwards-incompatible ffprobe versions, [use a strict version range](https://docs.npmjs.com/files/package.json#dependencies) for it or use a [lockfile](https://docs.npmjs.com/files/package-lock.json).

## Installation

``` bash
$ npm install ffprobe-static
```

*Note:* During installation, it will download the appropriate `ffprobe` binary from the [`b5.0.1` GitHub release](https://github.com/eugeneware/ffprobe-static/releases/tag/b5.0.1). Use and distribution of the binary releases of `ffprobe` are covered by their respective license.

### Custom binaries url

By default, the `ffprobe` binary will get downloaded from `https://github.com/eugeneware/ffprobe-static/releases/download`. To customise this, e.g. when using a mirror, set the `FFPROBE_BINARIES_URL` environment variable.

```shell
export FFPROBE_BINARIES_URL=https://cdn.npmmirror.com/binaries/ffprobe-static
npm install ffprobe-static
```

### Electron & other cross-platform packaging tools

Because `ffprobe-static` will download a binary specific to the OS/platform, you need to purge `node_modules` before (re-)packaging your app *for a different OS/platform* ([read more in #35](https://github.com/eugeneware/ffprobe-static/issues/35#issuecomment-630225392)).

## Example Usage

Returns the path of a statically linked ffprobe binary on the local filesystem.

``` js
const pathToFfprobe = require('ffprobe-static');
console.log(pathToFfprobe)
// /Users/j/playground/node_modules/ffprobe-static/ffprobe
```

Check the [example script](example.js) for a more thorough example.

## Sources of the binaries

The binaries downloaded by `ffprobe-static` are from these locations:

- [Windows x64 builds](https://www.gyan.dev/ffmpeg/builds/)
- [Windows x86 builds](https://github.com/sudo-nautilus/FFmpeg-Builds-Win32/)
- [Linux x64/x86/ARM/ARM64 builds](https://johnvansickle.com/ffmpeg/)
- macOS [x64 (Intel)](https://evermeet.cx/pub/ffmpeg/) & [ARM64 (Apple Silicon)](https://osxexperts.net/) builds

## Show your support

This npm package includes statically linked binaries that are produced by the following individuals. Please consider supporting and donating to them who have been providing quality binary builds for many years:

- **Linux builds**: [John Van Sickle](https://www.johnvansickle.com/ffmpeg/)
- **macOS builds**: [Helmut K. C. Tessarek](https://evermeet.cx/ffmpeg/#donations)
40 changes: 40 additions & 0 deletions packages/ffprobe-static/example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env node
'use strict'

const {resolve} = require('path')
const shell = require('any-shell-escape')
const {exec} = require('child_process')
const pathToFfprobe = require('.')

const argv = process.argv.slice(2)
if (argv.includes('-h') || argv.includes('--help')) {
console.info(`
This is just a simple CLI wrapper around the powerful ffprobe CLI tool.
This script just showcases how to use ffprobe-static; It wouldn't make
sense to hide a flexible tool behind a limited wrapper script.
Usage:
./example.js <file>
Example:
./example.js audio-file.m4a
`)
process.exit(0)
}

const [file, dest] = argv
if (!file) {
console.error('Missing <file> positional argument.')
process.exit(1)
}

const inspectAsJson = shell([
pathToFfprobe,
'-show_format', '-show_streams',
'-of', 'json',
resolve(process.cwd(), file),
])

exec(inspectAsJson, (err) => {
if (!err) return;
console.error(err)
process.exit(1)
})
39 changes: 24 additions & 15 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,34 @@

const {ok, strictEqual} = require('assert')
const {isAbsolute} = require('path')
const fs = require('fs')
const {statSync, accessSync, constants} = require('fs')
const {spawnSync} = require('child_process')
const shell = require('any-shell-escape')
const ffmpegPath = require('.')

console.info('TAP version 12')
console.info('1..4')
{
const ffmpegPath = require('./packages/ffmpeg-static')

ok(isAbsolute(ffmpegPath))
console.info('ok 1 - ffmpeg path is absolute')
ok(isAbsolute(ffmpegPath), 'ffmpeg path must be absolute')
ok(statSync(ffmpegPath).isFile(ffmpegPath), `${ffmpegPath} must be a file`)
accessSync(ffmpegPath, constants.X_OK, `${ffmpegPath} must be executable`)

ok(fs.statSync(ffmpegPath).isFile(ffmpegPath))
console.info(`ok 2 - ${ffmpegPath} is a file`)
const {status} = spawnSync(ffmpegPath, ['--help'], {
stdio: ['ignore', 'ignore', 'pipe'], // stdin, stdout, stderr
})
strictEqual(status, 0, `\`${ffmpegPath} --help\` exits with 0`)
}

fs.accessSync(ffmpegPath, fs.constants.X_OK)
console.info(`ok 3 - ${ffmpegPath} is executable`)
{
const ffprobePath = require('./packages/ffprobe-static')

const {status} = spawnSync(ffmpegPath, ['--help'], {
stdio: ['ignore', 'ignore', 'pipe'], // stdin, stdout, stderr
})
strictEqual(status, 0)
console.info(`ok 4 - \`${ffmpegPath} --help\` works`)
ok(isAbsolute(ffprobePath), 'ffprobe path must be absolute')
ok(statSync(ffprobePath).isFile(ffprobePath), `${ffprobePath} must be a file`)
accessSync(ffprobePath, constants.X_OK, `${ffprobePath} must be executable`)

const {status} = spawnSync(ffprobePath, ['--help'], {
stdio: ['ignore', 'ignore', 'pipe'], // stdin, stdout, stderr
})
strictEqual(status, 0, `\`${ffprobePath} --help\` exits with 0`)
}

console.info('seems to work ✔︎')

0 comments on commit c90e794

Please sign in to comment.