forked from eugeneware/ffmpeg-static
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.js
executable file
·49 lines (44 loc) · 1.07 KB
/
example.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
#!/usr/bin/env node
'use strict'
const {resolve} = require('path')
const shell = require('any-shell-escape')
const {exec} = require('child_process')
const pathToFfmpeg = require('.')
const argv = process.argv.slice(2)
if (argv.includes('-h') || argv.includes('--help')) {
console.info(`
This is just a simple CLI wrapper around the powerful ffmpeg CLI tool.
This script just showcases how to use ffmpeg-static; It wouldn't make
sense to hide a flexible tool behind a limited wrapper script.
Usage:
./example.js <src> <dest>
Example:
./example.js src-audio-file.m4a dest-audio-file.mp3
`)
process.exit(0)
}
const [src, dest] = argv
if (!src) {
console.error('Missing <src> positional argument.')
process.exit(1)
}
if (!dest) {
console.error('Missing <dest> positional argument.')
process.exit(1)
}
const makeMp3 = shell([
pathToFfmpeg,
'-y', '-v', 'error',
'-i', resolve(process.cwd(), src),
'-acodec', 'mp3',
'-format', 'mp3',
resolve(process.cwd(), dest),
])
exec(makeMp3, (err) => {
if (err) {
console.error(err)
process.exit(1)
} else {
console.info('done!')
}
})