Skip to content

Commit

Permalink
tweak example.js 📝
Browse files Browse the repository at this point in the history
  • Loading branch information
derhuerst committed Jan 24, 2022
1 parent fe784fc commit f6aef1a
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions example.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env node
'use strict'

const {join} = require('path')
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')) {
Expand All @@ -12,18 +13,30 @@ 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([
'ffmpeg', '-y', '-v', 'error',
'-i', join(process.cwd(), src),
pathToFfmpeg,
'-y', '-v', 'error',
'-i', resolve(process.cwd(), src),
'-acodec', 'mp3',
'-format', 'mp3',
join(process.cwd(), dest)
resolve(process.cwd(), dest),
])

exec(makeMp3, (err) => {
Expand Down

0 comments on commit f6aef1a

Please sign in to comment.