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

codecs.ts 1.9 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { FfprobeData } from 'fluent-ffmpeg'
  2. import { getAudioStream, getVideoStream } from '@peertube/peertube-ffmpeg'
  3. import { logger } from '../logger.js'
  4. import { forceNumber } from '@peertube/peertube-core-utils'
  5. export async function getVideoStreamCodec (path: string) {
  6. const videoStream = await getVideoStream(path)
  7. if (!videoStream) return ''
  8. const videoCodec = videoStream.codec_tag_string
  9. if (videoCodec === 'vp09') return 'vp09.00.50.08'
  10. if (videoCodec === 'hev1') return 'hev1.1.6.L93.B0'
  11. const baseProfileMatrix = {
  12. avc1: {
  13. High: '6400',
  14. Main: '4D40',
  15. Baseline: '42E0'
  16. },
  17. av01: {
  18. High: '1',
  19. Main: '0',
  20. Professional: '2'
  21. }
  22. }
  23. let baseProfile = baseProfileMatrix[videoCodec][videoStream.profile]
  24. if (!baseProfile) {
  25. logger.warn('Cannot get video profile codec of %s.', path, { videoStream })
  26. baseProfile = baseProfileMatrix[videoCodec]['High'] // Fallback
  27. }
  28. if (videoCodec === 'av01') {
  29. let level = videoStream.level.toString()
  30. if (level.length === 1) level = `0${level}`
  31. // Guess the tier indicator and bit depth
  32. return `${videoCodec}.${baseProfile}.${level}M.08`
  33. }
  34. let level = forceNumber(videoStream.level).toString(16)
  35. if (level.length === 1) level = `0${level}`
  36. // Default, h264 codec
  37. return `${videoCodec}.${baseProfile}${level}`
  38. }
  39. export async function getAudioStreamCodec (path: string, existingProbe?: FfprobeData) {
  40. const { audioStream } = await getAudioStream(path, existingProbe)
  41. if (!audioStream) return ''
  42. const audioCodecName = audioStream.codec_name
  43. if (audioCodecName === 'opus') return 'opus'
  44. if (audioCodecName === 'vorbis') return 'vorbis'
  45. if (audioCodecName === 'aac') return 'mp4a.40.2'
  46. if (audioCodecName === 'mp3') return 'mp4a.40.34'
  47. logger.warn('Cannot get audio codec of %s.', path, { audioStream })
  48. return 'mp4a.40.2' // Fallback
  49. }