JSPM

  • Created
  • Published
  • Downloads 966
  • Score
    100M100P100Q105030F

Handbrake for node.js. Brings video encoding.

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 Handbrake for node.js, funnily enough. It aspires to do two things:

  1. provide a lean and stable foundation for building video transcoding software in node.js
  2. enhance the vanilla HandbrakeCLI command-line experience with some new features:
    • Cleaner output, live updating statistics
    • Improved user input validation
    • Clear explainations when user input is invalid

Compatible Platforms

Tested on Mac OSX, Ubuntu 14, Windows XP, Windows 7 and Windows 8.1.

Ubuntu 14.04 notice: Transcoding to MP4 fails on Ubuntu since 14.04 for this reason.

##Installation ###System Requirements Just node.js. Every else is installed automatically.

###As a library Move into your project directory then run:

$ npm install handbrake-js --save

Mac / Linux users may need to run with sudo.

Now you can begin encoding from your app.

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

hbjs.spawn({ input: "dope shit.avi", output: "dope shit.m4v" })
  .on("error", function(err){
    // invalid user input, no video found etc
  })
  .on("progress", function(progress){
    console.log(
      "Percent complete: %s, ETA: %s", 
      progress.percentComplete, 
      progress.eta
    );
  });

###As a command-line app From any directory run the following:

$ npm install -g handbrake-js

Mac / Linux users may need to run with sudo.

Now, you can call handbrake as you would HandbrakeCLI, using all the usual options. By default, just statistics are output, passing --verbose prints the raw HandbrakeCLI output. This command will transcode an AVI to the more universal H.264 (mp4):

$ handbrake --input "some episode.avi" --output "some episode.mp4" --preset Normal
Task      % done     FPS       Avg FPS   ETA
Encoding  1.07       131.76    158.12    00h21m11s

#API Reference Handbrake for node.js.

Example

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

Members

##hbjs.cliOptions Command-line-args option definitions, useful when building a CLI.

Type: array
##hbjs.spawn(options) Spawns a HandbrakeCLI process with the supplied options, returning an instance of Handbrake on which you can listen for events.

Params

  • options Object | Array - Options to pass directly to HandbrakeCLI

Returns: Handbrake - A Handbrake instance
Example

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

hbjs.spawn(options)
    .on("error", console.error)
    .on("output", console.log);

##hbjs.exec(options, [onComplete]) 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 - 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 hbjs = require("handbrake-js");

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

##class: hbjs~Handbrake A thin wrapper on the handbrakeCLI child_process handle. An instance of this class is returned by hbjs.spawn().

Extends: EventEmitter
Members

###handbrake.output A String containing all handbrakeCLI output

###handbrake.options the options HandbrakeCLI was spawned with

###event: "start" Fired as HandbrakeCLI is launched. Nothing has happened yet.

###event: "begin" Fired when encoding begins. If you're expecting an encode and this never fired, something went wrong.

###event: "progress" Fired at regular intervals passing a progress object containing:

  • taskNumber Number current task index
  • taskCount Number total tasks in the queue
  • percentComplete Number
  • fps Number Frames per second
  • avgFps Number Average frames per second
  • eta String Estimated time until completion
  • task String Task description, either "Encoding" or "Muxing"

###event: "output" An aggregate of stdout and stderr output from the underlying HandbrakeCLI process.

###event: "error" All operational exceptions are delivered via this event. Passes an Error instance, the name value of which will be one of:

  • HandbrakeCLINotFound
  • HandbrakeCLIError
  • NoTitleFound
  • HandbrakeCLICrash
  • ValidationError

###event: "end" Fired on successful completion of an encoding task. Always follows a begin event, with some progress in between.

###event: "complete" Fired when HandbrakeCLI exited cleanly. This does not necessarily mean your encode completed as planned..

documented by jsdoc-to-markdown.