0.4.4 • Published 3 years ago

ffmpeg-nodejs v0.4.4

Weekly downloads
1
License
MIT
Repository
github
Last release
3 years ago

FFmpeg-Nodejs

The project call the ffmpeg API by c language to achieve work which is video frame-to-picture and video recording, and call nodejs's napi to provide nodejs calls.

Preparation

# install nodejs
# https://github.com/nodesource/distributions/blob/master/README.md

# install compilers
npm i cmake-js -g

x install clang cmake g++
NOTE: x means your system package manager command, like apt, yum, dnf, or something else.

Develop

  1. learn javascript https://developer.mozilla.org/en-US/docs/Web/JavaScript

  2. learn nodejs https://nodejs.org/dist/latest/docs/api/

  3. learn c I suggest that you read the book "c primer plus"

  4. learn cmake https://cmake.org/cmake/help/latest/

  5. learn napi https://nodejs.org/dist/latest/docs/api/n-api.html

  6. learn cmake-js https://www.npmjs.com/package/cmake-js

  7. learn ffmpeg https://ffmpeg.org/ffmpeg.html

Compile

If you had not installed ffmpeg-dev whose version is 4.x, and libjpeg, you should install nasm and pkg-config first

Then compiling command is as follows:

npm install (or npm run compile or yarn build)

If you want more command, please see package.json scripts, and do not use cmake or make directly, because it not a pure c project, it is a NODEJS project.

note

windows not support c11 yet, so don't use it on windows!

Examples

const FFmpegNode = require('ffmpeg-nodejs');

const video_addr = ... ;
const dir = ... ;

const type = FFmpegNode.TYPE();
const targetType = type.JPEG;

const logLevel = FFmpegNode.LEVEL().INFO;

let suffix = ".yuv";
switch (targetType) {
    case type.YUV:
        suffix = ".yuv";
        break;
    case type.RGB:
        suffix = ".rgb";
        break;
    case type.JPEG:
        suffix = ".jpg";
        break;
}

let i = 0;

function runWithCallback() {
    let ffmpegNode = FFmpegNode.init(video_addr, 2, false, false, logLevel, 1, true);

    ffmpegNode.then((obj) => {
        console.info(targetType);
        obj.readImageStreamThreadly(100, targetType, 1);
        obj.on("data", (buffer) => {
            let now = new Date();
            let name = dir + "/tmp/images/buffer-" + now.getHours() + "-" + 
                        now.getMinutes() + "-" + now.getSeconds() + "-" + 
                        (i++) + suffix;
            fs.writeFileSync(name, buffer);
        });

        obj.on("error", (err) => {
            console.error(err);
            obj.close();
        });
    }).catch(err => {
        console.error(err);
    });
}

runWithCallback();
0.4.4

3 years ago

0.4.3

3 years ago

0.4.2

3 years ago

0.4.1

4 years ago

0.4.0

5 years ago

0.3.0

5 years ago

0.2.10

5 years ago

0.2.9

5 years ago

0.2.8

5 years ago

0.2.7

5 years ago

0.2.6

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

6 years ago

0.0.1

6 years ago