PeerTube/scripts/print-transcode-command.ts

50 lines
1.3 KiB
TypeScript
Raw Normal View History

2021-06-25 17:39:27 +02:00
import { program } from 'commander'
2021-08-27 14:32:44 +02:00
import ffmpeg from 'fluent-ffmpeg'
import { exit } from 'process'
2022-02-11 10:51:33 +01:00
import { buildVODCommand, runCommand, TranscodeVODOptions } from '@server/helpers/ffmpeg'
import { VideoTranscodingProfilesManager } from '@server/lib/transcoding/default-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',
2021-01-28 09:37:26 +01:00
availableEncoders: VideoTranscodingProfilesManager.Instance.getAvailableEncoders(),
profile: 'default',
resolution: +cmd.resolution,
isPortraitMode: false
2022-02-11 10:51:33 +01:00
} as TranscodeVODOptions
let command = ffmpeg(options.inputPath)
.output(options.outputPath)
2022-02-11 10:51:33 +01:00
command = await buildVODCommand(command, options)
command.on('start', (cmdline) => {
console.log(cmdline)
exit()
})
await runCommand({ command })
}