• Stars
    star
    566
  • Rank 78,774 (Top 2 %)
  • Language
    JavaScript
  • License
    Other
  • Created almost 12 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Video encoding / transcoding / converting for node.js

view on npm npm module downloads Gihub repo dependents Gihub package dependents Node.js CI js-standard-style

Upgraders, please read the release notes.

handbrake-js

Handbrake-js is Handbrake (v1.6.1) for node.js. It aspires to provide a lean and stable foundation for building video transcoding software in node.js.

HandBrake is a tool for converting video from nearly any format to a selection of modern, widely supported codecs. It can process most common multimedia files and any DVD or BluRay sources that do not contain any copy protection.

Outputs:

  • File Containers: .MP4(.M4V) and .MKV
  • Video Encoders: H.264(x264), H.265(x265) MPEG-4 and MPEG-2 (libav), VP8 (libvpx) and Theora(libtheora)
  • Audio Encoders: AAC, CoreAudio AAC/HE-AAC (OS X Only), MP3, Flac, AC3, or Vorbis
  • Audio Pass-thru: AC-3, DTS, DTS-HD, AAC and MP3 tracks

Read more about the features.

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. On Mac and Windows, every else is installed automatically. However on Linux, you must install HandbrakeCLI manually with these commands:

sudo add-apt-repository --yes ppa:stebbins/handbrake-releases
sudo apt-get update -qq
sudo apt-get install -qq handbrake-cli

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.

const hbjs = require('handbrake-js')

