Skip to content

Commit

Permalink
ok, finally this will be @mmomtchev/ffmpeg
Browse files Browse the repository at this point in the history
  • Loading branch information
mmomtchev committed Dec 8, 2023
1 parent ad3d1e3 commit 5a4ac2d
Show file tree
Hide file tree
Showing 22 changed files with 49 additions and 49 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ jobs:
python-version: "3.11"
- name: Set up the unit tests
run: |
curl https://codeload.github.com/mmomtchev/ffmpeg.js/zip/refs/tags/v${{ github.event.inputs.version }} --output repo.zip
curl https://codeload.github.com/mmomtchev/ffmpeg/zip/refs/tags/v${{ github.event.inputs.version }} --output repo.zip
unzip repo.zip
mv ffmpeg.js-${{ github.event.inputs.version }}/test .
mv ffmpeg-${{ github.event.inputs.version }}/test .
npm install @types/chai @types/mocha @types/node chai magickwand.js mocha ts-node tsconfig-paths
- name: Install from npm
run: npm i ffmpeg.js@${{ github.event.inputs.version }}
run: npm i @mmomtchev/ffmpeg@${{ github.event.inputs.version }}
- name: Run the unit tests
run: |
cd test
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `ffmpeg.js` Changelog
# `@mmomtchev/ffmpeg` Changelog

All notable changes to this project will be documented in this file.

Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# ffmpeg (w/avcpp) bindings for Node.js

