print-transcode-command.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { program } from 'commander'
  2. import ffmpeg from 'fluent-ffmpeg'
  3. import { exit } from 'process'
  4. import { buildVODCommand, runCommand, TranscodeVODOptions } from '@server/helpers/ffmpeg'
  5. import { VideoTranscodingProfilesManager } from '@server/lib/transcoding/default-transcoding-profiles'
  6. program
  7. .arguments('<path>')
  8. .requiredOption('-r, --resolution [resolution]', 'video resolution')
  9. .action((path, cmd) => {
  10. if (cmd.resolution !== undefined && Number.isNaN(+cmd.resolution)) {
  11. console.error('The resolution must be an integer (example: 1080).')
  12. process.exit(-1)
  13. }
  14. run(path, cmd)
  15. .then(() => process.exit(0))
  16. .catch(err => {
  17. console.error(err)
  18. process.exit(-1)
  19. })
  20. })
  21. .parse(process.argv)
  22. async function run (path: string, cmd: any) {
  23. const options = {
  24. type: 'video' as 'video',
  25. inputPath: path,
  26. outputPath: '/dev/null',
  27. availableEncoders: VideoTranscodingProfilesManager.Instance.getAvailableEncoders(),
  28. profile: 'default',
  29. resolution: +cmd.resolution
  30. } as TranscodeVODOptions
  31. let command = ffmpeg(options.inputPath)
  32. .output(options.outputPath)
  33. command = await buildVODCommand(command, options)
  34. command.on('start', (cmdline) => {
  35. console.log(cmdline)
  36. exit()
  37. })
  38. await runCommand({ command })
  39. }