ニジカ投稿局 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.

framerate.ts 1.4 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { VIDEO_TRANSCODING_FPS } from '@server/initializers/constants.js'
  2. export function computeOutputFPS (options: {
  3. inputFPS: number
  4. resolution: number
  5. }) {
  6. const { resolution } = options
  7. let fps = options.inputFPS
  8. if (
  9. // On small/medium resolutions, limit FPS
  10. resolution !== undefined &&
  11. resolution < VIDEO_TRANSCODING_FPS.KEEP_ORIGIN_FPS_RESOLUTION_MIN &&
  12. fps > VIDEO_TRANSCODING_FPS.AVERAGE
  13. ) {
  14. // Get closest standard framerate by modulo: downsampling has to be done to a divisor of the nominal fps value
  15. fps = getClosestFramerateStandard({ fps, type: 'STANDARD' })
  16. }
  17. if (fps < VIDEO_TRANSCODING_FPS.HARD_MIN) {
  18. throw new Error(`Cannot compute FPS because ${fps} is lower than our minimum value ${VIDEO_TRANSCODING_FPS.HARD_MIN}`)
  19. }
  20. // Cap min FPS
  21. if (fps < VIDEO_TRANSCODING_FPS.SOFT_MIN) fps = VIDEO_TRANSCODING_FPS.SOFT_MIN
  22. // Cap max FPS
  23. if (fps > VIDEO_TRANSCODING_FPS.SOFT_MAX) fps = getClosestFramerateStandard({ fps, type: 'HD_STANDARD' })
  24. return fps
  25. }
  26. // ---------------------------------------------------------------------------
  27. // Private
  28. // ---------------------------------------------------------------------------
  29. function getClosestFramerateStandard (options: {
  30. fps: number
  31. type: 'HD_STANDARD' | 'STANDARD'
  32. }) {
  33. const { fps, type } = options
  34. return VIDEO_TRANSCODING_FPS[type].slice(0)
  35. .sort((a, b) => fps % a - fps % b)[0]
  36. }