audio-only.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
  2. import { expect } from 'chai'
  3. import { getAudioStream, getVideoStreamDimensionsInfo } from '@peertube/peertube-ffmpeg'
  4. import {
  5. cleanupTests,
  6. createMultipleServers,
  7. doubleFollow,
  8. PeerTubeServer,
  9. setAccessTokensToServers,
  10. waitJobs
  11. } from '@peertube/peertube-server-commands'
  12. describe('Test audio only video transcoding', function () {
  13. let servers: PeerTubeServer[] = []
  14. let videoUUID: string
  15. let webVideoAudioFileUrl: string
  16. let fragmentedAudioFileUrl: string
  17. before(async function () {
  18. this.timeout(120000)
  19. const configOverride = {
  20. transcoding: {
  21. enabled: true,
  22. resolutions: {
  23. '0p': true,
  24. '144p': false,
  25. '240p': true,
  26. '360p': false,
  27. '480p': false,
  28. '720p': false,
  29. '1080p': false,
  30. '1440p': false,
  31. '2160p': false
  32. },
  33. hls: {
  34. enabled: true
  35. },
  36. web_videos: {
  37. enabled: true
  38. }
  39. }
  40. }
  41. servers = await createMultipleServers(2, configOverride)
  42. // Get the access tokens
  43. await setAccessTokensToServers(servers)
  44. // Server 1 and server 2 follow each other
  45. await doubleFollow(servers[0], servers[1])
  46. })
  47. it('Should upload a video and transcode it', async function () {
  48. this.timeout(120000)
  49. const { uuid } = await servers[0].videos.upload({ attributes: { name: 'audio only' } })
  50. videoUUID = uuid
  51. await waitJobs(servers)
  52. for (const server of servers) {
  53. const video = await server.videos.get({ id: videoUUID })
  54. expect(video.streamingPlaylists).to.have.lengthOf(1)
  55. for (const files of [ video.files, video.streamingPlaylists[0].files ]) {
  56. expect(files).to.have.lengthOf(3)
  57. expect(files[0].resolution.id).to.equal(720)
  58. expect(files[1].resolution.id).to.equal(240)
  59. expect(files[2].resolution.id).to.equal(0)
  60. }
  61. if (server.serverNumber === 1) {
  62. webVideoAudioFileUrl = video.files[2].fileUrl
  63. fragmentedAudioFileUrl = video.streamingPlaylists[0].files[2].fileUrl
  64. }
  65. }
  66. })
  67. it('0p transcoded video should not have video', async function () {
  68. const paths = [
  69. servers[0].servers.buildWebVideoFilePath(webVideoAudioFileUrl),
  70. servers[0].servers.buildFragmentedFilePath(videoUUID, fragmentedAudioFileUrl)
  71. ]
  72. for (const path of paths) {
  73. const { audioStream } = await getAudioStream(path)
  74. expect(audioStream['codec_name']).to.be.equal('aac')
  75. expect(audioStream['bit_rate']).to.be.at.most(384 * 8000)
  76. const size = await getVideoStreamDimensionsInfo(path)
  77. expect(size.height).to.equal(0)
  78. expect(size.width).to.equal(0)
  79. expect(size.isPortraitMode).to.be.false
  80. expect(size.ratio).to.equal(0)
  81. expect(size.resolution).to.equal(0)
  82. }
  83. })
  84. after(async function () {
  85. await cleanupTests(servers)
  86. })
  87. })