]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/videos/video-transcoder.ts
Add basic video editor support
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / video-transcoder.ts
index 21609fd822da0a000c44ef0969fdf3817c2aa28b..245c4c012dbf010aabdec0edb2e40c0cec0f174b 100644 (file)
@@ -3,29 +3,28 @@
 import 'mocha'
 import * as chai from 'chai'
 import { omit } from 'lodash'
-import { getMaxBitrate } from '@shared/core-utils'
+import { canDoQuickTranscode } from '@server/helpers/ffmpeg'
+import { generateHighBitrateVideo, generateVideoWithFramerate, getAllFiles } from '@server/tests/shared'
+import { buildAbsoluteFixturePath, getMaxBitrate, getMinLimitBitrate } from '@shared/core-utils'
+import {
+  getAudioStream,
+  buildFileMetadata,
+  getVideoStreamBitrate,
+  getVideoStreamFPS,
+  getVideoStreamDimensionsInfo,
+  hasAudioStream
+} from '@shared/extra-utils'
+import { HttpStatusCode, VideoState } from '@shared/models'
 import {
-  buildAbsoluteFixturePath,
   cleanupTests,
   createMultipleServers,
   doubleFollow,
-  generateHighBitrateVideo,
-  generateVideoWithFramerate,
   makeGetRequest,
   PeerTubeServer,
   setAccessTokensToServers,
   waitJobs,
   webtorrentAdd
-} from '@shared/extra-utils'
-import { HttpStatusCode, VideoState } from '@shared/models'
-import {
-  canDoQuickTranscode,
-  getAudioStream,
-  getMetadataFromFile,
-  getVideoFileBitrate,
-  getVideoFileFPS,
-  getVideoFileResolution
-} from '../../../helpers/ffprobe-utils'
+} from '@shared/server-commands'
 
 const expect = chai.expect
 
@@ -40,6 +39,7 @@ function updateConfigForTranscoding (server: PeerTubeServer) {
         webtorrent: { enabled: true },
         resolutions: {
           '0p': false,
+          '144p': true,
           '240p': true,
           '360p': true,
           '480p': true,
@@ -119,7 +119,7 @@ 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)
+        expect(videoDetails.files).to.have.lengthOf(5)
 
         const magnetUri = videoDetails.files[0].magnetUri
         expect(magnetUri).to.match(/\.mp4/)
@@ -205,7 +205,7 @@ 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)
+          expect(videoDetails.files).to.have.lengthOf(5)
 
           const magnetUri = videoDetails.files[0].magnetUri
           expect(magnetUri).to.contain('.mp4')
@@ -226,7 +226,7 @@ describe('Test video transcoding', function () {
 
       await waitJobs(servers)
 
-      const resolutions = [ 240, 360, 480, 720, 1080, 1440, 2160 ]
+      const resolutions = [ 144, 240, 360, 480, 720, 1080, 1440, 2160 ]
 
       for (const server of servers) {
         const videoDetails = await server.videos.get({ id: video4k })
@@ -259,7 +259,7 @@ 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)
+        expect(videoDetails.files).to.have.lengthOf(5)
 
         const file = videoDetails.files.find(f => f.resolution.id === 240)
         const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
@@ -294,8 +294,7 @@ describe('Test video transcoding', function () {
         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')
+        expect(await hasAudioStream(path)).to.be.false
       }
     })
 
@@ -316,7 +315,7 @@ 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)
+        expect(videoDetails.files).to.have.lengthOf(5)
 
         const fixturePath = buildAbsoluteFixturePath(attributes.fixture)
         const fixtureVideoProbe = await getAudioStream(fixturePath)