`ffmpeg.js` is a JavaScript wrapper around [`avcpp`](https://github.com/h4tr3d/avcpp) which is a C++ wrapper around the low-level C API of [`ffmpeg`](https://ffmpeg.org/).
`ffmpeg` is a JavaScript wrapper around [`avcpp`](https://github.com/h4tr3d/avcpp) which is a C++ wrapper around the low-level C API of [`ffmpeg`](https://ffmpeg.org/).

# Current status

The project has an alpha version published to `npm` and basic video and audio demultiplexing, transcoding and multiplexing are functional.

You should be aware that `ffmpeg` is a low-level C API and it is very unsafe to use - trying to interpret 720p as 1080p will always end up with a segfault. `avcpp` adds a semi-safe layer on top of it, but mismatching stream parameters will still lead to a segfault. `ffmpeg.js` should never segfault if all the parameters are correctly checked and set up - but may easily segfault if these are mismatched - or if the asynchronous methods are reentered.
You should be aware that `ffmpeg` is a low-level C API and it is very unsafe to use - trying to interpret 720p as 1080p will always end up with a segfault. `avcpp` adds a semi-safe layer on top of it, but mismatching stream parameters will still lead to a segfault. `ffmpeg` should never segfault if all the parameters are correctly checked and set up - but may easily segfault if these are mismatched - or if the asynchronous methods are reentered.

Producing a completely safe wrapper that never segfaults, no matter what the user does, is a gargantuan task that is currently not planned.

Expand All @@ -22,20 +22,20 @@ If you need to access the actual pixel data or audio samples, then, depending on

## Install

`ffmpeg.js` comes with prebuilt binaries for Windows, Linux and macOS on x64 platforms.
`ffmpeg` comes with prebuilt binaries for Windows, Linux and macOS on x64 platforms.

You can rebuild it from source using `node-pre-gyp` which will be automatically called by `npm install`. This will pull and build `ffmpeg` using `conan` which will leave a very large directory `${HOME}/.conan` which can be safely deleted.

## Streams API

The easiest way to use `ffmpeg.js` is the high-level streams API.
The easiest way to use `ffmpeg` is the high-level streams API.

### Quickstart

A quick example for generalized video transcoding using the streams API.

```ts
import { Muxer, Demuxer, VideoDecoder, VideoEncoder, Discarder, VideoTransform, VideoStreamDefinition } from 'ffmpeg.js/stream';
import { Muxer, Demuxer, VideoDecoder, VideoEncoder, Discarder, VideoTransform, VideoStreamDefinition } from '@mmomtchev/ffmpeg/stream';

// Create a Demuxer - a Demuxer is an object that has multiple ReadableStream,
// it decodes the input container format and emits compressed data
Expand Down Expand Up @@ -104,11 +104,11 @@ input.on('ready', () => {
### More examples

You should start by looking at the unit tests:
* [`transcode.test.ts`](https://github.com/mmomtchev/ffmpeg.js/blob/main/test/transcode.test.ts) contains simple examples for transcoding audio and video
* [`extract.test.ts`](https://github.com/mmomtchev/ffmpeg.js/blob/main/test/extract.test.ts) contains a simple example for extracting a still from a video and importing it in ImageMagick
* [`encode.test.ts`](https://github.com/mmomtchev/ffmpeg.js/blob/main/test/encode.test.ts) contains a simple example for producing a video from stills using ImageMagick
* [`rescale.test.ts`](https://github.com/mmomtchev/ffmpeg.js/blob/main/test/rescale.test.ts) contains a simple example for rescaling/resampling a video using ffmpeg's built-in `libswscale`
* [`resample.test.ts`](https://github.com/mmomtchev/ffmpeg.js/blob/main/test/resample.test.ts) contains a simple example for resampling audio using ffmpeg's built-in `libswresample`
* [`transcode.test.ts`](https://github.com/mmomtchev/ffmpeg/blob/main/test/transcode.test.ts) contains simple examples for transcoding audio and video
* [`extract.test.ts`](https://github.com/mmomtchev/ffmpeg/blob/main/test/extract.test.ts) contains a simple example for extracting a still from a video and importing it in ImageMagick
* [`encode.test.ts`](https://github.com/mmomtchev/ffmpeg/blob/main/test/encode.test.ts) contains a simple example for producing a video from stills using ImageMagick
* [`rescale.test.ts`](https://github.com/mmomtchev/ffmpeg/blob/main/test/rescale.test.ts) contains a simple example for rescaling/resampling a video using ffmpeg's built-in `libswscale`
* [`resample.test.ts`](https://github.com/mmomtchev/ffmpeg/blob/main/test/resample.test.ts) contains a simple example for resampling audio using ffmpeg's built-in `libswresample`

## Supported pixel and audio formats

Expand Down
2 changes: 1 addition & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
'copies': [
{
'files': [
'<(PRODUCT_DIR)/ffmpeg.js.node'
'<(PRODUCT_DIR)/ffmpeg.node'
],
'destination': '<(module_path)'
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ffmpeg.js",
"name": "@mmomtchev/ffmpeg",
"version": "0.9.0",
"description": "avcpp (ffmpeg) bindings for Node.js",
"description": "Full native ffmpeg bindings for Node.js with Streams support",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
Expand All @@ -15,7 +15,7 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/mmomtchev/ffmpeg.js.git"
"url": "git+https://github.com/mmomtchev/ffmpeg.git"
},
"keywords": [
"node.js",
Expand All @@ -25,26 +25,26 @@
"codec"
],
"binary": {
"module_name": "ffmpeg.js",
"module_name": "ffmpeg",
"module_path": "./lib/binding/{platform}-{arch}",
"remote_path": "v{version}",
"host": "https://github.com/mmomtchev/ffmpeg.js/releases/download/",
"host": "https://github.com/mmomtchev/ffmpeg/releases/download/",
"package_name": "{platform}-{arch}.tar.gz",
"hosting": {
"provider": "github",
"repo": "mmomtchev/ffmpeg.js"
"repo": "mmomtchev/ffmpeg"
}
},
"author": "Momtchil Momtchev <[email protected]>",
"license": "ISC",
"bugs": {
"url": "https://github.com/mmomtchev/ffmpeg.js/issues"
"url": "https://github.com/mmomtchev/ffmpeg/issues"
},
"exports": {
".": "./lib/index.js",
"./stream": "./lib/Stream.js"
},
"homepage": "https://github.com/mmomtchev/ffmpeg.js#readme",
"homepage": "https://github.com/mmomtchev/ffmpeg#readme",
"dependencies": {
"@mapbox/node-pre-gyp": "^1.0.11",
"nobind17": "^1.1.1",
Expand Down
2 changes: 1 addition & 1 deletion src/lib/AudioDecoder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Transform } from 'node:stream';
import ffmpeg from 'ffmpeg.js';
import ffmpeg from '@mmomtchev/ffmpeg';
import { AudioStreamDefinition, MediaStream } from './MediaStream';
import { TransformCallback } from 'stream';

Expand Down
2 changes: 1 addition & 1 deletion src/lib/AudioEncoder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Transform } from 'node:stream';
import ffmpeg from 'ffmpeg.js';
import ffmpeg from '@mmomtchev/ffmpeg';
import { AudioStreamDefinition, MediaStream } from './MediaStream';
import { TransformCallback } from 'stream';

Expand Down
2 changes: 1 addition & 1 deletion src/lib/AudioTransform.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Transform, TransformOptions, TransformCallback } from 'node:stream';
import ffmpeg from 'ffmpeg.js';
import ffmpeg from '@mmomtchev/ffmpeg';
import { AudioStreamDefinition } from './MediaStream';

export const verbose = (process.env.DEBUG_AUDIO_TRANSFORM || process.env.DEBUG_ALL) ? console.debug.bind(console) : () => undefined;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Demuxer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EventEmitter, ReadableOptions } from 'node:stream';
import ffmpeg from 'ffmpeg.js';
import ffmpeg from '@mmomtchev/ffmpeg';
import { EncodedMediaReadable } from './MediaStream';

const { FormatContext } = ffmpeg;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Muxer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EventEmitter, WritableOptions } from 'node:stream';
import { EncodedMediaWritable, MediaEncoder, isAudioDefinition, isVideoDefinition } from './MediaStream';
import ffmpeg from 'ffmpeg.js';
import ffmpeg from '@mmomtchev/ffmpeg';

const { FormatContext, OutputFormat } = ffmpeg;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/VideoDecoder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Transform } from 'node:stream';
import ffmpeg from 'ffmpeg.js';
import ffmpeg from '@mmomtchev/ffmpeg';
import { VideoStreamDefinition, MediaStream } from './MediaStream';
import { TransformCallback } from 'stream';

Expand Down
2 changes: 1 addition & 1 deletion src/lib/VideoEncoder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Transform } from 'node:stream';
import ffmpeg from 'ffmpeg.js';
import ffmpeg from '@mmomtchev/ffmpeg';
import { VideoStreamDefinition, MediaStream } from './MediaStream';
import { TransformCallback } from 'stream';

Expand Down
2 changes: 1 addition & 1 deletion src/lib/VideoTransform.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Transform, TransformOptions, TransformCallback } from 'node:stream';
import ffmpeg from 'ffmpeg.js';
import ffmpeg from '@mmomtchev/ffmpeg';
import { VideoStreamDefinition } from './MediaStream';

export interface VideoTransformOptions extends TransformOptions {
Expand Down
4 changes: 2 additions & 2 deletions test/demuxer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import * as path from 'node:path';

import { assert } from 'chai';

import ffmpeg from 'ffmpeg.js';
import { Demuxer, AudioDecoder, VideoDecoder } from 'ffmpeg.js/stream';
import ffmpeg from '@mmomtchev/ffmpeg';
import { Demuxer, AudioDecoder, VideoDecoder } from '@mmomtchev/ffmpeg/stream';

ffmpeg.setLogLevel(process.env.DEBUG_FFMPEG ? ffmpeg.AV_LOG_DEBUG : ffmpeg.AV_LOG_ERROR);

Expand Down
4 changes: 2 additions & 2 deletions test/encode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import * as path from 'node:path';
import * as fs from 'node:fs';
import { Magick } from 'magickwand.js';

import ffmpeg from 'ffmpeg.js';
import { VideoEncoder, Muxer } from 'ffmpeg.js/stream';
import ffmpeg from '@mmomtchev/ffmpeg';
import { VideoEncoder, Muxer } from '@mmomtchev/ffmpeg/stream';

ffmpeg.setLogLevel(process.env.DEBUG_FFMPEG ? ffmpeg.AV_LOG_DEBUG : ffmpeg.AV_LOG_ERROR);

Expand Down
4 changes: 2 additions & 2 deletions test/extract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { Magick } from 'magickwand.js';

import { assert } from 'chai';

import ffmpeg from 'ffmpeg.js';
import { Demuxer, VideoDecoder, Discarder } from 'ffmpeg.js/stream';
import ffmpeg from '@mmomtchev/ffmpeg';
import { Demuxer, VideoDecoder, Discarder } from '@mmomtchev/ffmpeg/stream';

ffmpeg.setLogLevel(process.env.DEBUG_FFMPEG ? ffmpeg.AV_LOG_DEBUG : ffmpeg.AV_LOG_ERROR);

Expand Down
4 changes: 2 additions & 2 deletions test/resample.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import * as fs from 'node:fs';

import { assert } from 'chai';

import ffmpeg from 'ffmpeg.js';
import { Muxer, Demuxer, AudioDecoder, AudioEncoder, AudioTransform, Discarder, AudioStreamDefinition } from 'ffmpeg.js/stream';
import ffmpeg from '@mmomtchev/ffmpeg';
import { Muxer, Demuxer, AudioDecoder, AudioEncoder, AudioTransform, Discarder, AudioStreamDefinition } from '@mmomtchev/ffmpeg/stream';

ffmpeg.setLogLevel(process.env.DEBUG_FFMPEG ? ffmpeg.AV_LOG_DEBUG : ffmpeg.AV_LOG_ERROR);

Expand Down
4 changes: 2 additions & 2 deletions test/rescale.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import * as fs from 'node:fs';

import { assert } from 'chai';

import ffmpeg from 'ffmpeg.js';
import { Muxer, Demuxer, VideoDecoder, VideoEncoder, Discarder, VideoTransform, VideoStreamDefinition } from 'ffmpeg.js/stream';
import ffmpeg from '@mmomtchev/ffmpeg';
import { Muxer, Demuxer, VideoDecoder, VideoEncoder, Discarder, VideoTransform, VideoStreamDefinition } from '@mmomtchev/ffmpeg/stream';

ffmpeg.setLogLevel(process.env.DEBUG_FFMPEG ? ffmpeg.AV_LOG_DEBUG : ffmpeg.AV_LOG_ERROR);

Expand Down
4 changes: 2 additions & 2 deletions test/transcode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import * as fs from 'node:fs';

import { assert } from 'chai';

import ffmpeg from 'ffmpeg.js';
import { Muxer, Demuxer, VideoDecoder, VideoEncoder, AudioDecoder, AudioEncoder, Discarder } from 'ffmpeg.js/stream';
import ffmpeg from '@mmomtchev/ffmpeg';
import { Muxer, Demuxer, VideoDecoder, VideoEncoder, AudioDecoder, AudioEncoder, Discarder } from '@mmomtchev/ffmpeg/stream';

ffmpeg.setLogLevel(process.env.DEBUG_FFMPEG ? ffmpeg.AV_LOG_DEBUG : ffmpeg.AV_LOG_ERROR);

Expand Down
4 changes: 2 additions & 2 deletions test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
"outDir": "lib",
"declaration": true,
"paths": {
"ffmpeg.js": [
"@mmomtchev/ffmpeg": [
"../lib"
],
"ffmpeg.js/stream": [
"@mmomtchev/ffmpeg/stream": [
"../lib/Stream"
]
}
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
"outDir": "lib",
"declaration": true,
"paths": {
"ffmpeg.js": [
"@mmomtchev/ffmpeg": [
"./lib"
],
"ffmpeg.js/stream": [
"@mmomtchev/ffmpeg/stream": [
"./lib/Stream"
]
}
Expand Down

0 comments on commit 5a4ac2d

Please sign in to comment.