2021-06-25 11:39:27 -04:00
|
|
|
import { program } from 'commander'
|
2021-08-27 08:32:44 -04:00
|
|
|
import ffmpeg from 'fluent-ffmpeg'
|
2020-12-22 21:38:38 -05:00
|
|
|
import { exit } from 'process'
|
2022-02-11 04:51:33 -05:00
|
|
|
import { buildVODCommand, runCommand, TranscodeVODOptions } from '@server/helpers/ffmpeg'
|
|
|
|
import { VideoTranscodingProfilesManager } from '@server/lib/transcoding/default-transcoding-profiles'
|
2020-12-22 21:38:38 -05:00
|
|
|
|
|
|
|
program
|
|
|
|
.arguments('<path>')
|
|
|
|
.requiredOption('-r, --resolution [resolution]', 'video resolution')
|
|
|
|
.action((path, cmd) => {
|
|
|
|
if (cmd.resolution !== undefined && Number.isNaN(+cmd.resolution)) {
|
|
|
|
console.error('The resolution must be an integer (example: 1080).')
|
|
|
|
process.exit(-1)
|
|
|
|
}
|
|
|
|
|
|
|
|
run(path, cmd)
|
|
|
|
.then(() => process.exit(0))
|
|
|
|
.catch(err => {
|
|
|
|
console.error(err)
|
|
|
|
process.exit(-1)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.parse(process.argv)
|
|
|
|
|
|
|
|
async function run (path: string, cmd: any) {
|
|
|
|
const options = {
|
|
|
|
type: 'video' as 'video',
|
|
|
|
inputPath: path,
|
|
|
|
outputPath: '/dev/null',
|
|
|
|
|
2021-01-28 03:37:26 -05:00
|
|
|
availableEncoders: VideoTranscodingProfilesManager.Instance.getAvailableEncoders(),
|
2020-12-22 21:38:38 -05:00
|
|
|
profile: 'default',
|
|
|
|
|
2022-08-05 04:36:19 -04:00
|
|
|
resolution: +cmd.resolution
|
2022-02-11 04:51:33 -05:00
|
|
|
} as TranscodeVODOptions
|
2020-12-22 21:38:38 -05:00
|
|
|
|
|
|
|
let command = ffmpeg(options.inputPath)
|
|
|
|
.output(options.outputPath)
|
|
|
|
|
2022-02-11 04:51:33 -05:00
|
|
|
command = await buildVODCommand(command, options)
|
2020-12-22 21:38:38 -05:00
|
|
|
|
|
|
|
command.on('start', (cmdline) => {
|
|
|
|
console.log(cmdline)
|
|
|
|
exit()
|
|
|
|
})
|
|
|
|
|
2021-03-03 04:23:05 -05:00
|
|
|
await runCommand({ command })
|
2020-12-22 21:38:38 -05:00
|
|
|
}
|