2
1

print-transcode-command.ts 1.3 KB

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