-
Notifications
You must be signed in to change notification settings - Fork 0
/
split.js
executable file
·68 lines (47 loc) · 2.15 KB
/
split.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env node
const config = require('./config')
const path = require('path')
const fse = require('fs-extra')
const program = require('commander')
const commands = require('./commands')
const ffmpeg = require('fluent-ffmpeg')
//paths to the ffmpeg binaries for fluent-ffmpeg
ffmpeg.setFfmpegPath(config.ffmpegPath)
ffmpeg.setFfprobePath(config.ffprobePath)
//set up the command line interface with the commander module
program
.version(config.version)
.usage('[options] <file ...>')
.description('Splits the videos files into separate video and audio channels.')
.option('--output-suffix [string]', 'Suffix for output filenames', '')
.option('--output-folder [string]', 'Folder for output filenames [split]', 'split')
.option('--output-audio-extension [string]', 'Extension for output audio files [.m4a]', '.m4a')
.option('--output-video-extension [string]', 'Extension for output video files [.m4v]', '.m4v')
.option('-v, --verbose', 'Logs information about execution')
.parse(process.argv)
//expand globs in file arguments
let filenames = commands.expandGlobsSync(program.args)
//ensure that the output folder exists
commands.ensureOutputFolder(program)
//run the split command on all program arguments
commands.runCommandAllSequential(program, filenames, splitCommand)
function splitCommand (options, filename, metadata) {
const outputFilenameVideo = commands.getOutputFilename(Object.assign({}, options, {outputExtension: options.outputVideoExtension}), filename)
const outputFilenameAudio = commands.getOutputFilename(Object.assign({}, options, {outputExtension: options.outputAudioExtension}), filename)
if (options.verbose) {
console.log(`\nSplitting from ${filename}, writing to ${outputFilenameVideo} and ${outputFilenameAudio}`)
}
//returns a promise that resolves or rejects according to the results of the split
return new Promise( function (resolve, reject) {
ffmpeg(filename)
.output(outputFilenameVideo)
.noAudio()
.videoCodec('copy')
.output(outputFilenameAudio)
.noVideo()
.audioCodec('copy')
.on('error', err => reject(err))
.on('end', () => resolve())
.run()
})
}