]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/videos/video-transcoder.ts
Fix bitrate tests
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / video-transcoder.ts
index e4892bb24d03b34f38a64934134ee089a275f05e..21609fd822da0a000c44ef0969fdf3817c2aa28b 100644 (file)
@@ -3,7 +3,7 @@
 import 'mocha'
 import * as chai from 'chai'
 import { omit } from 'lodash'
-import { join } from 'path'
+import { getMaxBitrate } from '@shared/core-utils'
 import {
   buildAbsoluteFixturePath,
   cleanupTests,
@@ -17,8 +17,7 @@ import {
   waitJobs,
   webtorrentAdd
 } from '@shared/extra-utils'
-import { getMaxBitrate, HttpStatusCode, VideoResolution, VideoState } from '@shared/models'
-import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants'
+import { HttpStatusCode, VideoState } from '@shared/models'
 import {
   canDoQuickTranscode,
   getAudioStream,
@@ -191,15 +190,6 @@ describe('Test video transcoding', function () {
     it('Should accept and transcode additional extensions', async function () {
       this.timeout(300_000)
 
-      let tempFixturePath: string
-
-      {
-        tempFixturePath = await generateHighBitrateVideo()
-
-        const bitrate = await getVideoFileBitrate(tempFixturePath)
-        expect(bitrate).to.be.above(getMaxBitrate(VideoResolution.H_1080P, 25, VIDEO_TRANSCODING_FPS))
-      }
-
       for (const fixture of [ 'video_short.mkv', 'video_short.avi' ]) {
         const attributes = {
           name: fixture,
@@ -271,7 +261,8 @@ describe('Test video transcoding', function () {
 
         expect(videoDetails.files).to.have.lengthOf(4)
 
-        const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-240.mp4'))
+        const file = videoDetails.files.find(f => f.resolution.id === 240)
+        const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
         const probe = await getAudioStream(path)
 
         if (probe.audioStream) {
@@ -300,8 +291,9 @@ describe('Test video transcoding', function () {
         const video = data.find(v => v.name === attributes.name)
         const videoDetails = await server.videos.get({ id: video.id })
 
-        expect(videoDetails.files).to.have.lengthOf(4)
-        const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-240.mp4'))
+        const file = videoDetails.files.find(f => f.resolution.id === 240)
+        const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
+
         const probe = await getAudioStream(path)
         expect(probe).to.not.have.property('audioStream')
       }
@@ -328,7 +320,9 @@ describe('Test video transcoding', function () {
 
         const fixturePath = buildAbsoluteFixturePath(attributes.fixture)
         const fixtureVideoProbe = await getAudioStream(fixturePath)
-        const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-240.mp4'))
+
+        const file = videoDetails.files.find(f => f.resolution.id === 240)
+        const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
 
         const videoProbe = await getAudioStream(path)
 
@@ -485,14 +479,16 @@ describe('Test video transcoding', function () {
         expect(videoDetails.files[2].fps).to.be.below(31)
         expect(videoDetails.files[3].fps).to.be.below(31)
 
-        for (const resolution of [ '240', '360', '480' ]) {
-          const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-' + resolution + '.mp4'))
+        for (const resolution of [ 240, 360, 480 ]) {
+          const file = videoDetails.files.find(f => f.resolution.id === resolution)
+          const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
           const fps = await getVideoFileFPS(path)
 
           expect(fps).to.be.below(31)
         }
 
-        const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-720.mp4'))
+        const file = videoDetails.files.find(f => f.resolution.id === 720)
+        const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
         const fps = await getVideoFileFPS(path)
 
         expect(fps).to.be.above(58).and.below(62)
@@ -524,16 +520,19 @@ describe('Test video transcoding', function () {
       for (const server of servers) {
         const { data } = await server.videos.list()
 
-        const video = data.find(v => v.name === attributes.name)
+        const { id } = data.find(v => v.name === attributes.name)
+        const video = await server.videos.get({ id })
 
         {
-          const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-240.mp4'))
+          const file = video.files.find(f => f.resolution.id === 240)
+          const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
           const fps = await getVideoFileFPS(path)
           expect(fps).to.be.equal(25)
         }
 
         {
-          const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-720.mp4'))
+          const file = video.files.find(f => f.resolution.id === 720)
+          const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
           const fps = await getVideoFileFPS(path)
           expect(fps).to.be.equal(59)
         }
@@ -542,17 +541,11 @@ describe('Test video transcoding', function () {
   })
 
   describe('Bitrate control', function () {
+
     it('Should respect maximum bitrate values', async function () {
       this.timeout(160_000)
 
-      let tempFixturePath: string
-
-      {
-        tempFixturePath = await generateHighBitrateVideo()
-
-        const bitrate = await getVideoFileBitrate(tempFixturePath)
-        expect(bitrate).to.be.above(getMaxBitrate(VideoResolution.H_1080P, 25, VIDEO_TRANSCODING_FPS))
-      }
+      const tempFixturePath = await generateHighBitrateVideo()
 
       const attributes = {
         name: 'high bitrate video',
@@ -567,17 +560,21 @@ describe('Test video transcoding', function () {
       for (const server of servers) {
         const { data } = await server.videos.list()
 
-        const video = data.find(v => v.name === attributes.name)
+        const { id } = data.find(v => v.name === attributes.name)
+        const video = await server.videos.get({ id })
 
-        for (const resolution of [ '240', '360', '480', '720', '1080' ]) {
-          const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-' + resolution + '.mp4'))
+        for (const resolution of [ 240, 360, 480, 720, 1080 ]) {
+          const file = video.files.find(f => f.resolution.id === resolution)
+          const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
 
           const bitrate = await getVideoFileBitrate(path)
           const fps = await getVideoFileFPS(path)
-          const resolution2 = await getVideoFileResolution(path)
+          const dataResolution = await getVideoFileResolution(path)
+
+          expect(resolution).to.equal(resolution)
 
-          expect(resolution2.videoFileResolution.toString()).to.equal(resolution)
-          expect(bitrate).to.be.below(getMaxBitrate(resolution2.videoFileResolution, fps, VIDEO_TRANSCODING_FPS))
+          const maxBitrate = getMaxBitrate({ ...dataResolution, fps })
+          expect(bitrate).to.be.below(maxBitrate)
         }
       }
     })
@@ -608,15 +605,19 @@ describe('Test video transcoding', function () {
         fixture: 'low-bitrate.mp4'
       }
 
-      const { uuid } = await servers[1].videos.upload({ attributes })
+      const { id } = await servers[1].videos.upload({ attributes })
 
       await waitJobs(servers)
 
+      const video = await servers[1].videos.get({ id })
+
       const resolutions = [ 240, 360, 480, 720, 1080 ]
       for (const r of resolutions) {
-        const path = `videos/${uuid}-${r}.mp4`
-        const size = await servers[1].servers.getServerFileSize(path)
-        expect(size, `${path} not below ${60_000}`).to.be.below(60_000)
+        const file = video.files.find(f => f.resolution.id === r)
+
+        const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
+        const bitrate = await getVideoFileBitrate(path)
+        expect(bitrate, `${path} not below ${60_000}`).to.be.below(60_000)
       }
     })
   })
@@ -630,7 +631,9 @@ describe('Test video transcoding', function () {
       await waitJobs(servers)
 
       {
-        const path = servers[1].servers.buildDirectory(join('videos', videoUUID + '-240.mp4'))
+        const video = await servers[1].videos.get({ id: videoUUID })
+        const file = video.files.find(f => f.resolution.id === 240)
+        const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
         const metadata = await getMetadataFromFile(path)
 
         // expected format properties
@@ -689,7 +692,7 @@ describe('Test video transcoding', function () {
   describe('Transcoding job queue', function () {
 
     it('Should have the appropriate priorities for transcoding jobs', async function () {
-      const body = await servers[1].jobs.getJobsList({
+      const body = await servers[1].jobs.list({
         start: 0,
         count: 100,
         sort: '-createdAt',