PeerTube/scripts/print-transcode-command.ts
Chocobozzz f8360396ff
Stop using tsconfig register
Prefer to replace paths at compile time
2022-01-06 08:26:14 +01:00

50 lines
1.3 KiB
TypeScript

import { program } from 'commander'
import ffmpeg from 'fluent-ffmpeg'
import { exit } from 'process'
import { buildx264VODCommand, runCommand, TranscodeOptions } from '@server/helpers/ffmpeg-utils'
import { VideoTranscodingProfilesManager } from '@server/lib/transcoding/video-transcoding-profiles'
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',
availableEncoders: VideoTranscodingProfilesManager.Instance.getAvailableEncoders(),
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()
})
await runCommand({ command })
}