create-transcoding-job.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import * as program from 'commander'
  2. import { VideoModel } from '../server/models/video/video'
  3. import { initDatabaseModels } from '../server/initializers'
  4. import { JobQueue } from '../server/lib/job-queue'
  5. program
  6. .option('-v, --video [videoUUID]', 'Video UUID')
  7. .option('-r, --resolution [resolution]', 'Video resolution (integer)')
  8. .parse(process.argv)
  9. if (program['video'] === undefined) {
  10. console.error('All parameters are mandatory.')
  11. process.exit(-1)
  12. }
  13. if (program.resolution !== undefined && Number.isNaN(+program.resolution)) {
  14. console.error('The resolution must be an integer (example: 1080).')
  15. process.exit(-1)
  16. }
  17. run()
  18. .then(() => process.exit(0))
  19. .catch(err => {
  20. console.error(err)
  21. process.exit(-1)
  22. })
  23. async function run () {
  24. await initDatabaseModels(true)
  25. const video = await VideoModel.loadByUUIDWithFile(program['video'])
  26. if (!video) throw new Error('Video not found.')
  27. const dataInput = {
  28. videoUUID: video.uuid,
  29. isNewVideo: false,
  30. resolution: undefined
  31. }
  32. if (program.resolution !== undefined) {
  33. dataInput.resolution = program.resolution
  34. }
  35. await JobQueue.Instance.init()
  36. await JobQueue.Instance.createJob({ type: 'video-file', payload: dataInput })
  37. console.log('Transcoding job for video %s created.', video.uuid)
  38. }