Home

Awesome

batch-transcode-video

NPM Version Image dependencies Status Image devDependencies Status Image License Type Image

batch-transcode-video screenshot 1

A command-line utility for recursively running batch cropping and transcoding operations on a directory of videos. This utility is a wrapper for a a utility called transcode_video which itself is a wrapper for trancoding utilities such as HandbrakeCLI, MKVToolNix, and ffmpeg.

Prerequisites

Requires Node.js and Ruby.

Important: You must have all of the dependencies listed in this section of the transcode_video README.

Before installing batch-transcode-video, install the video_transcoding gem using the following command.

gem install video_transcoding

Installation

This utility can be installed so that it is globally accessible from the terminal as batch-transcode-video using the following command.

npm i batch-transcode-video -g

Usage

For all the videos found in the input directory, this utility will determine if the source should be cropped (e.g.: it has black bars on the top and bottom of the source video) using detect-crop and then it will be transcoded using transcode-video. When in CLI mode, the progress and remaining time for the current file and the entire batch are displayed.

This utility can recover from most errors, and as such, it will continue to sequentially process source files even if a previous transcoding operation has failed.

A summary is displayed when the entire batch transcoding operation is finished. The summary includes the overall number of errors encountered and files successfully created.

Before You Begin

WARNING: If the program cannot successfully transcode an input file, and then verify the output video file, it will be marked as errored and the transcoded file (if one exists) will be deleted from the output directory. This is done to prevent partially-transcoded files from remaining in the output directory that then need to be manually deleted before retrying the transcoding operation.

If you run the program using an output directory containing previously-transcoded video, especially for source files that still exist in your input directory, you must use the --diff option to ensure sucessful transcodes from previous batches are not deleted from the output directory. In --diff mode, input files are skipped when their corresponding output files already exist in the output directory.

Alternatively, you can use the --keep option to ensure files are never deleted from the output directory, even if they have errors or failed to finish transcoding. However, subsequent runs, with or without using the --diff option, will not reprocess failed input files, unless the corresponding output files are manually deleted.

Instructions

Recursively search for videos to transcode using video_transcoding. If an input directory is not specified then the current directory will be used as the input directory. If an output directory is not specified, the input directory will be used for the transcoded videos. By default, if an output file already exists then it will be treated as an error. Use the --diff option to skip input files that already exist in the output folder.

batch-transcode-video --input video/ --output transcoded/ --diff

Transcoded files will be placed in the same directory as the source unless you specify an output directory. The relative folder structure will be maintained in the output directory unless you use the flatten flag.

If you want to modify the search pattern that will be used to locate video in the input directory, you can specify a glob pattern using the mask option.

Non-binary Usage

You can also directly require() the underlying BatchTranscodeVideo video class. By default, the ES5-compatible files will be loaded when requiring this module.

// ES5 (default)
var BatchTranscodeVideo = require('batch-transcode-video');
var batch = new BatchTranscodeVideo({
  input: './my/rawVideos/',
  output: './my/transcodedVideos/'
}, ['--dry-run']);
batch
.transcodeAll()
.then(function (res) {
  console.log(res);
})
.catch(function (err) {
  console.log(err);
});

But, you can also require the raw ES2015 source files if you are running in an ES2015 capable environment.

Note: The un-transpiled source files are not including when you install the library using npm install. To get the ES2015 source, you need to clone this repository from GitHub using git clone.

// ES2015
import BatchTranscodeVideo from './batch-transcode-video/index.js';
let batch = new BatchTranscodeVideo(options, transcodeOptions);

Note: If you import the non-CLI files, you will not see any formatted progress bars and summary output in the console. To require the CLI version of the library from your application, then simply import the index-cli.js file instead of index.js.

import CliBatchTranscodeVideo from './batch-transcode-video/index-cli.js';
import minimist from 'minimist';
let options = minimist(process.argv.slice(2), {'--': true});
let batch = new CliBatchTranscodeVideo(options, options['--']);
// Start CLI mode
batch.cli();

Options

Providing options to transcode-video

If you want to provide custom options to trancode-video then you can place them at the end of your normal options following a -- and they will be passed directly to the transcode-video program. Find more information about the allowed options at the transcode_video README.

batch-transcode-video --input video/ --output transcoded/ --diff -- --dry-run