ニジカ投稿局 https://tv.nizika.tv
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.

transcoding-resolutions.ts 2.1 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { toEven } from '@peertube/peertube-core-utils'
  2. import { VideoResolution, VideoResolutionType } from '@peertube/peertube-models'
  3. import { CONFIG } from '@server/initializers/config.js'
  4. export function buildOriginalFileResolution (inputResolution: number) {
  5. if (CONFIG.TRANSCODING.ALWAYS_TRANSCODE_ORIGINAL_RESOLUTION === true) {
  6. return toEven(inputResolution)
  7. }
  8. const resolutions = computeResolutionsToTranscode({
  9. input: inputResolution,
  10. type: 'vod',
  11. includeInput: false,
  12. strictLower: false,
  13. // We don't really care about the audio resolution in this context
  14. hasAudio: true
  15. })
  16. if (resolutions.length === 0) {
  17. return toEven(inputResolution)
  18. }
  19. return Math.max(...resolutions)
  20. }
  21. export function computeResolutionsToTranscode (options: {
  22. input: number
  23. type: 'vod' | 'live'
  24. includeInput: boolean
  25. strictLower: boolean
  26. hasAudio: boolean
  27. }) {
  28. const { input, type, includeInput, strictLower, hasAudio } = options
  29. const configResolutions = type === 'vod'
  30. ? CONFIG.TRANSCODING.RESOLUTIONS
  31. : CONFIG.LIVE.TRANSCODING.RESOLUTIONS
  32. const resolutionsEnabled = new Set<number>()
  33. // Put in the order we want to proceed jobs
  34. const availableResolutions: VideoResolutionType[] = [
  35. VideoResolution.H_NOVIDEO,
  36. VideoResolution.H_480P,
  37. VideoResolution.H_360P,
  38. VideoResolution.H_720P,
  39. VideoResolution.H_240P,
  40. VideoResolution.H_144P,
  41. VideoResolution.H_1080P,
  42. VideoResolution.H_1440P,
  43. VideoResolution.H_4K
  44. ]
  45. for (const resolution of availableResolutions) {
  46. // Resolution not enabled
  47. if (configResolutions[resolution + 'p'] !== true) continue
  48. // Too big resolution for input file
  49. if (input < resolution) continue
  50. // We only want lower resolutions than input file
  51. if (strictLower && input === resolution) continue
  52. // Audio resolutio but no audio in the video
  53. if (resolution === VideoResolution.H_NOVIDEO && !hasAudio) continue
  54. resolutionsEnabled.add(resolution)
  55. }
  56. if (includeInput) {
  57. // Always use an even resolution to avoid issues with ffmpeg
  58. resolutionsEnabled.add(toEven(input))
  59. }
  60. return Array.from(resolutionsEnabled)
  61. }