From 3a4992633ee62d5edfbb484d9c6bcb3cf158489d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 31 Jul 2023 14:34:36 +0200 Subject: Migrate server to ESM Sorry for the very big commit that may lead to git log issues and merge conflicts, but it's a major step forward: * Server can be faster at startup because imports() are async and we can easily lazy import big modules * Angular doesn't seem to support ES import (with .js extension), so we had to correctly organize peertube into a monorepo: * Use yarn workspace feature * Use typescript reference projects for dependencies * Shared projects have been moved into "packages", each one is now a node module (with a dedicated package.json/tsconfig.json) * server/tools have been moved into apps/ and is now a dedicated app bundled and published on NPM so users don't have to build peertube cli tools manually * server/tests have been moved into packages/ so we don't compile them every time we want to run the server * Use isolatedModule option: * Had to move from const enum to const (https://www.typescriptlang.org/docs/handbook/enums.html#objects-vs-enums) * Had to explictely specify "type" imports when used in decorators * Prefer tsx (that uses esbuild under the hood) instead of ts-node to load typescript files (tests with mocha or scripts): * To reduce test complexity as esbuild doesn't support decorator metadata, we only test server files that do not import server models * We still build tests files into js files for a faster CI * Remove unmaintained peertube CLI import script * Removed some barrels to speed up execution (less imports) --- server/tests/api/transcoding/audio-only.ts | 104 --- server/tests/api/transcoding/create-transcoding.ts | 266 ------- server/tests/api/transcoding/hls.ts | 175 ----- server/tests/api/transcoding/index.ts | 6 - server/tests/api/transcoding/transcoder.ts | 800 --------------------- .../api/transcoding/update-while-transcoding.ts | 160 ----- server/tests/api/transcoding/video-studio.ts | 377 ---------- 7 files changed, 1888 deletions(-) delete mode 100644 server/tests/api/transcoding/audio-only.ts delete mode 100644 server/tests/api/transcoding/create-transcoding.ts delete mode 100644 server/tests/api/transcoding/hls.ts delete mode 100644 server/tests/api/transcoding/index.ts delete mode 100644 server/tests/api/transcoding/transcoder.ts delete mode 100644 server/tests/api/transcoding/update-while-transcoding.ts delete mode 100644 server/tests/api/transcoding/video-studio.ts (limited to 'server/tests/api/transcoding') diff --git a/server/tests/api/transcoding/audio-only.ts b/server/tests/api/transcoding/audio-only.ts deleted file mode 100644 index f4cc012ef..000000000 --- a/server/tests/api/transcoding/audio-only.ts +++ /dev/null @@ -1,104 +0,0 @@ -/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ - -import { expect } from 'chai' -import { getAudioStream, getVideoStreamDimensionsInfo } from '@shared/ffmpeg' -import { - cleanupTests, - createMultipleServers, - doubleFollow, - PeerTubeServer, - setAccessTokensToServers, - waitJobs -} from '@shared/server-commands' - -describe('Test audio only video transcoding', function () { - let servers: PeerTubeServer[] = [] - let videoUUID: string - let webVideoAudioFileUrl: string - let fragmentedAudioFileUrl: string - - before(async function () { - this.timeout(120000) - - const configOverride = { - transcoding: { - enabled: true, - resolutions: { - '0p': true, - '144p': false, - '240p': true, - '360p': false, - '480p': false, - '720p': false, - '1080p': false, - '1440p': false, - '2160p': false - }, - hls: { - enabled: true - }, - web_videos: { - enabled: true - } - } - } - servers = await createMultipleServers(2, configOverride) - - // Get the access tokens - await setAccessTokensToServers(servers) - - // Server 1 and server 2 follow each other - await doubleFollow(servers[0], servers[1]) - }) - - it('Should upload a video and transcode it', async function () { - this.timeout(120000) - - const { uuid } = await servers[0].videos.upload({ attributes: { name: 'audio only' } }) - videoUUID = uuid - - await waitJobs(servers) - - for (const server of servers) { - const video = await server.videos.get({ id: videoUUID }) - expect(video.streamingPlaylists).to.have.lengthOf(1) - - for (const files of [ video.files, video.streamingPlaylists[0].files ]) { - expect(files).to.have.lengthOf(3) - expect(files[0].resolution.id).to.equal(720) - expect(files[1].resolution.id).to.equal(240) - expect(files[2].resolution.id).to.equal(0) - } - - if (server.serverNumber === 1) { - webVideoAudioFileUrl = video.files[2].fileUrl - fragmentedAudioFileUrl = video.streamingPlaylists[0].files[2].fileUrl - } - } - }) - - it('0p transcoded video should not have video', async function () { - const paths = [ - servers[0].servers.buildWebVideoFilePath(webVideoAudioFileUrl), - servers[0].servers.buildFragmentedFilePath(videoUUID, fragmentedAudioFileUrl) - ] - - for (const path of paths) { - const { audioStream } = await getAudioStream(path) - expect(audioStream['codec_name']).to.be.equal('aac') - expect(audioStream['bit_rate']).to.be.at.most(384 * 8000) - - const size = await getVideoStreamDimensionsInfo(path) - - expect(size.height).to.equal(0) - expect(size.width).to.equal(0) - expect(size.isPortraitMode).to.be.false - expect(size.ratio).to.equal(0) - expect(size.resolution).to.equal(0) - } - }) - - after(async function () { - await cleanupTests(servers) - }) -}) diff --git a/server/tests/api/transcoding/create-transcoding.ts b/server/tests/api/transcoding/create-transcoding.ts deleted file mode 100644 index 9a891043c..000000000 --- a/server/tests/api/transcoding/create-transcoding.ts +++ /dev/null @@ -1,266 +0,0 @@ -/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ - -import { expect } from 'chai' -import { checkResolutionsInMasterPlaylist, expectStartWith } from '@server/tests/shared' -import { areMockObjectStorageTestsDisabled } from '@shared/core-utils' -import { HttpStatusCode, VideoDetails } from '@shared/models' -import { - cleanupTests, - ConfigCommand, - createMultipleServers, - doubleFollow, - expectNoFailedTranscodingJob, - makeRawRequest, - ObjectStorageCommand, - PeerTubeServer, - setAccessTokensToServers, - waitJobs -} from '@shared/server-commands' - -async function checkFilesInObjectStorage (objectStorage: ObjectStorageCommand, video: VideoDetails) { - for (const file of video.files) { - expectStartWith(file.fileUrl, objectStorage.getMockWebVideosBaseUrl()) - await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 }) - } - - if (video.streamingPlaylists.length === 0) return - - const hlsPlaylist = video.streamingPlaylists[0] - for (const file of hlsPlaylist.files) { - expectStartWith(file.fileUrl, objectStorage.getMockPlaylistBaseUrl()) - await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 }) - } - - expectStartWith(hlsPlaylist.playlistUrl, objectStorage.getMockPlaylistBaseUrl()) - await makeRawRequest({ url: hlsPlaylist.playlistUrl, expectedStatus: HttpStatusCode.OK_200 }) - - expectStartWith(hlsPlaylist.segmentsSha256Url, objectStorage.getMockPlaylistBaseUrl()) - await makeRawRequest({ url: hlsPlaylist.segmentsSha256Url, expectedStatus: HttpStatusCode.OK_200 }) -} - -function runTests (enableObjectStorage: boolean) { - let servers: PeerTubeServer[] = [] - let videoUUID: string - let publishedAt: string - - let shouldBeDeleted: string[] - const objectStorage = new ObjectStorageCommand() - - before(async function () { - this.timeout(120000) - - const config = enableObjectStorage - ? objectStorage.getDefaultMockConfig() - : {} - - // Run server 2 to have transcoding enabled - servers = await createMultipleServers(2, config) - await setAccessTokensToServers(servers) - - await servers[0].config.disableTranscoding() - - await doubleFollow(servers[0], servers[1]) - - if (enableObjectStorage) await objectStorage.prepareDefaultMockBuckets() - - const { shortUUID } = await servers[0].videos.quickUpload({ name: 'video' }) - videoUUID = shortUUID - - await waitJobs(servers) - - const video = await servers[0].videos.get({ id: videoUUID }) - publishedAt = video.publishedAt as string - - await servers[0].config.enableTranscoding() - }) - - it('Should generate HLS', async function () { - this.timeout(60000) - - await servers[0].videos.runTranscoding({ - videoId: videoUUID, - transcodingType: 'hls' - }) - - await waitJobs(servers) - await expectNoFailedTranscodingJob(servers[0]) - - for (const server of servers) { - const videoDetails = await server.videos.get({ id: videoUUID }) - - expect(videoDetails.files).to.have.lengthOf(1) - expect(videoDetails.streamingPlaylists).to.have.lengthOf(1) - expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(5) - - if (enableObjectStorage) await checkFilesInObjectStorage(objectStorage, videoDetails) - } - }) - - it('Should generate Web Video', async function () { - this.timeout(60000) - - await servers[0].videos.runTranscoding({ - videoId: videoUUID, - transcodingType: 'web-video' - }) - - await waitJobs(servers) - - for (const server of servers) { - const videoDetails = await server.videos.get({ id: videoUUID }) - - expect(videoDetails.files).to.have.lengthOf(5) - expect(videoDetails.streamingPlaylists).to.have.lengthOf(1) - expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(5) - - if (enableObjectStorage) await checkFilesInObjectStorage(objectStorage, videoDetails) - } - }) - - it('Should generate Web Video from HLS only video', async function () { - this.timeout(60000) - - await servers[0].videos.removeAllWebVideoFiles({ videoId: videoUUID }) - await waitJobs(servers) - - await servers[0].videos.runTranscoding({ videoId: videoUUID, transcodingType: 'web-video' }) - await waitJobs(servers) - - for (const server of servers) { - const videoDetails = await server.videos.get({ id: videoUUID }) - - expect(videoDetails.files).to.have.lengthOf(5) - expect(videoDetails.streamingPlaylists).to.have.lengthOf(1) - expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(5) - - if (enableObjectStorage) await checkFilesInObjectStorage(objectStorage, videoDetails) - } - }) - - it('Should only generate Web Video', async function () { - this.timeout(60000) - - await servers[0].videos.removeHLSPlaylist({ videoId: videoUUID }) - await waitJobs(servers) - - await servers[0].videos.runTranscoding({ videoId: videoUUID, transcodingType: 'web-video' }) - await waitJobs(servers) - - for (const server of servers) { - const videoDetails = await server.videos.get({ id: videoUUID }) - - expect(videoDetails.files).to.have.lengthOf(5) - expect(videoDetails.streamingPlaylists).to.have.lengthOf(0) - - if (enableObjectStorage) await checkFilesInObjectStorage(objectStorage, videoDetails) - } - }) - - it('Should correctly update HLS playlist on resolution change', async function () { - this.timeout(120000) - - await servers[0].config.updateExistingSubConfig({ - newConfig: { - transcoding: { - enabled: true, - resolutions: ConfigCommand.getCustomConfigResolutions(false), - - webVideos: { - enabled: true - }, - hls: { - enabled: true - } - } - } - }) - - const { uuid } = await servers[0].videos.quickUpload({ name: 'quick' }) - - await waitJobs(servers) - - for (const server of servers) { - const videoDetails = await server.videos.get({ id: uuid }) - - expect(videoDetails.files).to.have.lengthOf(1) - expect(videoDetails.streamingPlaylists).to.have.lengthOf(1) - expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(1) - - if (enableObjectStorage) await checkFilesInObjectStorage(objectStorage, videoDetails) - - shouldBeDeleted = [ - videoDetails.streamingPlaylists[0].files[0].fileUrl, - videoDetails.streamingPlaylists[0].playlistUrl, - videoDetails.streamingPlaylists[0].segmentsSha256Url - ] - } - - await servers[0].config.updateExistingSubConfig({ - newConfig: { - transcoding: { - enabled: true, - resolutions: ConfigCommand.getCustomConfigResolutions(true), - - webVideos: { - enabled: true - }, - hls: { - enabled: true - } - } - } - }) - - await servers[0].videos.runTranscoding({ videoId: uuid, transcodingType: 'hls' }) - await waitJobs(servers) - - for (const server of servers) { - const videoDetails = await server.videos.get({ id: uuid }) - - expect(videoDetails.streamingPlaylists).to.have.lengthOf(1) - expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(5) - - if (enableObjectStorage) { - await checkFilesInObjectStorage(objectStorage, videoDetails) - - const hlsPlaylist = videoDetails.streamingPlaylists[0] - const resolutions = hlsPlaylist.files.map(f => f.resolution.id) - await checkResolutionsInMasterPlaylist({ server: servers[0], playlistUrl: hlsPlaylist.playlistUrl, resolutions }) - - const shaBody = await servers[0].streamingPlaylists.getSegmentSha256({ url: hlsPlaylist.segmentsSha256Url, withRetry: true }) - expect(Object.keys(shaBody)).to.have.lengthOf(5) - } - } - }) - - it('Should have correctly deleted previous files', async function () { - for (const fileUrl of shouldBeDeleted) { - await makeRawRequest({ url: fileUrl, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) - } - }) - - it('Should not have updated published at attributes', async function () { - const video = await servers[0].videos.get({ id: videoUUID }) - - expect(video.publishedAt).to.equal(publishedAt) - }) - - after(async function () { - if (objectStorage) await objectStorage.cleanupMock() - - await cleanupTests(servers) - }) -} - -describe('Test create transcoding jobs from API', function () { - - describe('On filesystem', function () { - runTests(false) - }) - - describe('On object storage', function () { - if (areMockObjectStorageTestsDisabled()) return - - runTests(true) - }) -}) diff --git a/server/tests/api/transcoding/hls.ts b/server/tests/api/transcoding/hls.ts deleted file mode 100644 index d67043c2a..000000000 --- a/server/tests/api/transcoding/hls.ts +++ /dev/null @@ -1,175 +0,0 @@ -/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ - -import { join } from 'path' -import { checkDirectoryIsEmpty, checkTmpIsEmpty, completeCheckHlsPlaylist } from '@server/tests/shared' -import { areMockObjectStorageTestsDisabled } from '@shared/core-utils' -import { HttpStatusCode } from '@shared/models' -import { - cleanupTests, - createMultipleServers, - doubleFollow, - ObjectStorageCommand, - PeerTubeServer, - setAccessTokensToServers, - waitJobs -} from '@shared/server-commands' -import { DEFAULT_AUDIO_RESOLUTION } from '../../../initializers/constants' - -describe('Test HLS videos', function () { - let servers: PeerTubeServer[] = [] - - function runTestSuite (hlsOnly: boolean, objectStorageBaseUrl?: string) { - const videoUUIDs: string[] = [] - - it('Should upload a video and transcode it to HLS', async function () { - this.timeout(120000) - - const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video 1', fixture: 'video_short.webm' } }) - videoUUIDs.push(uuid) - - await waitJobs(servers) - - await completeCheckHlsPlaylist({ servers, videoUUID: uuid, hlsOnly, objectStorageBaseUrl }) - }) - - it('Should upload an audio file and transcode it to HLS', async function () { - this.timeout(120000) - - const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video audio', fixture: 'sample.ogg' } }) - videoUUIDs.push(uuid) - - await waitJobs(servers) - - await completeCheckHlsPlaylist({ - servers, - videoUUID: uuid, - hlsOnly, - resolutions: [ DEFAULT_AUDIO_RESOLUTION, 360, 240 ], - objectStorageBaseUrl - }) - }) - - it('Should update the video', async function () { - this.timeout(30000) - - await servers[0].videos.update({ id: videoUUIDs[0], attributes: { name: 'video 1 updated' } }) - - await waitJobs(servers) - - await completeCheckHlsPlaylist({ servers, videoUUID: videoUUIDs[0], hlsOnly, objectStorageBaseUrl }) - }) - - it('Should delete videos', async function () { - for (const uuid of videoUUIDs) { - await servers[0].videos.remove({ id: uuid }) - } - - await waitJobs(servers) - - for (const server of servers) { - for (const uuid of videoUUIDs) { - await server.videos.get({ id: uuid, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) - } - } - }) - - it('Should have the playlists/segment deleted from the disk', async function () { - for (const server of servers) { - await checkDirectoryIsEmpty(server, 'web-videos', [ 'private' ]) - await checkDirectoryIsEmpty(server, join('web-videos', 'private')) - - await checkDirectoryIsEmpty(server, join('streaming-playlists', 'hls'), [ 'private' ]) - await checkDirectoryIsEmpty(server, join('streaming-playlists', 'hls', 'private')) - } - }) - - it('Should have an empty tmp directory', async function () { - for (const server of servers) { - await checkTmpIsEmpty(server) - } - }) - } - - before(async function () { - this.timeout(120000) - - const configOverride = { - transcoding: { - enabled: true, - allow_audio_files: true, - hls: { - enabled: true - } - } - } - servers = await createMultipleServers(2, configOverride) - - // Get the access tokens - await setAccessTokensToServers(servers) - - // Server 1 and server 2 follow each other - await doubleFollow(servers[0], servers[1]) - }) - - describe('With Web Video & HLS enabled', function () { - runTestSuite(false) - }) - - describe('With only HLS enabled', function () { - - before(async function () { - await servers[0].config.updateCustomSubConfig({ - newConfig: { - transcoding: { - enabled: true, - allowAudioFiles: true, - resolutions: { - '144p': false, - '240p': true, - '360p': true, - '480p': true, - '720p': true, - '1080p': true, - '1440p': true, - '2160p': true - }, - hls: { - enabled: true - }, - webVideos: { - enabled: false - } - } - } - }) - }) - - runTestSuite(true) - }) - - describe('With object storage enabled', function () { - if (areMockObjectStorageTestsDisabled()) return - - const objectStorage = new ObjectStorageCommand() - - before(async function () { - this.timeout(120000) - - const configOverride = objectStorage.getDefaultMockConfig() - await objectStorage.prepareDefaultMockBuckets() - - await servers[0].kill() - await servers[0].run(configOverride) - }) - - runTestSuite(true, objectStorage.getMockPlaylistBaseUrl()) - - after(async function () { - await objectStorage.cleanupMock() - }) - }) - - after(async function () { - await cleanupTests(servers) - }) -}) diff --git a/server/tests/api/transcoding/index.ts b/server/tests/api/transcoding/index.ts deleted file mode 100644 index 9866418d6..000000000 --- a/server/tests/api/transcoding/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -export * from './audio-only' -export * from './create-transcoding' -export * from './hls' -export * from './transcoder' -export * from './update-while-transcoding' -export * from './video-studio' diff --git a/server/tests/api/transcoding/transcoder.ts b/server/tests/api/transcoding/transcoder.ts deleted file mode 100644 index 5386d236f..000000000 --- a/server/tests/api/transcoding/transcoder.ts +++ /dev/null @@ -1,800 +0,0 @@ -/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ - -import { expect } from 'chai' -import { canDoQuickTranscode } from '@server/lib/transcoding/transcoding-quick-transcode' -import { checkWebTorrentWorks, generateHighBitrateVideo, generateVideoWithFramerate } from '@server/tests/shared' -import { buildAbsoluteFixturePath, getAllFiles, getMaxTheoreticalBitrate, getMinTheoreticalBitrate, omit } from '@shared/core-utils' -import { - ffprobePromise, - getAudioStream, - getVideoStreamBitrate, - getVideoStreamDimensionsInfo, - getVideoStreamFPS, - hasAudioStream -} from '@shared/ffmpeg' -import { HttpStatusCode, VideoFileMetadata, VideoState } from '@shared/models' -import { - cleanupTests, - createMultipleServers, - doubleFollow, - makeGetRequest, - PeerTubeServer, - setAccessTokensToServers, - waitJobs -} from '@shared/server-commands' - -function updateConfigForTranscoding (server: PeerTubeServer) { - return server.config.updateCustomSubConfig({ - newConfig: { - transcoding: { - enabled: true, - allowAdditionalExtensions: true, - allowAudioFiles: true, - hls: { enabled: true }, - webVideos: { enabled: true }, - resolutions: { - '0p': false, - '144p': true, - '240p': true, - '360p': true, - '480p': true, - '720p': true, - '1080p': true, - '1440p': true, - '2160p': true - } - } - } - }) -} - -describe('Test video transcoding', function () { - let servers: PeerTubeServer[] = [] - let video4k: string - - before(async function () { - this.timeout(30_000) - - // Run servers - servers = await createMultipleServers(2) - - await setAccessTokensToServers(servers) - - await doubleFollow(servers[0], servers[1]) - - await updateConfigForTranscoding(servers[1]) - }) - - describe('Basic transcoding (or not)', function () { - - it('Should not transcode video on server 1', async function () { - this.timeout(60_000) - - const attributes = { - name: 'my super name for server 1', - description: 'my super description for server 1', - fixture: 'video_short.webm' - } - await servers[0].videos.upload({ attributes }) - - await waitJobs(servers) - - for (const server of servers) { - const { data } = await server.videos.list() - const video = data[0] - - const videoDetails = await server.videos.get({ id: video.id }) - expect(videoDetails.files).to.have.lengthOf(1) - - const magnetUri = videoDetails.files[0].magnetUri - expect(magnetUri).to.match(/\.webm/) - - await checkWebTorrentWorks(magnetUri, /\.webm$/) - } - }) - - it('Should transcode video on server 2', async function () { - this.timeout(120_000) - - const attributes = { - name: 'my super name for server 2', - description: 'my super description for server 2', - fixture: 'video_short.webm' - } - await servers[1].videos.upload({ attributes }) - - await waitJobs(servers) - - for (const server of servers) { - const { data } = await server.videos.list() - - const video = data.find(v => v.name === attributes.name) - const videoDetails = await server.videos.get({ id: video.id }) - - expect(videoDetails.files).to.have.lengthOf(5) - - const magnetUri = videoDetails.files[0].magnetUri - expect(magnetUri).to.match(/\.mp4/) - - await checkWebTorrentWorks(magnetUri, /\.mp4$/) - } - }) - - it('Should wait for transcoding before publishing the video', async function () { - this.timeout(160_000) - - { - // Upload the video, but wait transcoding - const attributes = { - name: 'waiting video', - fixture: 'video_short1.webm', - waitTranscoding: true - } - const { uuid } = await servers[1].videos.upload({ attributes }) - const videoId = uuid - - // Should be in transcode state - const body = await servers[1].videos.get({ id: videoId }) - expect(body.name).to.equal('waiting video') - expect(body.state.id).to.equal(VideoState.TO_TRANSCODE) - expect(body.state.label).to.equal('To transcode') - expect(body.waitTranscoding).to.be.true - - { - // Should have my video - const { data } = await servers[1].videos.listMyVideos() - const videoToFindInMine = data.find(v => v.name === attributes.name) - expect(videoToFindInMine).not.to.be.undefined - expect(videoToFindInMine.state.id).to.equal(VideoState.TO_TRANSCODE) - expect(videoToFindInMine.state.label).to.equal('To transcode') - expect(videoToFindInMine.waitTranscoding).to.be.true - } - - { - // Should not list this video - const { data } = await servers[1].videos.list() - const videoToFindInList = data.find(v => v.name === attributes.name) - expect(videoToFindInList).to.be.undefined - } - - // Server 1 should not have the video yet - await servers[0].videos.get({ id: videoId, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) - } - - await waitJobs(servers) - - for (const server of servers) { - const { data } = await server.videos.list() - const videoToFind = data.find(v => v.name === 'waiting video') - expect(videoToFind).not.to.be.undefined - - const videoDetails = await server.videos.get({ id: videoToFind.id }) - - expect(videoDetails.state.id).to.equal(VideoState.PUBLISHED) - expect(videoDetails.state.label).to.equal('Published') - expect(videoDetails.waitTranscoding).to.be.true - } - }) - - it('Should accept and transcode additional extensions', async function () { - this.timeout(300_000) - - for (const fixture of [ 'video_short.mkv', 'video_short.avi' ]) { - const attributes = { - name: fixture, - fixture - } - - await servers[1].videos.upload({ attributes }) - - await waitJobs(servers) - - for (const server of servers) { - const { data } = await server.videos.list() - - const video = data.find(v => v.name === attributes.name) - const videoDetails = await server.videos.get({ id: video.id }) - expect(videoDetails.files).to.have.lengthOf(5) - - const magnetUri = videoDetails.files[0].magnetUri - expect(magnetUri).to.contain('.mp4') - } - } - }) - - it('Should transcode a 4k video', async function () { - this.timeout(200_000) - - const attributes = { - name: '4k video', - fixture: 'video_short_4k.mp4' - } - - const { uuid } = await servers[1].videos.upload({ attributes }) - video4k = uuid - - await waitJobs(servers) - - const resolutions = [ 144, 240, 360, 480, 720, 1080, 1440, 2160 ] - - for (const server of servers) { - const videoDetails = await server.videos.get({ id: video4k }) - expect(videoDetails.files).to.have.lengthOf(resolutions.length) - - for (const r of resolutions) { - expect(videoDetails.files.find(f => f.resolution.id === r)).to.not.be.undefined - expect(videoDetails.streamingPlaylists[0].files.find(f => f.resolution.id === r)).to.not.be.undefined - } - } - }) - }) - - describe('Audio transcoding', function () { - - it('Should transcode high bit rate mp3 to proper bit rate', async function () { - this.timeout(60_000) - - const attributes = { - name: 'mp3_256k', - fixture: 'video_short_mp3_256k.mp4' - } - await servers[1].videos.upload({ attributes }) - - await waitJobs(servers) - - for (const server of servers) { - const { data } = await server.videos.list() - - const video = data.find(v => v.name === attributes.name) - const videoDetails = await server.videos.get({ id: video.id }) - - expect(videoDetails.files).to.have.lengthOf(5) - - const file = videoDetails.files.find(f => f.resolution.id === 240) - const path = servers[1].servers.buildWebVideoFilePath(file.fileUrl) - const probe = await getAudioStream(path) - - if (probe.audioStream) { - expect(probe.audioStream['codec_name']).to.be.equal('aac') - expect(probe.audioStream['bit_rate']).to.be.at.most(384 * 8000) - } else { - this.fail('Could not retrieve the audio stream on ' + probe.absolutePath) - } - } - }) - - it('Should transcode video with no audio and have no audio itself', async function () { - this.timeout(60_000) - - const attributes = { - name: 'no_audio', - fixture: 'video_short_no_audio.mp4' - } - await servers[1].videos.upload({ attributes }) - - await waitJobs(servers) - - for (const server of servers) { - const { data } = await server.videos.list() - - const video = data.find(v => v.name === attributes.name) - const videoDetails = await server.videos.get({ id: video.id }) - - const file = videoDetails.files.find(f => f.resolution.id === 240) - const path = servers[1].servers.buildWebVideoFilePath(file.fileUrl) - - expect(await hasAudioStream(path)).to.be.false - } - }) - - it('Should leave the audio untouched, but properly transcode the video', async function () { - this.timeout(60_000) - - const attributes = { - name: 'untouched_audio', - fixture: 'video_short.mp4' - } - await servers[1].videos.upload({ attributes }) - - await waitJobs(servers) - - for (const server of servers) { - const { data } = await server.videos.list() - - const video = data.find(v => v.name === attributes.name) - const videoDetails = await server.videos.get({ id: video.id }) - - expect(videoDetails.files).to.have.lengthOf(5) - - const fixturePath = buildAbsoluteFixturePath(attributes.fixture) - const fixtureVideoProbe = await getAudioStream(fixturePath) - - const file = videoDetails.files.find(f => f.resolution.id === 240) - const path = servers[1].servers.buildWebVideoFilePath(file.fileUrl) - - 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)) - } else { - this.fail('Could not retrieve the audio stream on ' + videoProbe.absolutePath) - } - } - }) - }) - - describe('Audio upload', function () { - - function runSuite (mode: 'legacy' | 'resumable') { - - before(async function () { - await servers[1].config.updateCustomSubConfig({ - newConfig: { - transcoding: { - hls: { enabled: true }, - webVideos: { enabled: true }, - resolutions: { - '0p': false, - '144p': false, - '240p': false, - '360p': false, - '480p': false, - '720p': false, - '1080p': false, - '1440p': false, - '2160p': false - } - } - } - }) - }) - - it('Should merge an audio file with the preview file', async function () { - this.timeout(60_000) - - const attributes = { name: 'audio_with_preview', previewfile: 'custom-preview.jpg', fixture: 'sample.ogg' } - await servers[1].videos.upload({ attributes, mode }) - - await waitJobs(servers) - - for (const server of servers) { - const { data } = await server.videos.list() - - const video = data.find(v => v.name === 'audio_with_preview') - const videoDetails = await server.videos.get({ id: video.id }) - - expect(videoDetails.files).to.have.lengthOf(1) - - await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, expectedStatus: HttpStatusCode.OK_200 }) - await makeGetRequest({ url: server.url, path: videoDetails.previewPath, expectedStatus: HttpStatusCode.OK_200 }) - - const magnetUri = videoDetails.files[0].magnetUri - expect(magnetUri).to.contain('.mp4') - } - }) - - it('Should upload an audio file and choose a default background image', async function () { - this.timeout(60_000) - - const attributes = { name: 'audio_without_preview', fixture: 'sample.ogg' } - await servers[1].videos.upload({ attributes, mode }) - - await waitJobs(servers) - - for (const server of servers) { - const { data } = await server.videos.list() - - const video = data.find(v => v.name === 'audio_without_preview') - const videoDetails = await server.videos.get({ id: video.id }) - - expect(videoDetails.files).to.have.lengthOf(1) - - await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, expectedStatus: HttpStatusCode.OK_200 }) - await makeGetRequest({ url: server.url, path: videoDetails.previewPath, expectedStatus: HttpStatusCode.OK_200 }) - - const magnetUri = videoDetails.files[0].magnetUri - expect(magnetUri).to.contain('.mp4') - } - }) - - it('Should upload an audio file and create an audio version only', async function () { - this.timeout(60_000) - - await servers[1].config.updateCustomSubConfig({ - newConfig: { - transcoding: { - hls: { enabled: true }, - webVideos: { enabled: true }, - resolutions: { - '0p': true, - '144p': false, - '240p': false, - '360p': false - } - } - } - }) - - const attributes = { name: 'audio_with_preview', previewfile: 'custom-preview.jpg', fixture: 'sample.ogg' } - const { id } = await servers[1].videos.upload({ attributes, mode }) - - await waitJobs(servers) - - for (const server of servers) { - const videoDetails = await server.videos.get({ id }) - - for (const files of [ videoDetails.files, videoDetails.streamingPlaylists[0].files ]) { - expect(files).to.have.lengthOf(2) - expect(files.find(f => f.resolution.id === 0)).to.not.be.undefined - } - } - - await updateConfigForTranscoding(servers[1]) - }) - } - - describe('Legacy upload', function () { - runSuite('legacy') - }) - - describe('Resumable upload', function () { - runSuite('resumable') - }) - }) - - describe('Framerate', function () { - - it('Should transcode a 60 FPS video', async function () { - this.timeout(60_000) - - const attributes = { - name: 'my super 30fps name for server 2', - description: 'my super 30fps description for server 2', - fixture: '60fps_720p_small.mp4' - } - await servers[1].videos.upload({ attributes }) - - await waitJobs(servers) - - for (const server of servers) { - const { data } = await server.videos.list() - - const video = data.find(v => v.name === attributes.name) - const videoDetails = await server.videos.get({ id: video.id }) - - 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 [ 144, 240, 360, 480 ]) { - const file = videoDetails.files.find(f => f.resolution.id === resolution) - const path = servers[1].servers.buildWebVideoFilePath(file.fileUrl) - 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.buildWebVideoFilePath(file.fileUrl) - const fps = await getVideoStreamFPS(path) - - expect(fps).to.be.above(58).and.below(62) - } - }) - - it('Should downscale to the closest divisor standard framerate', async function () { - this.timeout(200_000) - - let tempFixturePath: string - - { - tempFixturePath = await generateVideoWithFramerate(59) - - const fps = await getVideoStreamFPS(tempFixturePath) - expect(fps).to.be.equal(59) - } - - const attributes = { - name: '59fps video', - description: '59fps video', - fixture: tempFixturePath - } - - await servers[1].videos.upload({ attributes }) - - await waitJobs(servers) - - for (const server of servers) { - const { data } = await server.videos.list() - - const { id } = data.find(v => v.name === attributes.name) - const video = await server.videos.get({ id }) - - { - const file = video.files.find(f => f.resolution.id === 240) - const path = servers[1].servers.buildWebVideoFilePath(file.fileUrl) - 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.buildWebVideoFilePath(file.fileUrl) - const fps = await getVideoStreamFPS(path) - expect(fps).to.be.equal(59) - } - } - }) - }) - - describe('Bitrate control', function () { - - it('Should respect maximum bitrate values', async function () { - this.timeout(160_000) - - const tempFixturePath = await generateHighBitrateVideo() - - const attributes = { - name: 'high bitrate video', - description: 'high bitrate video', - fixture: tempFixturePath - } - - await servers[1].videos.upload({ attributes }) - - await waitJobs(servers) - - for (const server of servers) { - const { data } = await server.videos.list() - - const { id } = data.find(v => v.name === attributes.name) - const video = await server.videos.get({ id }) - - for (const resolution of [ 240, 360, 480, 720, 1080 ]) { - const file = video.files.find(f => f.resolution.id === resolution) - const path = servers[1].servers.buildWebVideoFilePath(file.fileUrl) - - const bitrate = await getVideoStreamBitrate(path) - const fps = await getVideoStreamFPS(path) - const dataResolution = await getVideoStreamDimensionsInfo(path) - - expect(resolution).to.equal(resolution) - - const maxBitrate = getMaxTheoreticalBitrate({ ...dataResolution, fps }) - expect(bitrate).to.be.below(maxBitrate) - } - } - }) - - 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, - '720p': true, - '1080p': true, - '1440p': true, - '2160p': true - }, - webVideos: { enabled: true }, - hls: { enabled: true } - } - } - await servers[1].config.updateCustomSubConfig({ newConfig }) - - const attributes = { - name: 'low bitrate', - fixture: 'low-bitrate.mp4' - } - - const { id } = await servers[1].videos.upload({ attributes }) - - await waitJobs(servers) - - const video = await servers[1].videos.get({ id }) - - const resolutions = [ 240, 360, 480, 720, 1080 ] - for (const r of resolutions) { - const file = video.files.find(f => f.resolution.id === r) - - const path = servers[1].servers.buildWebVideoFilePath(file.fileUrl) - const bitrate = await getVideoStreamBitrate(path) - - const inputBitrate = 60_000 - const limit = getMinTheoreticalBitrate({ 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) - } - }) - }) - - describe('FFprobe', function () { - - it('Should provide valid ffprobe data', async function () { - this.timeout(160_000) - - const videoUUID = (await servers[1].videos.quickUpload({ name: 'ffprobe data' })).uuid - await waitJobs(servers) - - { - const video = await servers[1].videos.get({ id: videoUUID }) - const file = video.files.find(f => f.resolution.id === 240) - const path = servers[1].servers.buildWebVideoFilePath(file.fileUrl) - - const probe = await ffprobePromise(path) - const metadata = new VideoFileMetadata(probe) - - // expected format properties - for (const p of [ - 'tags.encoder', - 'format_long_name', - 'size', - 'bit_rate' - ]) { - expect(metadata.format).to.have.nested.property(p) - } - - // expected stream properties - for (const p of [ - 'codec_long_name', - 'profile', - 'width', - 'height', - 'display_aspect_ratio', - 'avg_frame_rate', - 'pix_fmt' - ]) { - expect(metadata.streams[0]).to.have.nested.property(p) - } - - expect(metadata).to.not.have.nested.property('format.filename') - } - - for (const server of servers) { - const videoDetails = await server.videos.get({ id: videoUUID }) - - const videoFiles = getAllFiles(videoDetails) - expect(videoFiles).to.have.lengthOf(10) - - for (const file of videoFiles) { - expect(file.metadata).to.be.undefined - expect(file.metadataUrl).to.exist - expect(file.metadataUrl).to.contain(servers[1].url) - expect(file.metadataUrl).to.contain(videoUUID) - - const metadata = await server.videos.getFileMetadata({ url: file.metadataUrl }) - expect(metadata).to.have.nested.property('format.size') - } - } - }) - - it('Should correctly detect if quick transcode is possible', async function () { - this.timeout(10_000) - - expect(await canDoQuickTranscode(buildAbsoluteFixturePath('video_short.mp4'))).to.be.true - expect(await canDoQuickTranscode(buildAbsoluteFixturePath('video_short.webm'))).to.be.false - }) - }) - - describe('Transcoding job queue', function () { - - it('Should have the appropriate priorities for transcoding jobs', async function () { - const body = await servers[1].jobs.list({ - start: 0, - count: 100, - sort: 'createdAt', - jobType: 'video-transcoding' - }) - - const jobs = body.data - const transcodingJobs = jobs.filter(j => j.data.videoUUID === video4k) - - expect(transcodingJobs).to.have.lengthOf(16) - - const hlsJobs = transcodingJobs.filter(j => j.data.type === 'new-resolution-to-hls') - const webVideoJobs = transcodingJobs.filter(j => j.data.type === 'new-resolution-to-web-video') - const optimizeJobs = transcodingJobs.filter(j => j.data.type === 'optimize-to-web-video') - - expect(hlsJobs).to.have.lengthOf(8) - expect(webVideoJobs).to.have.lengthOf(7) - expect(optimizeJobs).to.have.lengthOf(1) - - for (const j of optimizeJobs.concat(hlsJobs.concat(webVideoJobs))) { - expect(j.priority).to.be.greaterThan(100) - expect(j.priority).to.be.lessThan(150) - } - }) - }) - - describe('Bounded transcoding', function () { - - it('Should not generate an upper resolution than original file', async function () { - this.timeout(120_000) - - await servers[0].config.updateExistingSubConfig({ - newConfig: { - transcoding: { - enabled: true, - hls: { enabled: true }, - webVideos: { enabled: true }, - resolutions: { - '0p': false, - '144p': false, - '240p': true, - '360p': false, - '480p': true, - '720p': false, - '1080p': false, - '1440p': false, - '2160p': false - }, - alwaysTranscodeOriginalResolution: false - } - } - }) - - const { uuid } = await servers[0].videos.quickUpload({ name: 'video', fixture: 'video_short.webm' }) - await waitJobs(servers) - - const video = await servers[0].videos.get({ id: uuid }) - const hlsFiles = video.streamingPlaylists[0].files - - expect(video.files).to.have.lengthOf(2) - expect(hlsFiles).to.have.lengthOf(2) - - // eslint-disable-next-line @typescript-eslint/require-array-sort-compare - const resolutions = getAllFiles(video).map(f => f.resolution.id).sort() - expect(resolutions).to.deep.equal([ 240, 240, 480, 480 ]) - }) - - it('Should only keep the original resolution if all resolutions are disabled', async function () { - this.timeout(120_000) - - await servers[0].config.updateExistingSubConfig({ - newConfig: { - transcoding: { - resolutions: { - '0p': false, - '144p': false, - '240p': false, - '360p': false, - '480p': false, - '720p': false, - '1080p': false, - '1440p': false, - '2160p': false - } - } - } - }) - - const { uuid } = await servers[0].videos.quickUpload({ name: 'video', fixture: 'video_short.webm' }) - await waitJobs(servers) - - const video = await servers[0].videos.get({ id: uuid }) - const hlsFiles = video.streamingPlaylists[0].files - - expect(video.files).to.have.lengthOf(1) - expect(hlsFiles).to.have.lengthOf(1) - - expect(video.files[0].resolution.id).to.equal(720) - expect(hlsFiles[0].resolution.id).to.equal(720) - }) - }) - - after(async function () { - await cleanupTests(servers) - }) -}) diff --git a/server/tests/api/transcoding/update-while-transcoding.ts b/server/tests/api/transcoding/update-while-transcoding.ts deleted file mode 100644 index cfb4fa0cc..000000000 --- a/server/tests/api/transcoding/update-while-transcoding.ts +++ /dev/null @@ -1,160 +0,0 @@ -/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ - -import { completeCheckHlsPlaylist } from '@server/tests/shared' -import { areMockObjectStorageTestsDisabled, wait } from '@shared/core-utils' -import { VideoPrivacy } from '@shared/models' -import { - cleanupTests, - createMultipleServers, - doubleFollow, - ObjectStorageCommand, - PeerTubeServer, - setAccessTokensToServers, - waitJobs -} from '@shared/server-commands' - -describe('Test update video privacy while transcoding', function () { - let servers: PeerTubeServer[] = [] - - const videoUUIDs: string[] = [] - - function runTestSuite (hlsOnly: boolean, objectStorageBaseUrl?: string) { - - it('Should not have an error while quickly updating a private video to public after upload #1', async function () { - this.timeout(360_000) - - const attributes = { - name: 'quick update', - privacy: VideoPrivacy.PRIVATE - } - - const { uuid } = await servers[0].videos.upload({ attributes, waitTorrentGeneration: false }) - await servers[0].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } }) - videoUUIDs.push(uuid) - - await waitJobs(servers) - - await completeCheckHlsPlaylist({ servers, videoUUID: uuid, hlsOnly, objectStorageBaseUrl }) - }) - - it('Should not have an error while quickly updating a private video to public after upload #2', async function () { - this.timeout(60000) - - { - const attributes = { - name: 'quick update 2', - privacy: VideoPrivacy.PRIVATE - } - - const { uuid } = await servers[0].videos.upload({ attributes, waitTorrentGeneration: true }) - await servers[0].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } }) - videoUUIDs.push(uuid) - - await waitJobs(servers) - - await completeCheckHlsPlaylist({ servers, videoUUID: uuid, hlsOnly, objectStorageBaseUrl }) - } - }) - - it('Should not have an error while quickly updating a private video to public after upload #3', async function () { - this.timeout(60000) - - const attributes = { - name: 'quick update 3', - privacy: VideoPrivacy.PRIVATE - } - - const { uuid } = await servers[0].videos.upload({ attributes, waitTorrentGeneration: true }) - await wait(1000) - await servers[0].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } }) - videoUUIDs.push(uuid) - - await waitJobs(servers) - - await completeCheckHlsPlaylist({ servers, videoUUID: uuid, hlsOnly, objectStorageBaseUrl }) - }) - } - - before(async function () { - this.timeout(120000) - - const configOverride = { - transcoding: { - enabled: true, - allow_audio_files: true, - hls: { - enabled: true - } - } - } - servers = await createMultipleServers(2, configOverride) - - // Get the access tokens - await setAccessTokensToServers(servers) - - // Server 1 and server 2 follow each other - await doubleFollow(servers[0], servers[1]) - }) - - describe('With Web Video & HLS enabled', function () { - runTestSuite(false) - }) - - describe('With only HLS enabled', function () { - - before(async function () { - await servers[0].config.updateCustomSubConfig({ - newConfig: { - transcoding: { - enabled: true, - allowAudioFiles: true, - resolutions: { - '144p': false, - '240p': true, - '360p': true, - '480p': true, - '720p': true, - '1080p': true, - '1440p': true, - '2160p': true - }, - hls: { - enabled: true - }, - webVideos: { - enabled: false - } - } - } - }) - }) - - runTestSuite(true) - }) - - describe('With object storage enabled', function () { - if (areMockObjectStorageTestsDisabled()) return - - const objectStorage = new ObjectStorageCommand() - - before(async function () { - this.timeout(120000) - - const configOverride = objectStorage.getDefaultMockConfig() - await objectStorage.prepareDefaultMockBuckets() - - await servers[0].kill() - await servers[0].run(configOverride) - }) - - runTestSuite(true, objectStorage.getMockPlaylistBaseUrl()) - - after(async function () { - await objectStorage.cleanupMock() - }) - }) - - after(async function () { - await cleanupTests(servers) - }) -}) diff --git a/server/tests/api/transcoding/video-studio.ts b/server/tests/api/transcoding/video-studio.ts deleted file mode 100644 index ba68f8e24..000000000 --- a/server/tests/api/transcoding/video-studio.ts +++ /dev/null @@ -1,377 +0,0 @@ -import { expect } from 'chai' -import { checkPersistentTmpIsEmpty, checkVideoDuration, expectStartWith } from '@server/tests/shared' -import { areMockObjectStorageTestsDisabled, getAllFiles } from '@shared/core-utils' -import { VideoStudioTask } from '@shared/models' -import { - cleanupTests, - createMultipleServers, - doubleFollow, - ObjectStorageCommand, - PeerTubeServer, - setAccessTokensToServers, - setDefaultVideoChannel, - VideoStudioCommand, - waitJobs -} from '@shared/server-commands' - -describe('Test video studio', function () { - let servers: PeerTubeServer[] = [] - let videoUUID: string - - async function renewVideo (fixture = 'video_short.webm') { - const video = await servers[0].videos.quickUpload({ name: 'video', fixture }) - videoUUID = video.uuid - - await waitJobs(servers) - } - - async function createTasks (tasks: VideoStudioTask[]) { - await servers[0].videoStudio.createEditionTasks({ videoId: videoUUID, tasks }) - await waitJobs(servers) - } - - before(async function () { - this.timeout(120_000) - - servers = await createMultipleServers(2) - - await setAccessTokensToServers(servers) - await setDefaultVideoChannel(servers) - - await doubleFollow(servers[0], servers[1]) - - await servers[0].config.enableMinimumTranscoding() - - await servers[0].config.enableStudio() - }) - - describe('Cutting', function () { - - it('Should cut the beginning of the video', async function () { - this.timeout(120_000) - - await renewVideo() - await waitJobs(servers) - - const beforeTasks = new Date() - - await createTasks([ - { - name: 'cut', - options: { - start: 2 - } - } - ]) - - for (const server of servers) { - await checkVideoDuration(server, videoUUID, 3) - - const video = await server.videos.get({ id: videoUUID }) - expect(new Date(video.publishedAt)).to.be.below(beforeTasks) - } - }) - - it('Should cut the end of the video', async function () { - this.timeout(120_000) - await renewVideo() - - await createTasks([ - { - name: 'cut', - options: { - end: 2 - } - } - ]) - - for (const server of servers) { - await checkVideoDuration(server, videoUUID, 2) - } - }) - - it('Should cut start/end of the video', async function () { - this.timeout(120_000) - await renewVideo('video_short1.webm') // 10 seconds video duration - - await createTasks([ - { - name: 'cut', - options: { - start: 2, - end: 6 - } - } - ]) - - for (const server of servers) { - await checkVideoDuration(server, videoUUID, 4) - } - }) - }) - - describe('Intro/Outro', function () { - - it('Should add an intro', async function () { - this.timeout(120_000) - await renewVideo() - - await createTasks([ - { - name: 'add-intro', - options: { - file: 'video_short.webm' - } - } - ]) - - for (const server of servers) { - await checkVideoDuration(server, videoUUID, 10) - } - }) - - it('Should add an outro', async function () { - this.timeout(120_000) - await renewVideo() - - await createTasks([ - { - name: 'add-outro', - options: { - file: 'video_very_short_240p.mp4' - } - } - ]) - - for (const server of servers) { - await checkVideoDuration(server, videoUUID, 7) - } - }) - - it('Should add an intro/outro', async function () { - this.timeout(120_000) - await renewVideo() - - await createTasks([ - { - name: 'add-intro', - options: { - file: 'video_very_short_240p.mp4' - } - }, - { - name: 'add-outro', - options: { - // Different frame rate - file: 'video_short2.webm' - } - } - ]) - - for (const server of servers) { - await checkVideoDuration(server, videoUUID, 12) - } - }) - - it('Should add an intro to a video without audio', async function () { - this.timeout(120_000) - await renewVideo('video_short_no_audio.mp4') - - await createTasks([ - { - name: 'add-intro', - options: { - file: 'video_very_short_240p.mp4' - } - } - ]) - - for (const server of servers) { - await checkVideoDuration(server, videoUUID, 7) - } - }) - - it('Should add an outro without audio to a video with audio', async function () { - this.timeout(120_000) - await renewVideo() - - await createTasks([ - { - name: 'add-outro', - options: { - file: 'video_short_no_audio.mp4' - } - } - ]) - - for (const server of servers) { - await checkVideoDuration(server, videoUUID, 10) - } - }) - - it('Should add an outro without audio to a video with audio', async function () { - this.timeout(120_000) - await renewVideo('video_short_no_audio.mp4') - - await createTasks([ - { - name: 'add-outro', - options: { - file: 'video_short_no_audio.mp4' - } - } - ]) - - for (const server of servers) { - await checkVideoDuration(server, videoUUID, 10) - } - }) - }) - - describe('Watermark', function () { - - it('Should add a watermark to the video', async function () { - this.timeout(120_000) - await renewVideo() - - const video = await servers[0].videos.get({ id: videoUUID }) - const oldFileUrls = getAllFiles(video).map(f => f.fileUrl) - - await createTasks([ - { - name: 'add-watermark', - options: { - file: 'custom-thumbnail.png' - } - } - ]) - - for (const server of servers) { - const video = await server.videos.get({ id: videoUUID }) - const fileUrls = getAllFiles(video).map(f => f.fileUrl) - - for (const oldUrl of oldFileUrls) { - expect(fileUrls).to.not.include(oldUrl) - } - } - }) - }) - - describe('Complex tasks', function () { - it('Should run a complex task', async function () { - this.timeout(240_000) - await renewVideo() - - await createTasks(VideoStudioCommand.getComplexTask()) - - for (const server of servers) { - await checkVideoDuration(server, videoUUID, 9) - } - }) - }) - - describe('HLS only studio edition', function () { - - before(async function () { - // Disable Web Videos - await servers[0].config.updateExistingSubConfig({ - newConfig: { - transcoding: { - webVideos: { - enabled: false - } - } - } - }) - }) - - it('Should run a complex task on HLS only video', async function () { - this.timeout(240_000) - await renewVideo() - - await createTasks(VideoStudioCommand.getComplexTask()) - - for (const server of servers) { - const video = await server.videos.get({ id: videoUUID }) - expect(video.files).to.have.lengthOf(0) - - await checkVideoDuration(server, videoUUID, 9) - } - }) - }) - - describe('Server restart', function () { - - it('Should still be able to run video edition after a server restart', async function () { - this.timeout(240_000) - - await renewVideo() - await servers[0].videoStudio.createEditionTasks({ videoId: videoUUID, tasks: VideoStudioCommand.getComplexTask() }) - - await servers[0].kill() - await servers[0].run() - - await waitJobs(servers) - - for (const server of servers) { - await checkVideoDuration(server, videoUUID, 9) - } - }) - - it('Should have an empty persistent tmp directory', async function () { - await checkPersistentTmpIsEmpty(servers[0]) - }) - }) - - describe('Object storage studio edition', function () { - if (areMockObjectStorageTestsDisabled()) return - - const objectStorage = new ObjectStorageCommand() - - before(async function () { - await objectStorage.prepareDefaultMockBuckets() - - await servers[0].kill() - await servers[0].run(objectStorage.getDefaultMockConfig()) - - await servers[0].config.enableMinimumTranscoding() - }) - - it('Should run a complex task on a video in object storage', async function () { - this.timeout(240_000) - await renewVideo() - - const video = await servers[0].videos.get({ id: videoUUID }) - const oldFileUrls = getAllFiles(video).map(f => f.fileUrl) - - await createTasks(VideoStudioCommand.getComplexTask()) - - for (const server of servers) { - const video = await server.videos.get({ id: videoUUID }) - const files = getAllFiles(video) - - for (const f of files) { - expect(oldFileUrls).to.not.include(f.fileUrl) - } - - for (const webVideoFile of video.files) { - expectStartWith(webVideoFile.fileUrl, objectStorage.getMockWebVideosBaseUrl()) - } - - for (const hlsFile of video.streamingPlaylists[0].files) { - expectStartWith(hlsFile.fileUrl, objectStorage.getMockPlaylistBaseUrl()) - } - - await checkVideoDuration(server, videoUUID, 9) - } - }) - - after(async function () { - await objectStorage.cleanupMock() - }) - }) - - after(async function () { - await cleanupTests(servers) - }) -}) -- cgit v1.2.3