]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/plugins/plugin-transcoding.ts
Add runner server tests
[github/Chocobozzz/PeerTube.git] / server / tests / plugins / plugin-transcoding.ts
index 3c54d37966264e7b42ff3d7f165b7299877c8dae..689eec5acdb3baafdf0b3475fb9d12c7b6684176 100644 (file)
@@ -1,20 +1,18 @@
 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
-import 'mocha'
 import { expect } from 'chai'
-import { join } from 'path'
-import { getAudioStream, getVideoFileFPS, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils'
+import { getAudioStream, getVideoStream, getVideoStreamFPS } from '@shared/ffmpeg'
+import { VideoPrivacy } from '@shared/models'
 import {
   cleanupTests,
   createSingleServer,
-  PluginsCommand,
   PeerTubeServer,
+  PluginsCommand,
   setAccessTokensToServers,
   setDefaultVideoChannel,
   testFfmpegStreamError,
   waitJobs
-} from '@shared/extra-utils'
-import { VideoPrivacy } from '@shared/models'
+} from '@shared/server-commands'
 
 async function createLiveWrapper (server: PeerTubeServer) {
   const liveAttributes = {
@@ -93,7 +91,7 @@ describe('Test transcoding plugins', function () {
 
     async function checkLiveFPS (uuid: string, type: 'above' | 'below', fps: number) {
       const playlistUrl = `${server.url}/static/streaming-playlists/hls/${uuid}/0.m3u8`
-      const videoFPS = await getVideoFileFPS(playlistUrl)
+      const videoFPS = await getVideoStreamFPS(playlistUrl)
 
       if (type === 'above') {
         expect(videoFPS).to.be.above(fps)
@@ -110,119 +108,125 @@ describe('Test transcoding plugins', function () {
       const config = await server.config.getConfig()
 
       expect(config.transcoding.availableProfiles).to.have.members([ 'default', 'low-vod', 'input-options-vod', 'bad-scale-vod' ])
-      expect(config.live.transcoding.availableProfiles).to.have.members([ 'default', 'low-live', 'input-options-live', 'bad-scale-live' ])
+      expect(config.live.transcoding.availableProfiles).to.have.members([ 'default', 'high-live', 'input-options-live', 'bad-scale-live' ])
     })
 
-    it('Should not use the plugin profile if not chosen by the admin', async function () {
-      this.timeout(240000)
+    describe('VOD', function () {
 
-      const videoUUID = (await server.videos.quickUpload({ name: 'video' })).uuid
-      await waitJobs([ server ])
+      it('Should not use the plugin profile if not chosen by the admin', async function () {
+        this.timeout(240000)
 
-      await checkVideoFPS(videoUUID, 'above', 20)
-    })
+        const videoUUID = (await server.videos.quickUpload({ name: 'video' })).uuid
+        await waitJobs([ server ])
 
-    it('Should use the vod profile', async function () {
-      this.timeout(240000)
+        await checkVideoFPS(videoUUID, 'above', 20)
+      })
 
-      await updateConf(server, 'low-vod', 'default')
+      it('Should use the vod profile', async function () {
+        this.timeout(240000)
 
-      const videoUUID = (await server.videos.quickUpload({ name: 'video' })).uuid
-      await waitJobs([ server ])
+        await updateConf(server, 'low-vod', 'default')
 
-      await checkVideoFPS(videoUUID, 'below', 12)
-    })
+        const videoUUID = (await server.videos.quickUpload({ name: 'video' })).uuid
+        await waitJobs([ server ])
 
-    it('Should apply input options in vod profile', async function () {
-      this.timeout(240000)
+        await checkVideoFPS(videoUUID, 'below', 12)
+      })
 
-      await updateConf(server, 'input-options-vod', 'default')
+      it('Should apply input options in vod profile', async function () {
+        this.timeout(240000)
 
-      const videoUUID = (await server.videos.quickUpload({ name: 'video' })).uuid
-      await waitJobs([ server ])
+        await updateConf(server, 'input-options-vod', 'default')
 
-      await checkVideoFPS(videoUUID, 'below', 6)
-    })
+        const videoUUID = (await server.videos.quickUpload({ name: 'video' })).uuid
+        await waitJobs([ server ])
 
-    it('Should apply the scale filter in vod profile', async function () {
-      this.timeout(240000)
+        await checkVideoFPS(videoUUID, 'below', 6)
+      })
 
-      await updateConf(server, 'bad-scale-vod', 'default')
+      it('Should apply the scale filter in vod profile', async function () {
+        this.timeout(240000)
 
-      const videoUUID = (await server.videos.quickUpload({ name: 'video' })).uuid
-      await waitJobs([ server ])
+        await updateConf(server, 'bad-scale-vod', 'default')
 
-      // Transcoding failed
-      const video = await server.videos.get({ id: videoUUID })
-      expect(video.files).to.have.lengthOf(1)
-      expect(video.streamingPlaylists).to.have.lengthOf(0)
+        const videoUUID = (await server.videos.quickUpload({ name: 'video' })).uuid
+        await waitJobs([ server ])
+
+        // Transcoding failed
+        const video = await server.videos.get({ id: videoUUID })
+        expect(video.files).to.have.lengthOf(1)
+        expect(video.streamingPlaylists).to.have.lengthOf(0)
+      })
     })
 
-    it('Should not use the plugin profile if not chosen by the admin', async function () {
-      this.timeout(240000)
+    describe('Live', function () {
 
-      const liveVideoId = await createLiveWrapper(server)
+      it('Should not use the plugin profile if not chosen by the admin', async function () {
+        this.timeout(240000)
 
-      await server.live.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' })
-      await server.live.waitUntilPublished({ videoId: liveVideoId })
-      await waitJobs([ server ])
+        const liveVideoId = await createLiveWrapper(server)
 
-      await checkLiveFPS(liveVideoId, 'above', 20)
-    })
+        await server.live.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_very_short_240p.mp4' })
+        await server.live.waitUntilPublished({ videoId: liveVideoId })
+        await waitJobs([ server ])
 
-    it('Should use the live profile', async function () {
-      this.timeout(240000)
+        await checkLiveFPS(liveVideoId, 'above', 20)
+      })
 
-      await updateConf(server, 'low-vod', 'low-live')
+      it('Should use the live profile', async function () {
+        this.timeout(240000)
 
-      const liveVideoId = await createLiveWrapper(server)
+        await updateConf(server, 'low-vod', 'high-live')
 
-      await server.live.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' })
-      await server.live.waitUntilPublished({ videoId: liveVideoId })
-      await waitJobs([ server ])
+        const liveVideoId = await createLiveWrapper(server)
 
-      await checkLiveFPS(liveVideoId, 'below', 12)
-    })
+        await server.live.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_very_short_240p.mp4' })
+        await server.live.waitUntilPublished({ videoId: liveVideoId })
+        await waitJobs([ server ])
 
-    it('Should apply the input options on live profile', async function () {
-      this.timeout(240000)
+        await checkLiveFPS(liveVideoId, 'above', 45)
+      })
 
-      await updateConf(server, 'low-vod', 'input-options-live')
+      it('Should apply the input options on live profile', async function () {
+        this.timeout(240000)
 
-      const liveVideoId = await createLiveWrapper(server)
+        await updateConf(server, 'low-vod', 'input-options-live')
 
-      await server.live.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' })
-      await server.live.waitUntilPublished({ videoId: liveVideoId })
-      await waitJobs([ server ])
+        const liveVideoId = await createLiveWrapper(server)
 
-      await checkLiveFPS(liveVideoId, 'below', 6)
-    })
+        await server.live.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_very_short_240p.mp4' })
+        await server.live.waitUntilPublished({ videoId: liveVideoId })
+        await waitJobs([ server ])
 
-    it('Should apply the scale filter name on live profile', async function () {
-      this.timeout(240000)
+        await checkLiveFPS(liveVideoId, 'above', 45)
+      })
 
-      await updateConf(server, 'low-vod', 'bad-scale-live')
+      it('Should apply the scale filter name on live profile', async function () {
+        this.timeout(240000)
 
-      const liveVideoId = await createLiveWrapper(server)
+        await updateConf(server, 'low-vod', 'bad-scale-live')
 
-      const command = await server.live.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' })
-      await testFfmpegStreamError(command, true)
-    })
+        const liveVideoId = await createLiveWrapper(server)
 
-    it('Should default to the default profile if the specified profile does not exist', async function () {
-      this.timeout(240000)
+        const command = await server.live.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_very_short_240p.mp4' })
+        await testFfmpegStreamError(command, true)
+      })
 
-      await server.plugins.uninstall({ npmName: 'peertube-plugin-test-transcoding-one' })
+      it('Should default to the default profile if the specified profile does not exist', async function () {
+        this.timeout(240000)
 
-      const config = await server.config.getConfig()
+        await server.plugins.uninstall({ npmName: 'peertube-plugin-test-transcoding-one' })
 
-      expect(config.transcoding.availableProfiles).to.deep.equal([ 'default' ])
-      expect(config.live.transcoding.availableProfiles).to.deep.equal([ 'default' ])
+        const config = await server.config.getConfig()
 
-      const videoUUID = (await server.videos.quickUpload({ name: 'video' })).uuid
-      await waitJobs([ server ])
+        expect(config.transcoding.availableProfiles).to.deep.equal([ 'default' ])
+        expect(config.live.transcoding.availableProfiles).to.deep.equal([ 'default' ])
+
+        const videoUUID = (await server.videos.quickUpload({ name: 'video', fixture: 'video_very_short_240p.mp4' })).uuid
+        await waitJobs([ server ])
 
-      await checkVideoFPS(videoUUID, 'above', 20)
+        await checkVideoFPS(videoUUID, 'above', 20)
+      })
     })
 
   })
@@ -238,14 +242,16 @@ describe('Test transcoding plugins', function () {
     it('Should use the new vod encoders', async function () {
       this.timeout(240000)
 
-      const videoUUID = (await server.videos.quickUpload({ name: 'video', fixture: 'video_short_240p.mp4' })).uuid
+      const videoUUID = (await server.videos.quickUpload({ name: 'video', fixture: 'video_very_short_240p.mp4' })).uuid
       await waitJobs([ server ])
 
-      const path = server.servers.buildDirectory(join('videos', videoUUID + '-240.mp4'))
+      const video = await server.videos.get({ id: videoUUID })
+
+      const path = server.servers.buildWebTorrentFilePath(video.files[0].fileUrl)
       const audioProbe = await getAudioStream(path)
       expect(audioProbe.audioStream.codec_name).to.equal('opus')
 
-      const videoProbe = await getVideoStreamFromFile(path)
+      const videoProbe = await getVideoStream(path)
       expect(videoProbe.codec_name).to.equal('vp9')
     })
 
@@ -262,7 +268,7 @@ describe('Test transcoding plugins', function () {
       const audioProbe = await getAudioStream(playlistUrl)
       expect(audioProbe.audioStream.codec_name).to.equal('opus')
 
-      const videoProbe = await getVideoStreamFromFile(playlistUrl)
+      const videoProbe = await getVideoStream(playlistUrl)
       expect(videoProbe.codec_name).to.equal('h264')
     })
   })