Federated video streaming platform using ActivityPub and P2P in the web browser with Angular. https://joinpeertube.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

102 lines
3.0 KiB

  1. import { program } from 'commander'
  2. import { isUUIDValid, toCompleteUUID } from '@server/helpers/custom-validators/misc'
  3. import { computeLowerResolutionsToTranscode } from '@server/helpers/ffprobe-utils'
  4. import { CONFIG } from '@server/initializers/config'
  5. import { addTranscodingJob } from '@server/lib/video'
  6. import { VideoState, VideoTranscodingPayload } from '@shared/models'
  7. import { initDatabaseModels } from '../server/initializers/database'
  8. import { JobQueue } from '../server/lib/job-queue'
  9. import { VideoModel } from '../server/models/video/video'
  10. program
  11. .option('-v, --video [videoUUID]', 'Video UUID')
  12. .option('-r, --resolution [resolution]', 'Video resolution (integer)')
  13. .option('--generate-hls', 'Generate HLS playlist')
  14. .parse(process.argv)
  15. const options = program.opts()
  16. if (options.video === undefined) {
  17. console.error('All parameters are mandatory.')
  18. process.exit(-1)
  19. }
  20. if (options.resolution !== undefined && Number.isNaN(+options.resolution)) {
  21. console.error('The resolution must be an integer (example: 1080).')
  22. process.exit(-1)
  23. }
  24. run()
  25. .then(() => process.exit(0))
  26. .catch(err => {
  27. console.error(err)
  28. process.exit(-1)
  29. })
  30. async function run () {
  31. await initDatabaseModels(true)
  32. const uuid = toCompleteUUID(options.video)
  33. if (isUUIDValid(uuid) === false) {
  34. console.error('%s is not a valid video UUID.', options.video)
  35. return
  36. }
  37. const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(uuid)
  38. if (!video) throw new Error('Video not found.')
  39. const dataInput: VideoTranscodingPayload[] = []
  40. const maxResolution = video.getMaxQualityFile().resolution
  41. // Generate HLS files
  42. if (options.generateHls || CONFIG.TRANSCODING.WEBTORRENT.ENABLED === false) {
  43. const resolutionsEnabled = options.resolution
  44. ? [ parseInt(options.resolution) ]
  45. : computeLowerResolutionsToTranscode(maxResolution, 'vod').concat([ maxResolution ])
  46. for (const resolution of resolutionsEnabled) {
  47. dataInput.push({
  48. type: 'new-resolution-to-hls',
  49. videoUUID: video.uuid,
  50. resolution,
  51. isPortraitMode: false,
  52. copyCodecs: false,
  53. isNewVideo: false,
  54. isMaxQuality: maxResolution === resolution,
  55. autoDeleteWebTorrentIfNeeded: false
  56. })
  57. }
  58. } else {
  59. if (options.resolution !== undefined) {
  60. dataInput.push({
  61. type: 'new-resolution-to-webtorrent',
  62. videoUUID: video.uuid,
  63. isNewVideo: false,
  64. resolution: parseInt(options.resolution)
  65. })
  66. } else {
  67. if (video.VideoFiles.length === 0) {
  68. console.error('Cannot regenerate webtorrent files with a HLS only video.')
  69. return
  70. }
  71. dataInput.push({
  72. type: 'optimize-to-webtorrent',
  73. videoUUID: video.uuid,
  74. isNewVideo: false
  75. })
  76. }
  77. }
  78. JobQueue.Instance.init(true)
  79. video.state = VideoState.TO_TRANSCODE
  80. await video.save()
  81. for (const d of dataInput) {
  82. await addTranscodingJob(d, {})
  83. console.log('Transcoding job for video %s created.', video.uuid)
  84. }
  85. }