JSPM

  • Created
  • Published
  • Downloads 966
  • Score
    100M100P100Q107218F

An alternative, cross-platform distrubution of HandbrakeCLI (v0.9.9) adding javascript, streaming and improved command-line interfaces.

Package Exports

  • handbrake-js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (handbrake-js) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

view on npm npm module downloads per month Build Status Dependency Status Analytics

handbrake-js

Handbrake-js is a node.js module wrapping Handbrake (v0.9.9) with a Javascript API, documented below. It's primary purpose is to bring video transcoding to your app.

Installation

All 3rd party dependencies, including HandbrakeCLI itself, are installed automatically. The only system requirement is node.js, which you should install first.

Mac / Linux users may need to run either of the following commands with sudo.

As a library

Move into your project directory then run:

$ npm install handbrake-js --save

As a command-line app

From any directory run the following:

$ npm install -g handbrake-js

Now, you can call handbrake as you would HandbrakeCLI, using all the usual options. This command will transcode an AVI to the more universal H.264 (mp4):

$ handbrake --input "some episode.avi" --output "some episode.mp4" --preset Normal

API Documentation

#handbrake-js

An npm distribution of HandbrakeCLI for command line or library use.

##Methods

###exec

Runs HandbrakeCLI with the supplied options calling the supplied callback on completion. The exec method is best suited for short duration tasks where you can wait until completion for the output.

Params:

  • options Object | Thing | Array

    Options to pass directly to HandbrakeCLI

  • onComplete Function

    If passed, onComplete(err, stdout, stderr) will be called on completion, stdout and stderr being strings containing the HandbrakeCLI output.

####Example

var handbrake = require("handbrake-js");

handbrake.exec({ preset-list: true }, function(err, stdout, stderr){
    if (err) throw err;
    console.log(stdout);
});

###spawn

Spawns a HandbrakeCLI process with the supplied options, returning a handle on the running process.

Returns: HandbrakeProcess - A handle on which you can listen for events on the Handbrake process.

Params:

  • options Object | Thing | Array

    Options to pass directly to HandbrakeCLI

####Example

var handbrake = require("handbrake-js");

var options = {
    input: "Eight Miles High.mov",
    output: "Eight Miles High.m4v",
    preset: "Normal"
};

handbrake.spawn(options)
    .on("error", function(err){
        console.log("ERROR: " + err.message);
    })
    .on("output", console.log);
    .on("progress", function(progress){
        console.log(progress.task + ": " + progress.percentComplete);
    })
    .on("complete", function(){ 
        console.log("Done!"); 
    });

#HandbrakeProcess

A handle on the Handbrake encoding process, used to catch and respond to run-time events.

##Events

###progress

Fired at regular intervals passing progress information

Params:

  • progress Object
    • percentComplete Number - Percentage complete
    • fps Number - Frames per second
    • avgFps Number - Average frames per second
    • eta String - Estimated time until completion
    • task String - Task description, e.g. "Encoding", "Scanning" etc.

###output

Passes the standard HandbrakeCLI output

Params:

  • output String

###terminated

Fired if Handbrake-js was killed by CTRL-C

###error

Fired if either HandbrakeCLI crashed or ran successfully but failed to find a valid title in the input video.

Params:

  • error Error

###complete

Fired on completion of a successful encode

#HandbrakeOptions

An options Thing describing all valid Handbrake option names, types and values.