handbrake-js

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

npm install handbrake-js
50 downloads in the last week
74 downloads in the last month

NPM version Build Status Dependency Status Analytics

handbrake-js

Handbrake-js is an alternative, cross-platform distrubution of HandbrakeCLI (v0.9.9) adding Javascript, streaming and improved command-line interfaces.

Command line use

Install

Install Node.js, then run

$ npm install -g handbrake-js

Mac / Linux users may need to run the above with sudo

Usage

Call handbrake as you would HandbrakeCLI, using all the usual options:

$ handbrake --input "Ballroom Bangra.avi" --output "Ballroom Bangra.mp4" --preset Normal

Notifications

During long-running encodes, Mac users can receive system notifications every three minutes displaying current progress. To enable this, ensure terminal-notifier is installed.

Install via homebrew:

$ brew install terminal-notifier

Install via RubyGems:

$ [sudo] gem install terminal-notifier

As a library

Install

$ npm install handbrake-js --save

HandbrakeCLI installation

On Windows and Mac OSX installing handbrake-js automatically installs the correct HandbrakeCLI binary for your platform. Ubuntu users should additionally run:

$ sudo npm -g run-script handbrake-js ubuntu-setup

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.

NPM

npm loves you