create-transcoding-job.ts 1.5 KB

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