2020-12-23 03:38:38 +01:00
|
|
|
import { registerTSPaths } from '../server/helpers/register-ts-paths'
|
|
|
|
registerTSPaths()
|
|
|
|
|
|
|
|
import * as program from 'commander'
|
|
|
|
import * as ffmpeg from 'fluent-ffmpeg'
|
|
|
|
import { buildx264VODCommand, runCommand, TranscodeOptions } from '@server/helpers/ffmpeg-utils'
|
|
|
|
import { exit } from 'process'
|
2021-05-11 10:57:25 +02:00
|
|
|
import { VideoTranscodingProfilesManager } from '@server/lib/transcoding/video-transcoding-profiles'
|
2020-12-23 03:38:38 +01: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 09:37:26 +01:00
|
|
|
availableEncoders: VideoTranscodingProfilesManager.Instance.getAvailableEncoders(),
|
2020-12-23 03:38:38 +01:00
|
|
|
profile: 'default',
|
|
|
|
|
|
|
|
resolution: +cmd.resolution,
|
|
|
|
isPortraitMode: false
|
|
|
|
} as TranscodeOptions
|
|
|
|
|
|
|
|
let command = ffmpeg(options.inputPath)
|
|
|
|
.output(options.outputPath)
|
|
|
|
|
|
|
|
command = await buildx264VODCommand(command, options)
|
|
|
|
|
|
|
|
command.on('start', (cmdline) => {
|
|
|
|
console.log(cmdline)
|
|
|
|
exit()
|
|
|
|
})
|
|
|
|
|
2021-03-03 10:23:05 +01:00
|
|
|
await runCommand({ command })
|
2020-12-23 03:38:38 +01:00
|
|
|
}
|