Skip to content

Commit 21f5b07

Browse files
committed
add ffmpeg arguments
1 parent 2a909e9 commit 21f5b07

File tree

4 files changed

+50
-4
lines changed

4 files changed

+50
-4
lines changed

cli/Command.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ class Command {
7878
output: this.argv.output || '.',
7979
format: this.argv.format,
8080
audioonly: this.argv.audioonly,
81-
quality: this.argv.quality
81+
quality: this.argv.quality,
82+
inputParams: this.argv.inputParam,
83+
outputParams: this.argv.outputParam
8284
})
8385

8486
let downloadBar

cli/index.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const Command = require('./Command.js')
77

88
const argv = yargs
99
.usage('Usage: $0 <command> [options]')
10-
.example('$0 -i myaudio.mp3 -t parse.txt -o /home/Music -m title=Test')
10+
.example('$0 -i myvideo.avi -f mp4 -t parse.txt -o /home/Videos -m title=Test -p:o "\'-vf scale=320:-1\'"')
1111
.alias('a', 'audioonly')
1212
.alias('o', 'output')
1313
.alias('t', 'template')
@@ -17,6 +17,8 @@ const argv = yargs
1717
.alias('f', 'format')
1818
.alias('s', 'sections')
1919
.alias('q', 'quality')
20+
.alias('p:i', 'inputParam')
21+
.alias('p:o', 'outputParam')
2022
.describe('o', 'Output path')
2123
.describe('t', 'Template text file')
2224
.describe('i', 'Input file or YouTube URL')
@@ -26,13 +28,17 @@ const argv = yargs
2628
.describe('a', 'Force download only audio files when using a url as input')
2729
.describe('s', 'Sections to split')
2830
.describe('q', 'Download quality (highest/lowest/highestaudio/lowestaudio/highestvideo/lowestvideo)')
31+
.describe('p:i', 'Additional FFMpeg input parameters')
32+
.describe('p:o', 'Additional FFMpeg output parameters')
2933
.default('f', 'mp3')
3034
.default('t', 'templ.txt')
3135
.default('i', 'input.mp3')
3236
.default('a', false)
3337
.default('c', 3)
3438
.default('q', 'highest')
3539
.array('m').default('m', [])
40+
.array('p:i').default('p:i', [])
41+
.array('p:o').default('p:o', [])
3642
.array('s')
3743
.help('h').alias('h', 'help')
3844
.argv

lib/MediaSplit.js

+27-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class MediaSplit extends EventEmitter {
2828
* @param {string} options.format - Output format (mp3, m4a, flac, etc)
2929
* @param {boolean} options.audioonly - Force download only audio files when using a url as input
3030
* @param {string} options.quality - Download quality
31+
* @param {string[]} options.inputParams - FFMpeg additional input parameters
32+
* @param {string[]} options.outputParams - FFMpeg additional output parameters
3133
* @return MediaSplit
3234
*/
3335
constructor (options = {}) {
@@ -43,10 +45,20 @@ class MediaSplit extends EventEmitter {
4345
output: '.',
4446
format: 'mp3',
4547
audioonly: false,
46-
quality: 'highest'
48+
quality: 'highest',
49+
inputParams: [],
50+
outputParams: []
4751
}
4852

49-
this._options = Object.assign(defaults, options)
53+
this._options = Object.assign(
54+
defaults,
55+
options,
56+
{
57+
inputParams: this._sanitizeParams(options.inputParams),
58+
outputParams: this._sanitizeParams(options.outputParams)
59+
}
60+
)
61+
5062
this._inputFile = ''
5163
this._downloadOptions = {}
5264
}
@@ -327,6 +339,7 @@ class MediaSplit extends EventEmitter {
327339
'-hide_banner',
328340
'-loglevel', 'repeat+error',
329341
'-y',
342+
...this._options.inputParams,
330343
'-i', this._inputFile,
331344
'-ss', section.start
332345
]
@@ -353,6 +366,9 @@ class MediaSplit extends EventEmitter {
353366
args.push('-metadata', `${name}=${value}`)
354367
}
355368

369+
// Additional ffmpeg output arguments
370+
args.push(...this._options.outputParams)
371+
356372
// And finally the output path
357373
args.push(path.join(this._options.output, section.name))
358374

@@ -373,6 +389,15 @@ class MediaSplit extends EventEmitter {
373389
return Promise.all(promises)
374390
}
375391

392+
/**
393+
* @param {string[]} params
394+
*/
395+
_sanitizeParams (params) {
396+
return (params || [])
397+
.map((x) => x.replace(/^("|')/gim, '').replace(/("|')$/gim, ''))
398+
.flatMap(x => x.split(' '))
399+
}
400+
376401
_checkAccess (dir, mode) {
377402
return new Promise((resolve, reject) => fs.access(dir, mode, (err) => err ? reject(err) : resolve(dir)))
378403
}

spec/Command.spec.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict'
2+
3+
const expect = require('chai').expect
4+
const spawnSync = require('child_process').spawnSync
5+
const path = require('path')
6+
7+
describe('Command', () => {
8+
it('should return 0 code', () => {
9+
const binPath = path.resolve('cli/index.js')
10+
const proc = spawnSync('node', [ binPath, 'h' ])
11+
expect(proc.status).to.be.equal(0)
12+
})
13+
})

0 commit comments

Comments
 (0)