@@ -348,6 +347,7 @@ describe('Test video transcoding', function () {
               webtorrent: { enabled: true },
               resolutions: {
                 '0p': false,
+                '144p': false,
                 '240p': false,
                 '360p': false,
                 '480p': false,
@@ -419,6 +419,7 @@ describe('Test video transcoding', function () {
               webtorrent: { enabled: true },
               resolutions: {
                 '0p': true,
+                '144p': false,
                 '240p': false,
                 '360p': false
               }
@@ -473,23 +474,24 @@ 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)
+        expect(videoDetails.files).to.have.lengthOf(5)
         expect(videoDetails.files[0].fps).to.be.above(58).and.below(62)
         expect(videoDetails.files[1].fps).to.be.below(31)
         expect(videoDetails.files[2].fps).to.be.below(31)
         expect(videoDetails.files[3].fps).to.be.below(31)
+        expect(videoDetails.files[4].fps).to.be.below(31)
 
-        for (const resolution of [ 240, 360, 480 ]) {
+        for (const resolution of [ 144, 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)
+          const fps = await getVideoStreamFPS(path)
 
           expect(fps).to.be.below(31)
         }
 
         const file = videoDetails.files.find(f => f.resolution.id === 720)
         const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
-        const fps = await getVideoFileFPS(path)
+        const fps = await getVideoStreamFPS(path)
 
         expect(fps).to.be.above(58).and.below(62)
       }
@@ -503,7 +505,7 @@ describe('Test video transcoding', function () {
       {
         tempFixturePath = await generateVideoWithFramerate(59)
 
-        const fps = await getVideoFileFPS(tempFixturePath)
+        const fps = await getVideoStreamFPS(tempFixturePath)
         expect(fps).to.be.equal(59)
       }
 
@@ -526,14 +528,14 @@ describe('Test video transcoding', function () {
         {
           const file = video.files.find(f => f.resolution.id === 240)
           const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
-          const fps = await getVideoFileFPS(path)
+          const fps = await getVideoStreamFPS(path)
           expect(fps).to.be.equal(25)
         }
 
         {
           const file = video.files.find(f => f.resolution.id === 720)
           const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
-          const fps = await getVideoFileFPS(path)
+          const fps = await getVideoStreamFPS(path)
           expect(fps).to.be.equal(59)
         }
       }
@@ -567,9 +569,9 @@ describe('Test video transcoding', function () {
           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 dataResolution = await getVideoFileResolution(path)
+          const bitrate = await getVideoStreamBitrate(path)
+          const fps = await getVideoStreamFPS(path)
+          const dataResolution = await getVideoStreamDimensionsInfo(path)
 
           expect(resolution).to.equal(resolution)
 
@@ -579,13 +581,14 @@ describe('Test video transcoding', function () {
       }
     })
 
-    it('Should not transcode to an higher bitrate than the original file', async function () {
+    it('Should not transcode to an higher bitrate than the original file but above our low limit', async function () {
       this.timeout(160_000)
 
       const newConfig = {
         transcoding: {
           enabled: true,
           resolutions: {
+            '144p': true,
             '240p': true,
             '360p': true,
             '480p': true,
@@ -616,8 +619,14 @@ describe('Test video transcoding', function () {
         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)
+        const bitrate = await getVideoStreamBitrate(path)
+
+        const inputBitrate = 60_000
+        const limit = getMinLimitBitrate({ fps: 10, ratio: 1, resolution: r })
+        let belowValue = Math.max(inputBitrate, limit)
+        belowValue += belowValue * 0.20 // Apply 20% margin because bitrate control is not very precise
+
+        expect(bitrate, `${path} not below ${limit}`).to.be.below(belowValue)
       }
     })
   })
@@ -634,7 +643,7 @@ describe('Test video transcoding', function () {
         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)
+        const metadata = await buildFileMetadata(path)
 
         // expected format properties
         for (const p of [
@@ -665,9 +674,8 @@ describe('Test video transcoding', function () {
       for (const server of servers) {
         const videoDetails = await server.videos.get({ id: videoUUID })
 
-        const videoFiles = videoDetails.files
-                                      .concat(videoDetails.streamingPlaylists[0].files)
-        expect(videoFiles).to.have.lengthOf(8)
+        const videoFiles = getAllFiles(videoDetails)
+        expect(videoFiles).to.have.lengthOf(10)
 
         for (const file of videoFiles) {
           expect(file.metadata).to.be.undefined
@@ -695,21 +703,21 @@ describe('Test video transcoding', function () {
       const body = await servers[1].jobs.list({
         start: 0,
         count: 100,
-        sort: '-createdAt',
+        sort: 'createdAt',
         jobType: 'video-transcoding'
       })
 
       const jobs = body.data
       const transcodingJobs = jobs.filter(j => j.data.videoUUID === video4k)
 
-      expect(transcodingJobs).to.have.lengthOf(14)
+      expect(transcodingJobs).to.have.lengthOf(16)
 
       const hlsJobs = transcodingJobs.filter(j => j.data.type === 'new-resolution-to-hls')
       const webtorrentJobs = transcodingJobs.filter(j => j.data.type === 'new-resolution-to-webtorrent')
       const optimizeJobs = transcodingJobs.filter(j => j.data.type === 'optimize-to-webtorrent')
 
-      expect(hlsJobs).to.have.lengthOf(7)
-      expect(webtorrentJobs).to.have.lengthOf(6)
+      expect(hlsJobs).to.have.lengthOf(8)
+      expect(webtorrentJobs).to.have.lengthOf(7)
       expect(optimizeJobs).to.have.lengthOf(1)
 
       for (const j of optimizeJobs.concat(hlsJobs.concat(webtorrentJobs))) {