From c729caf6cc34630877a0e5a1bda1719384cd0c8a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 11 Feb 2022 10:51:33 +0100 Subject: Add basic video editor support --- server/tests/api/videos/audio-only.ts | 7 +- server/tests/api/videos/index.ts | 1 + server/tests/api/videos/video-editor.ts | 368 +++++++++++++++++++++ .../tests/api/videos/video-playlist-thumbnails.ts | 6 +- server/tests/api/videos/video-playlists.ts | 6 +- server/tests/api/videos/video-transcoder.ts | 39 ++- 6 files changed, 404 insertions(+), 23 deletions(-) create mode 100644 server/tests/api/videos/video-editor.ts (limited to 'server/tests/api/videos') diff --git a/server/tests/api/videos/audio-only.ts b/server/tests/api/videos/audio-only.ts index e58360ffe..e7e73d382 100644 --- a/server/tests/api/videos/audio-only.ts +++ b/server/tests/api/videos/audio-only.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { getAudioStream, getVideoStreamSize } from '@server/helpers/ffprobe-utils' +import { getAudioStream, getVideoStreamDimensionsInfo } from '@server/helpers/ffmpeg' import { cleanupTests, createMultipleServers, @@ -91,9 +91,8 @@ describe('Test audio only video transcoding', function () { expect(audioStream['codec_name']).to.be.equal('aac') expect(audioStream['bit_rate']).to.be.at.most(384 * 8000) - const size = await getVideoStreamSize(path) - expect(size.height).to.equal(0) - expect(size.width).to.equal(0) + const size = await getVideoStreamDimensionsInfo(path) + expect(size).to.not.exist } }) diff --git a/server/tests/api/videos/index.ts b/server/tests/api/videos/index.ts index bedb9b8b6..72e6ae2b4 100644 --- a/server/tests/api/videos/index.ts +++ b/server/tests/api/videos/index.ts @@ -8,6 +8,7 @@ import './video-channels' import './video-comments' import './video-create-transcoding' import './video-description' +import './video-editor' import './video-files' import './video-hls' import './video-imports' diff --git a/server/tests/api/videos/video-editor.ts b/server/tests/api/videos/video-editor.ts new file mode 100644 index 000000000..a9b6950cc --- /dev/null +++ b/server/tests/api/videos/video-editor.ts @@ -0,0 +1,368 @@ +import { expect } from 'chai' +import { expectStartWith, getAllFiles } from '@server/tests/shared' +import { areObjectStorageTestsDisabled } from '@shared/core-utils' +import { VideoEditorTask } from '@shared/models' +import { + cleanupTests, + createMultipleServers, + doubleFollow, + ObjectStorageCommand, + PeerTubeServer, + setAccessTokensToServers, + setDefaultVideoChannel, + VideoEditorCommand, + waitJobs +} from '@shared/server-commands' + +describe('Test video editor', function () { + let servers: PeerTubeServer[] = [] + let videoUUID: string + + async function checkDuration (server: PeerTubeServer, duration: number) { + const video = await server.videos.get({ id: videoUUID }) + + expect(video.duration).to.be.approximately(duration, 1) + + for (const file of video.files) { + const metadata = await server.videos.getFileMetadata({ url: file.metadataUrl }) + + for (const stream of metadata.streams) { + expect(Math.round(stream.duration)).to.be.approximately(duration, 1) + } + } + } + + 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: VideoEditorTask[]) { + await servers[0].videoEditor.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.updateExistingSubConfig({ + newConfig: { + videoEditor: { + enabled: true + } + } + }) + }) + + 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 checkDuration(server, 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 checkDuration(server, 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 checkDuration(server, 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 checkDuration(server, 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 checkDuration(server, 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 checkDuration(server, 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 checkDuration(server, 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 checkDuration(server, 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 checkDuration(server, 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: '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(VideoEditorCommand.getComplexTask()) + + for (const server of servers) { + await checkDuration(server, 9) + } + }) + }) + + describe('HLS only video edition', function () { + + before(async function () { + // Disable webtorrent + await servers[0].config.updateExistingSubConfig({ + newConfig: { + transcoding: { + webtorrent: { + enabled: false + } + } + } + }) + }) + + it('Should run a complex task on HLS only video', async function () { + this.timeout(240_000) + await renewVideo() + + await createTasks(VideoEditorCommand.getComplexTask()) + + for (const server of servers) { + const video = await server.videos.get({ id: videoUUID }) + expect(video.files).to.have.lengthOf(0) + + await checkDuration(server, 9) + } + }) + }) + + describe('Object storage video edition', function () { + if (areObjectStorageTestsDisabled()) return + + before(async function () { + await ObjectStorageCommand.prepareDefaultBuckets() + + await servers[0].kill() + await servers[0].run(ObjectStorageCommand.getDefaultConfig()) + + 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(VideoEditorCommand.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 webtorrentFile of video.files) { + expectStartWith(webtorrentFile.fileUrl, ObjectStorageCommand.getWebTorrentBaseUrl()) + } + + for (const hlsFile of video.streamingPlaylists[0].files) { + expectStartWith(hlsFile.fileUrl, ObjectStorageCommand.getPlaylistBaseUrl()) + } + + await checkDuration(server, 9) + } + }) + }) + + after(async function () { + await cleanupTests(servers) + }) +}) diff --git a/server/tests/api/videos/video-playlist-thumbnails.ts b/server/tests/api/videos/video-playlist-thumbnails.ts index 5fdb0fc03..3944dc344 100644 --- a/server/tests/api/videos/video-playlist-thumbnails.ts +++ b/server/tests/api/videos/video-playlist-thumbnails.ts @@ -45,12 +45,16 @@ describe('Playlist thumbnail', function () { before(async function () { this.timeout(120000) - servers = await createMultipleServers(2, { transcoding: { enabled: false } }) + servers = await createMultipleServers(2) // Get the access tokens await setAccessTokensToServers(servers) await setDefaultVideoChannel(servers) + for (const server of servers) { + await server.config.disableTranscoding() + } + // Server 1 and server 2 follow each other await doubleFollow(servers[0], servers[1]) diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts index 1e8dbef02..c33a63df0 100644 --- a/server/tests/api/videos/video-playlists.ts +++ b/server/tests/api/videos/video-playlists.ts @@ -75,13 +75,17 @@ describe('Test video playlists', function () { before(async function () { this.timeout(120000) - servers = await createMultipleServers(3, { transcoding: { enabled: false } }) + servers = await createMultipleServers(3) // Get the access tokens await setAccessTokensToServers(servers) await setDefaultVideoChannel(servers) await setDefaultAccountAvatar(servers) + for (const server of servers) { + await server.config.disableTranscoding() + } + // Server 1 and server 2 follow each other await doubleFollow(servers[0], servers[1]) // Server 1 and server 3 follow each other diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts index d24a8f4e1..245c4c012 100644 --- a/server/tests/api/videos/video-transcoder.ts +++ b/server/tests/api/videos/video-transcoder.ts @@ -3,10 +3,17 @@ import 'mocha' import * as chai from 'chai' import { omit } from 'lodash' -import { canDoQuickTranscode } from '@server/helpers/ffprobe-utils' -import { generateHighBitrateVideo, generateVideoWithFramerate } from '@server/tests/shared' +import { canDoQuickTranscode } from '@server/helpers/ffmpeg' +import { generateHighBitrateVideo, generateVideoWithFramerate, getAllFiles } from '@server/tests/shared' import { buildAbsoluteFixturePath, getMaxBitrate, getMinLimitBitrate } from '@shared/core-utils' -import { getAudioStream, getMetadataFromFile, getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '@shared/extra-utils' +import { + getAudioStream, + buildFileMetadata, + getVideoStreamBitrate, + getVideoStreamFPS, + getVideoStreamDimensionsInfo, + hasAudioStream +} from '@shared/extra-utils' import { HttpStatusCode, VideoState } from '@shared/models' import { cleanupTests, @@ -287,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 } }) @@ -478,14 +484,14 @@ describe('Test video transcoding', function () { 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) } @@ -499,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) } @@ -522,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) } } @@ -563,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) @@ -613,7 +619,7 @@ 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) + const bitrate = await getVideoStreamBitrate(path) const inputBitrate = 60_000 const limit = getMinLimitBitrate({ fps: 10, ratio: 1, resolution: r }) @@ -637,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 [ @@ -668,8 +674,7 @@ 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) + const videoFiles = getAllFiles(videoDetails) expect(videoFiles).to.have.lengthOf(10) for (const file of videoFiles) { -- cgit v1.2.3