From 7d6c44b9801c61f751097c8e09b256f42a6eec82 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Fri, 2 Dec 2022 20:42:47 +0100 Subject: [PATCH] =?UTF-8?q?ff{mpeg,probe}-static=20subpackages:=20add=20te?= =?UTF-8?q?sts=20=E2=9C=85,=20example=20code=20&=20readme=20=F0=9F=93=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixes #19 closes #113 Co-Authored-By: Jannis R --- README.md | 48 ++--------------------- packages/ffmpeg-static/README.md | 61 ++++++++++++++++++++++++++++++ packages/ffmpeg-static/example.js | 49 ++++++++++++++++++++++++ packages/ffprobe-static/README.md | 59 +++++++++++++++++++++++++++++ packages/ffprobe-static/example.js | 40 ++++++++++++++++++++ test.js | 39 +++++++++++-------- 6 files changed, 236 insertions(+), 60 deletions(-) create mode 100644 packages/ffmpeg-static/README.md create mode 100755 packages/ffmpeg-static/example.js create mode 100644 packages/ffprobe-static/README.md create mode 100755 packages/ffprobe-static/example.js diff --git a/README.md b/README.md index 01f2cdb..40e254f 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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) diff --git a/packages/ffmpeg-static/README.md b/packages/ffmpeg-static/README.md new file mode 100644 index 0000000..6b41dc4 --- /dev/null +++ b/packages/ffmpeg-static/README.md @@ -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) diff --git a/packages/ffmpeg-static/example.js b/packages/ffmpeg-static/example.js new file mode 100755 index 0000000..d5de1e7 --- /dev/null +++ b/packages/ffmpeg-static/example.js @@ -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 +Example: + ./example.js src-audio-file.m4a dest-audio-file.mp3 +`) + process.exit(0) +} + +const [src, dest] = argv +if (!src) { + console.error('Missing positional argument.') + process.exit(1) +} +if (!dest) { + console.error('Missing 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!') + } +}) diff --git a/packages/ffprobe-static/README.md b/packages/ffprobe-static/README.md new file mode 100644 index 0000000..a017099 --- /dev/null +++ b/packages/ffprobe-static/README.md @@ -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) diff --git a/packages/ffprobe-static/example.js b/packages/ffprobe-static/example.js new file mode 100755 index 0000000..686c702 --- /dev/null +++ b/packages/ffprobe-static/example.js @@ -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 +Example: + ./example.js audio-file.m4a +`) + process.exit(0) +} + +const [file, dest] = argv +if (!file) { + console.error('Missing 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) +}) diff --git a/test.js b/test.js index eac83df..2e1e0c8 100644 --- a/test.js +++ b/test.js @@ -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 ✔︎')