hbjs.spawn({ input: 'something.avi', output: 'something.m4v' })
  .on('error', err => {
    // invalid user input, no video found etc
  })
  .on('progress', 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

const hbjs = require('handbrake-js')

hbjs.spawn([options]) ⇒ Handbrake

Spawns a HandbrakeCLI process with the supplied options, returning an instance of Handbrake on which you can listen for events.

Kind: static method of handbrake-js

Param Type Description
[options] object Options to pass directly to HandbrakeCLI
[options.HandbrakeCLIPath] string Override the built-in HandbrakeCLI binary path.

Example

const hbjs = require('handbrake-js')

const options = {
  input: 'something.avi',
  output: 'something.mp4',
  preset: 'Normal',
  rotate: 1
}
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.

Kind: static method of handbrake-js

Param Type Description
options Object Options to pass directly to HandbrakeCLI
[options.HandbrakeCLIPath] string Override the built-in HandbrakeCLI binary path.
[onComplete] function If passed, onComplete(err, stdout, stderr) will be called on completion, stdout and stderr being strings containing the HandbrakeCLI output.

Example

const hbjs = require('handbrake-js')

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

hbjs.run(options) ⇒ Promise

Identical to hbjs.exec except it returns a promise, rather than invoke a callback. Use this when you don't need the progress events reported by hbjs.spawn. Fulfils with an object containing the output in two properties: stdout and stderr.

Kind: static method of handbrake-js

Param Type Description
options Object Options to pass directly to HandbrakeCLI
[options.HandbrakeCLIPath] string Override the built-in HandbrakeCLI binary path.

Example

const hbjs = require('handbrake-js')

async function start () {
  const result = await hbjs.run({ version: true })
  console.log(result.stdout)
  // prints 'HandBrake 1.3.0'
}

start().catch(console.error)

handbrake-js~Handbrake ⇐ EventEmitter

A handle on the HandbrakeCLI process. Emits events you can monitor to track progress. An instance of this class is returned by spawn.

Kind: inner class of handbrake-js
Extends: EventEmitter
Emits: start, begin, progress, output, error, end, complete, cancelled

handbrake.output : string

A string containing all handbrakeCLI output

Kind: instance property of Handbrake

handbrake.options : object

a copy of the options passed to spawn

Kind: instance property of Handbrake

handbrake.eError

All operational errors are emitted via the error event.

Kind: instance enum of Handbrake
Properties

Name Default Description
VALIDATION ValidationError Thrown if you accidentally set identical input and output paths (which would clobber the input file), forget to specifiy an output path and other validation errors.
INVALID_INPUT InvalidInput Thrown when the input file specified does not appear to be a video file.
INVALID_PRESET InvalidPreset Thrown when an invalid preset is specified.
OTHER Other Thrown if Handbrake crashes.
NOT_FOUND HandbrakeCLINotFound Thrown if the installed HandbrakeCLI binary has gone missing.

handbrake.cancel()

Cancel the encode, kill the underlying HandbrakeCLI process then emit a cancelled event.

Kind: instance method of Handbrake

"start"

Fired as HandbrakeCLI is launched. Nothing has happened yet.

Kind: event emitted by Handbrake

"begin"

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

Kind: event emitted by Handbrake

"progress" (progress)

Fired at regular intervals passing a progress object.

Kind: event emitted by Handbrake

Param Type Description
progress object details of encode progress
progress.taskNumber number current task index
progress.taskCount number total tasks in the queue
progress.percentComplete number percent complete
progress.fps number Frames per second
progress.avgFps number Average frames per second
progress.eta string Estimated time until completion
progress.task string Task description, either "Encoding" or "Muxing"

"output" (output)

Kind: event emitted by Handbrake

Param Type Description
output string An aggregate of stdout and stderr output from the underlying HandbrakeCLI process.

"error" (error)

Kind: event emitted by Handbrake

Param Type Description
error Error All operational exceptions are delivered via this event.
error.name eError The unique error identifier
error.message string Error description
error.errno string The HandbrakeCLI return code

"end"

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

Kind: event emitted by Handbrake

"complete"

Fired when HandbrakeCLI exited cleanly. This does not necessarily mean your encode completed as planned..

Kind: event emitted by Handbrake

"cancelled"

If .cancel() was called, this event is emitted once the underlying HandbrakeCLI process has closed.

Kind: event emitted by Handbrake


© 2013-23 Lloyd Brookes <[email protected]>.

Tested by test-runner. Documented by jsdoc-to-markdown.

Handbrake (Authors) is licensed by GNU General Public License Version 2.

More Repositories

1

command-line-args

A mature, feature-complete library to parse command-line options.
JavaScript
685
star
2

renamer

Rename files in bulk.
JavaScript
522
star
3

command-line-usage

A simple, data-driven module for creating a usage guide.
JavaScript
207
star
4

wordwrapjs

Word-wrapping for javascript.
JavaScript
157
star
5

array-back

Isomorphic, load-anywhere arrayify function
JavaScript
82
star
6

byte-size

Isomorphic function to convert a bytes value (e.g. 3456) to a human-readable string ('3.5 kB')
JavaScript
73
star
7

ansi-escape-sequences

A simple, isomorphic library containing all known terminal ansi escape codes and sequences.
JavaScript
65
star
8

sort-array

Isomorphic, load-anywhere function to sort an array by scalar, deep or computed values in any standard or custom order
JavaScript
42
star
9

command-line-commands

Add a git-like command interface to your app.
JavaScript
41
star
10

transition-to-from-auto

perform CSS transitions to and from 'auto'
JavaScript
27
star
11

feature-detect-es6

Detect which ES6 features are available.
JavaScript
24
star
12

table-layout

Styleable plain-text table generator. Useful for formatting console output.
JavaScript
23
star
13

typical

Isomorphic, functional type-checking for Javascript
JavaScript
20
star
14

walk-back

Walk up the directory tree until a specified path is found.
JavaScript
13
star
15

usage-stats

A minimal Google Analytics Measurement Protocol client for tracking statistics in shell and javascript applications
JavaScript
12
star
16

browse

Terminal commands to launch your preferred browser (or any app) in full-screen mode
AppleScript
11
star
17

object-get

Access nested property values at any depth with a simple expression.
JavaScript
11
star
18

array-tools

Lightweight, use-anywhere toolkit for working with array data
JavaScript
9
star
19

common-log-format

Stream transform - converts common log format to JSON
JavaScript
9
star
20

gfmt

A use-anywhere, github-flavoured-markdown table generator.
JavaScript
9
star
21

table-layout-cli

Format data in column or table layout on the command line.
JavaScript
6
star
22

renamer-case

Renamer plugin to set the case of a filename.
JavaScript
5
star
23

find-replace

Replace or remove multiple items in an array
JavaScript
5
star
24

object-to-spawn-args

Converts an options object to an array suitable for passing to child_process.spawn()
JavaScript
5
star
25

yuidoc2md

A yuidoc-to-markdown generator
JavaScript
4
star
26

fs-then-native

Fs with a native promise API
JavaScript
4
star
27

work

Command and Command Queue pattern implementations
JavaScript
3
star
28

grunt-boil

Generate files with template-driven content. A simple, more generic alternative to Jekyll and Assemble.
JavaScript
3
star
29

home-path

Cross-platform home directory retriever
JavaScript
3
star
30

composite-class

An isomorphic JavaScript class for building composite structures.
JavaScript
3
star
31

file-set

Expand a list of paths and glob expressions into three sets: "files", "directories" and "not existing".
JavaScript
3
star
32

renamer-index-dir

Replaces the `{{index}}` token, resetting the counter for each folder visited.
JavaScript
3
star
33

current-module-paths

JavaScript
2
star
34

stream-handlebars

Extends handlebars with a streaming interface for .compile().
JavaScript
2
star
35

filter-where

Filter an array using any combination of scalars, object queries, functions or regular expressions.
JavaScript
2
star
36

veelo

Optimise your video library using Handbrake
JavaScript
2
star
37

cache-point

Simple, filesystem-backed memoisation cache.
JavaScript
2
star
38

fsm-base

Finite State Machine for use as a base class or mix-in
JavaScript
2
star
39

string-tools

Some useful functions for working with strings
JavaScript
2
star
40

command-line-tool

common operations for command-line tools
JavaScript
2
star
41

collect-json

Returns a stream which becomes readable with a single value once all (valid) JSON is received.
JavaScript
2
star
42

load-module

Node's require with a few extra features
JavaScript
2
star
43

stream-read-all

Returns a promise which fulfils with the supplied stream's content
JavaScript
2
star
44

template-clean

Template literal tag function to replace null and undefined values with an empty string
JavaScript
2
star
45

sse-server

Push an event stream from terminal to browser
JavaScript
2
star
46

argv-tools

Some useful tools for working with process.argv
JavaScript
1
star
47

boil-sitemap

Static website sitemap.xml generator
JavaScript
1
star
48

league

A hand-rolled Football League model with both Web and CLI visualisations.
JavaScript
1
star
49

race-timeout-anywhere

An isomorphic, load-anywhere timeout function for use with Promise.race.
JavaScript
1
star
50

stream-connect

Connects an arbitrary number of streams into a single, combined stream
JavaScript
1
star
51

obso

Observable Object
JavaScript
1
star
52

object-tools

Legacy module - no longer maintained
JavaScript
1
star
53

grunt-yuidoc2md

A markdown generator for yuidoc
JavaScript
1
star
54

config-master

A convention for storing and retrieving application config
JavaScript
1
star
55

console-dope

adds colouring and cursor control features to console
JavaScript
1
star
56

stream-monitor

Watch dem pipelines flow! Or not, as the case may be..
JavaScript
1
star
57

defer-promise

Isomorphic function returning a deferred promise. Uses native `Promise.defer` where available, else polyfills
JavaScript
1
star
58

cli-commands

A convention for building command-driven CLI apps
JavaScript
1
star
59

common-dir

Returns the parent directory common to each path
JavaScript
1
star
60

handlebars-json

Provides access to JSON.stringify from a Handlebars template.
JavaScript
1
star
61

collect-all

returns a stream which becomes readable once all input is received
JavaScript
1
star
62

boil

Boilerplate files, packages, apps, websites etc.
JavaScript
1
star
63

test-value

A module for testing values.
JavaScript
1
star
64

linguist

Translate strings or JSON from Node.js or the command line
JavaScript
1
star
65

create-mixin

For achieving something resembling multiple-inheritence in Javascript
JavaScript
1
star
66

nature

currently inactive
JavaScript
1
star