]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/live/live.ts
Add transcoding module comments
[github/Chocobozzz/PeerTube.git] / server / tests / api / live / live.ts
index aa2e1318ae24bab818b8ef7d4761277b0822fc72..0786db554a3469ce074b58f57c595a43a5c7f3f1 100644 (file)
@@ -3,14 +3,16 @@
 import 'mocha'
 import * as chai from 'chai'
 import { FfmpegCommand } from 'fluent-ffmpeg'
+import { join } from 'path'
+import { ffprobePromise, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils'
 import { getLiveNotificationSocket } from '@shared/extra-utils/socket/socket-io'
 import { LiveVideo, LiveVideoCreate, Video, VideoDetails, VideoPrivacy, VideoState, VideoStreamingPlaylistType } from '@shared/models'
 import {
   addVideoToBlacklist,
+  buildServerDirectory,
   checkLiveCleanup,
   checkLiveSegmentHash,
   checkResolutionsInMasterPlaylist,
-  checkSegmentHash,
   cleanupTests,
   createLive,
   doubleFollow,
@@ -37,6 +39,7 @@ import {
   viewVideo,
   wait,
   waitJobs,
+  waitUntilLivePublished,
   waitUntilLiveStarts,
   waitUntilLog
 } from '../../../../shared/extra-utils'
@@ -325,7 +328,7 @@ describe('Test live', function () {
 
         for (let i = 0; i < resolutions.length; i++) {
           const segmentName = `${i}-000001.ts`
-          await waitUntilLog(servers[0], `${video.uuid}/${segmentName}`, 1, false)
+          await waitUntilLog(servers[0], `${video.uuid}/${segmentName}`, 2, false)
 
           const res = await getPlaylist(`${servers[0].url}/static/streaming-playlists/hls/${video.uuid}/${i}.m3u8`)
           const subPlaylist = res.text
@@ -394,22 +397,30 @@ describe('Test live', function () {
     })
 
     it('Should enable transcoding with some resolutions and correctly save them', async function () {
-      this.timeout(60000)
+      this.timeout(120000)
 
       const resolutions = [ 240, 360, 720 ]
+
       await updateConf(resolutions)
       liveVideoId = await createLiveWrapper(true)
 
-      const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId)
+      const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId, 'video_short2.webm')
       await waitUntilLiveStarts(servers[0].url, servers[0].accessToken, liveVideoId)
       await waitJobs(servers)
 
       await testVideoResolutions(liveVideoId, resolutions)
 
       await stopFfmpeg(command)
+      await waitUntilLivePublished(servers[0].url, servers[0].accessToken, liveVideoId)
 
       await waitJobs(servers)
 
+      const bitrateLimits = {
+        720: 3000 * 1000,
+        360: 1100 * 1000,
+        240: 600 * 1000
+      }
+
       for (const server of servers) {
         const resVideo = await getVideo(server.url, liveVideoId)
         const video: VideoDetails = resVideo.body
@@ -425,9 +436,17 @@ describe('Test live', function () {
           const file = hlsPlaylist.files.find(f => f.resolution.id === resolution)
 
           expect(file).to.exist
-          expect(file.fps).to.equal(25)
+          expect(file.fps).to.be.approximately(30, 5)
           expect(file.size).to.be.greaterThan(1)
 
+          const filename = `${video.uuid}-${resolution}-fragmented.mp4`
+          const segmentPath = buildServerDirectory(servers[0], join('streaming-playlists', 'hls', video.uuid, filename))
+
+          const probe = await ffprobePromise(segmentPath)
+          const videoStream = await getVideoStreamFromFile(segmentPath, probe)
+
+          expect(probe.format.bit_rate).to.be.below(bitrateLimits[videoStream.height])
+
           await makeRawRequest(file.torrentUrl, 200)
           await makeRawRequest(file.fileUrl, 200)
         }