Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Fix max frame rate on original file

Chocobozzzb608a075c904
diff --git a/packages/tests/fixtures/1080p_60fps.mp4 b/packages/tests/fixtures/1080p_60fps.mp4
new file mode 100644
index 0000000000..3a26adc172
Binary files /dev/null and b/packages/tests/fixtures/1080p_60fps.mp4 differ
diff --git a/packages/tests/src/api/transcoding/transcoder-limits.ts b/packages/tests/src/api/transcoding/transcoder-limits.ts
index 8e786b6b1d..a198005d4f 100644
--- a/packages/tests/src/api/transcoding/transcoder-limits.ts
+++ b/packages/tests/src/api/transcoding/transcoder-limits.ts
@@ -41,8 +41,14 @@ describe('Test video transcoding limits', function () {
})
describe('Framerate limits', function () {
+ async function testFPS (options: {
+ uuid: string
+ originFPS: number
+ averageFPS: number
+ highFPS?: number
+ }) {
+ const { uuid, originFPS, averageFPS, highFPS = averageFPS } = options
- async function testFPS (uuid: string, originFPS: number, averageFPS: number) {
for (const server of servers) {
const video = await server.videos.get({ id: uuid })
@@ -56,10 +62,14 @@ describe('Test video transcoding limits', function () {
files.shift()
for (const file of files) {
- expect(file.fps).to.be.closeTo(averageFPS, 2)
+ const expectedFPS = file.resolution.id >= VideoResolution.H_720P
+ ? highFPS
+ : averageFPS
+
+ expect(file.fps).to.be.closeTo(expectedFPS, 2)
const path = servers[1].servers.buildWebVideoFilePath(file.fileUrl)
- expect(await getVideoStreamFPS(path)).to.be.closeTo(averageFPS, 2)
+ expect(await getVideoStreamFPS(path)).to.be.closeTo(expectedFPS, 2)
}
}
}
@@ -81,7 +91,7 @@ describe('Test video transcoding limits', function () {
const { uuid } = await servers[1].videos.upload({ attributes })
await waitJobs(servers)
- await testFPS(uuid, 60, 30)
+ await testFPS({ uuid, originFPS: 60, averageFPS: 30 })
})
it('Should transcode origin resolution to max FPS', async function () {
@@ -101,7 +111,7 @@ describe('Test video transcoding limits', function () {
const { uuid } = await servers[1].videos.upload({ attributes })
await waitJobs(servers)
- await testFPS(uuid, 50, 25)
+ await testFPS({ uuid, originFPS: 50, averageFPS: 25 })
}
})
@@ -121,7 +131,7 @@ describe('Test video transcoding limits', function () {
const { uuid } = await servers[1].videos.upload({ attributes })
await waitJobs(servers)
- await testFPS(uuid, 59, 25)
+ await testFPS({ uuid, originFPS: 59, averageFPS: 25 })
})
it('Should configure max FPS', async function () {
@@ -133,7 +143,7 @@ describe('Test video transcoding limits', function () {
const { uuid } = await servers[1].videos.upload({ attributes })
await waitJobs(servers)
- await testFPS(uuid, 15, 15)
+ await testFPS({ uuid, originFPS: 60, averageFPS: 15 })
})
it('Should not duplicate resolution on re-transcoding', async function () {
@@ -141,19 +151,19 @@ describe('Test video transcoding limits', function () {
await updateMaxFPS(50)
- const attributes = { name: 'capped 50fps', fixture: '60fps_720p_small.mp4' }
+ const attributes = { name: 'capped 50fps', fixture: '1080p_60fps.mp4' }
const { uuid } = await servers[1].videos.upload({ attributes })
await waitJobs(servers)
- await testFPS(uuid, 50, 25)
+ await testFPS({ uuid, originFPS: 60, averageFPS: 30, highFPS: 50 })
await servers[1].videos.runTranscoding({ transcodingType: 'web-video', videoId: uuid })
await waitJobs(servers)
const video = await servers[1].videos.get({ id: uuid })
- expect(video.files.map(f => f.resolution.id)).to.deep.equal([ 720, 480, 360, 240, 144 ])
+ expect(video.files.map(f => f.resolution.id)).to.deep.equal([ 1080, 720, 480, 360, 240, 144 ])
- await testFPS(uuid, 50, 25)
+ await testFPS({ uuid, originFPS: 60, averageFPS: 30, highFPS: 50 })
})
after(async function () {
@@ -162,7 +172,6 @@ describe('Test video transcoding limits', function () {
})
describe('Bitrate control', function () {
-
it('Should respect maximum bitrate values', async function () {
this.timeout(160_000)
@@ -251,7 +260,6 @@ describe('Test video transcoding limits', function () {
})
describe('Resolution capping', function () {
-
it('Should not generate an upper resolution than original file', async function () {
this.timeout(120_000)
diff --git a/packages/tests/src/peertube-runner/vod-transcoding.ts b/packages/tests/src/peertube-runner/vod-transcoding.ts
index 21fd85e34f..d5ff0bf95a 100644
--- a/packages/tests/src/peertube-runner/vod-transcoding.ts
+++ b/packages/tests/src/peertube-runner/vod-transcoding.ts
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import { getAllFiles, wait } from '@peertube/peertube-core-utils'
-import { VideoPrivacy } from '@peertube/peertube-models'
+import { VideoPrivacy, VideoResolution } from '@peertube/peertube-models'
import { areMockObjectStorageTestsDisabled } from '@peertube/peertube-node-utils'
import {
cleanupTests,
@@ -304,7 +304,6 @@ describe('Test VOD transcoding in peertube-runner program', function () {
const resolutions = 'max'
describe('Web video only enabled', function () {
-
before(async function () {
await servers[0].config.enableTranscoding({ resolutions, webVideo: true, hls: false, with0p: true })
})
@@ -313,7 +312,6 @@ describe('Test VOD transcoding in peertube-runner program', function () {
})
describe('HLS videos only enabled', function () {
-
before(async function () {
await servers[0].config.enableTranscoding({ resolutions, webVideo: false, hls: true, with0p: true })
})
@@ -322,7 +320,6 @@ describe('Test VOD transcoding in peertube-runner program', function () {
})
describe('HLS only with separated audio only enabled', function () {
-
before(async function () {
await servers[0].config.enableTranscoding({ resolutions, webVideo: false, hls: true, splitAudioAndVideo: true, with0p: true })
})
@@ -331,7 +328,6 @@ describe('Test VOD transcoding in peertube-runner program', function () {
})
describe('Web video & HLS with separated audio only enabled', function () {
-
before(async function () {
await servers[0].config.enableTranscoding({ resolutions, hls: true, webVideo: true, splitAudioAndVideo: true, with0p: true })
})
@@ -340,7 +336,6 @@ describe('Test VOD transcoding in peertube-runner program', function () {
})
describe('Web video & HLS enabled', function () {
-
before(async function () {
await servers[0].config.enableTranscoding({ resolutions, hls: true, webVideo: true, with0p: true, splitAudioAndVideo: false })
})
@@ -350,12 +345,10 @@ describe('Test VOD transcoding in peertube-runner program', function () {
}
describe('With videos on local filesystem storage', function () {
-
runSuites()
describe('Common', function () {
-
- it('Should cap max FPS', async function () {
+ it('Should cap max FPS with HLS and Web Videos enabled', async function () {
this.timeout(120_000)
await servers[0].config.enableTranscoding({ maxFPS: 15, resolutions: [ 240, 480, 720 ], hls: true, webVideo: true })
@@ -368,11 +361,14 @@ describe('Test VOD transcoding in peertube-runner program', function () {
expect(video.files).to.have.lengthOf(3)
expect(hlsFiles).to.have.lengthOf(3)
- const fpsArray = getAllFiles(video).map(f => f.fps)
+ const files = getAllFiles(video)
+ const file720p = files.find(f => f.resolution.id === VideoResolution.H_720P)
+ const file480p = files.find(f => f.resolution.id === VideoResolution.H_480P)
+ const file240p = files.find(f => f.resolution.id === VideoResolution.H_240P)
- for (const fps of fpsArray) {
- expect(fps).to.be.at.most(15)
- }
+ expect(file720p.fps).to.at.least(22)
+ expect(file480p.fps).to.be.at.most(15)
+ expect(file240p.fps).to.be.at.most(15)
})
it('Should not generate an upper resolution than original file', async function () {
@@ -423,7 +419,6 @@ describe('Test VOD transcoding in peertube-runner program', function () {
})
describe('Check cleanup', function () {
-
it('Should have an empty cache directory', async function () {
await checkPeerTubeRunnerCacheIsEmpty(peertubeRunner, 'transcoding')
})
diff --git a/server/core/helpers/ffmpeg/framerate.ts b/server/core/helpers/ffmpeg/framerate.ts
index d1501a0a8c..9eb98501c6 100644
--- a/server/core/helpers/ffmpeg/framerate.ts
+++ b/server/core/helpers/ffmpeg/framerate.ts
@@ -36,8 +36,8 @@ export function computeOutputFPS (options: {
// Cap min FPS
fps = Math.max(fps, settings.TRANSCODED_MIN)
- // Cap max FPS
- if (fps > settings.TRANSCODED_MAX) {
+ // Cap max FPS for non-origin video file
+ if (!isOriginResolution && fps > settings.TRANSCODED_MAX) {
fps = getClosestFramerate({ fps, settings, type: 'HD_STANDARD' })
}