-
-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ff{mpeg,probe}-static subpackages: add tests ✅, example code & readme 📝
- Loading branch information
Showing
6 changed files
with
236 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!') | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters