From ca5c612bfdd225433bcc6ace01c8024df3f674ba Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 24 Nov 2020 15:22:56 +0100 Subject: Add live transcoding bit rate tests --- server/tests/api/live/live.ts | 22 ++++++++++++++++++++-- server/tests/api/videos/audio-only.ts | 6 +++--- server/tests/api/videos/video-transcoder.ts | 25 ++++++++++++++----------- server/tests/cli/optimize-old-videos.ts | 4 ++-- server/tests/cli/prune-storage.ts | 14 +++++++------- 5 files changed, 46 insertions(+), 25 deletions(-) (limited to 'server/tests') diff --git a/server/tests/api/live/live.ts b/server/tests/api/live/live.ts index ac91b6b08..e685be08e 100644 --- a/server/tests/api/live/live.ts +++ b/server/tests/api/live/live.ts @@ -3,10 +3,13 @@ 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, @@ -396,10 +399,11 @@ describe('Test live', function () { this.timeout(60000) 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) @@ -409,6 +413,12 @@ describe('Test live', function () { await waitJobs(servers) + const bitrateLimits = { + 720: 2800 * 1000, + 360: 780 * 1000, + 240: 320 * 1000 + } + for (const server of servers) { const resVideo = await getVideo(server.url, liveVideoId) const video: VideoDetails = resVideo.body @@ -424,9 +434,17 @@ describe('Test live', function () { const file = hlsPlaylist.files.find(f => f.resolution.id === resolution) expect(file).to.exist - expect(file.fps).to.be.oneOf([ 24, 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) + console.log(videoStream) + expect(probe.format.bit_rate).to.be.below(bitrateLimits[videoStream.height]) + await makeRawRequest(file.torrentUrl, 200) await makeRawRequest(file.fileUrl, 200) } diff --git a/server/tests/api/videos/audio-only.ts b/server/tests/api/videos/audio-only.ts index 053b29ca1..294a00112 100644 --- a/server/tests/api/videos/audio-only.ts +++ b/server/tests/api/videos/audio-only.ts @@ -5,11 +5,11 @@ import * as chai from 'chai' import { join } from 'path' import { getAudioStream, getVideoStreamSize } from '@server/helpers/ffprobe-utils' import { + buildServerDirectory, cleanupTests, doubleFollow, flushAndRunMultipleServers, getVideo, - root, ServerInfo, setAccessTokensToServers, uploadVideo, @@ -80,8 +80,8 @@ describe('Test audio only video transcoding', function () { it('0p transcoded video should not have video', async function () { const paths = [ - join(root(), 'test' + servers[0].internalServerNumber, 'videos', videoUUID + '-0.mp4'), - join(root(), 'test' + servers[0].internalServerNumber, 'streaming-playlists', 'hls', videoUUID, videoUUID + '-0-fragmented.mp4') + buildServerDirectory(servers[0], join('videos', videoUUID + '-0.mp4')), + buildServerDirectory(servers[0], join('streaming-playlists', 'hls', videoUUID, videoUUID + '-0-fragmented.mp4')) ] for (const path of paths) { diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts index 3e336e786..164843d32 100644 --- a/server/tests/api/videos/video-transcoder.ts +++ b/server/tests/api/videos/video-transcoder.ts @@ -5,10 +5,10 @@ import * as chai from 'chai' import { FfprobeData } from 'fluent-ffmpeg' import { omit } from 'lodash' import { join } from 'path' - import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants' import { buildAbsoluteFixturePath, + buildServerDirectory, cleanupTests, doubleFollow, flushAndRunMultipleServers, @@ -20,7 +20,6 @@ import { getVideoFileMetadataUrl, getVideosList, makeGetRequest, - root, ServerInfo, setAccessTokensToServers, updateCustomSubConfig, @@ -136,7 +135,7 @@ describe('Test video transcoding', function () { expect(videoDetails.files).to.have.lengthOf(4) - const path = join(root(), 'test' + servers[1].internalServerNumber, 'videos', video.uuid + '-240.mp4') + const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-240.mp4')) const probe = await getAudioStream(path) if (probe.audioStream) { @@ -167,7 +166,7 @@ describe('Test video transcoding', function () { const videoDetails: VideoDetails = res2.body expect(videoDetails.files).to.have.lengthOf(4) - const path = join(root(), 'test' + servers[1].internalServerNumber, 'videos', video.uuid + '-240.mp4') + const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-240.mp4')) const probe = await getAudioStream(path) expect(probe).to.not.have.property('audioStream') } @@ -192,10 +191,13 @@ describe('Test video transcoding', function () { const videoDetails: VideoDetails = res2.body expect(videoDetails.files).to.have.lengthOf(4) + const fixturePath = buildAbsoluteFixturePath(videoAttributes.fixture) const fixtureVideoProbe = await getAudioStream(fixturePath) - const path = join(root(), 'test' + servers[1].internalServerNumber, 'videos', video.uuid + '-240.mp4') + const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-240.mp4')) + const videoProbe = await getAudioStream(path) + if (videoProbe.audioStream && fixtureVideoProbe.audioStream) { const toOmit = [ 'max_bit_rate', 'duration', 'duration_ts', 'nb_frames', 'start_time', 'start_pts' ] expect(omit(videoProbe.audioStream, toOmit)).to.be.deep.equal(omit(fixtureVideoProbe.audioStream, toOmit)) @@ -231,13 +233,13 @@ describe('Test video transcoding', function () { expect(videoDetails.files[3].fps).to.be.below(31) for (const resolution of [ '240', '360', '480' ]) { - const path = join(root(), 'test' + servers[1].internalServerNumber, 'videos', video.uuid + '-' + resolution + '.mp4') + const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-' + resolution + '.mp4')) const fps = await getVideoFileFPS(path) expect(fps).to.be.below(31) } - const path = join(root(), 'test' + servers[1].internalServerNumber, 'videos', video.uuid + '-720.mp4') + const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-720.mp4')) const fps = await getVideoFileFPS(path) expect(fps).to.be.above(58).and.below(62) @@ -325,7 +327,8 @@ describe('Test video transcoding', function () { const video = res.body.data.find(v => v.name === videoAttributes.name) for (const resolution of [ '240', '360', '480', '720', '1080' ]) { - const path = join(root(), 'test' + servers[1].internalServerNumber, 'videos', video.uuid + '-' + resolution + '.mp4') + const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-' + resolution + '.mp4')) + const bitrate = await getVideoFileBitrate(path) const fps = await getVideoFileFPS(path) const resolution2 = await getVideoFileResolution(path) @@ -458,13 +461,13 @@ describe('Test video transcoding', function () { const video = res.body.data.find(v => v.name === videoAttributes.name) { - const path = join(root(), 'test' + servers[1].internalServerNumber, 'videos', video.uuid + '-240.mp4') + const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-240.mp4')) const fps = await getVideoFileFPS(path) expect(fps).to.be.equal(25) } { - const path = join(root(), 'test' + servers[1].internalServerNumber, 'videos', video.uuid + '-720.mp4') + const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-720.mp4')) const fps = await getVideoFileFPS(path) expect(fps).to.be.equal(59) } @@ -513,7 +516,7 @@ describe('Test video transcoding', function () { await waitJobs(servers) { - const path = join(root(), 'test' + servers[1].internalServerNumber, 'videos', videoUUID + '-240.mp4') + const path = buildServerDirectory(servers[1], join('videos', videoUUID + '-240.mp4')) const metadata = await getMetadataFromFile(path) // expected format properties diff --git a/server/tests/cli/optimize-old-videos.ts b/server/tests/cli/optimize-old-videos.ts index 420fb8049..91a1c9cc4 100644 --- a/server/tests/cli/optimize-old-videos.ts +++ b/server/tests/cli/optimize-old-videos.ts @@ -4,6 +4,7 @@ import 'mocha' import * as chai from 'chai' import { join } from 'path' import { + buildServerDirectory, cleanupTests, doubleFollow, execCLI, @@ -12,7 +13,6 @@ import { getEnvCli, getVideo, getVideosList, - root, ServerInfo, setAccessTokensToServers, uploadVideo, @@ -100,7 +100,7 @@ describe('Test optimize old videos', function () { expect(file.size).to.be.below(8000000) - const path = join(root(), 'test' + servers[0].internalServerNumber, 'videos', video.uuid + '-' + file.resolution.id + '.mp4') + const path = buildServerDirectory(servers[0], join('videos', video.uuid + '-' + file.resolution.id + '.mp4')) const bitrate = await getVideoFileBitrate(path) const fps = await getVideoFileFPS(path) const resolution = await getVideoFileResolution(path) diff --git a/server/tests/cli/prune-storage.ts b/server/tests/cli/prune-storage.ts index 6cda80070..052a5f91e 100644 --- a/server/tests/cli/prune-storage.ts +++ b/server/tests/cli/prune-storage.ts @@ -28,13 +28,13 @@ import { join } from 'path' const expect = chai.expect async function countFiles (internalServerNumber: number, directory: string) { - const files = await readdir(buildServerDirectory(internalServerNumber, directory)) + const files = await readdir(buildServerDirectory({ internalServerNumber }, directory)) return files.length } async function assertNotExists (internalServerNumber: number, directory: string, substring: string) { - const files = await readdir(buildServerDirectory(internalServerNumber, directory)) + const files = await readdir(buildServerDirectory({ internalServerNumber }, directory)) for (const f of files) { expect(f).to.not.contain(substring) @@ -124,7 +124,7 @@ describe('Test prune storage scripts', function () { it('Should create some dirty files', async function () { for (let i = 0; i < 2; i++) { { - const base = buildServerDirectory(servers[0].internalServerNumber, 'videos') + const base = buildServerDirectory(servers[0], 'videos') const n1 = uuidv4() + '.mp4' const n2 = uuidv4() + '.webm' @@ -136,7 +136,7 @@ describe('Test prune storage scripts', function () { } { - const base = buildServerDirectory(servers[0].internalServerNumber, 'torrents') + const base = buildServerDirectory(servers[0], 'torrents') const n1 = uuidv4() + '-240.torrent' const n2 = uuidv4() + '-480.torrent' @@ -148,7 +148,7 @@ describe('Test prune storage scripts', function () { } { - const base = buildServerDirectory(servers[0].internalServerNumber, 'thumbnails') + const base = buildServerDirectory(servers[0], 'thumbnails') const n1 = uuidv4() + '.jpg' const n2 = uuidv4() + '.jpg' @@ -160,7 +160,7 @@ describe('Test prune storage scripts', function () { } { - const base = buildServerDirectory(servers[0].internalServerNumber, 'previews') + const base = buildServerDirectory(servers[0], 'previews') const n1 = uuidv4() + '.jpg' const n2 = uuidv4() + '.jpg' @@ -172,7 +172,7 @@ describe('Test prune storage scripts', function () { } { - const base = buildServerDirectory(servers[0].internalServerNumber, 'avatars') + const base = buildServerDirectory(servers[0], 'avatars') const n1 = uuidv4() + '.png' const n2 = uuidv4() + '.jpg' -- cgit v1.2.3