aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/transcoding
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/transcoding')
-rw-r--r--server/tests/api/transcoding/audio-only.ts102
-rw-r--r--server/tests/api/transcoding/create-transcoding.ts252
-rw-r--r--server/tests/api/transcoding/hls.ts289
-rw-r--r--server/tests/api/transcoding/index.ts5
-rw-r--r--server/tests/api/transcoding/transcoder.ts733
-rw-r--r--server/tests/api/transcoding/video-editor.ts368
6 files changed, 1749 insertions, 0 deletions
diff --git a/server/tests/api/transcoding/audio-only.ts b/server/tests/api/transcoding/audio-only.ts
new file mode 100644
index 000000000..e7e73d382
--- /dev/null
+++ b/server/tests/api/transcoding/audio-only.ts
@@ -0,0 +1,102 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import * as chai from 'chai'
5import { getAudioStream, getVideoStreamDimensionsInfo } from '@server/helpers/ffmpeg'
6import {
7 cleanupTests,
8 createMultipleServers,
9 doubleFollow,
10 PeerTubeServer,
11 setAccessTokensToServers,
12 waitJobs
13} from '@shared/server-commands'
14
15const expect = chai.expect
16
17describe('Test audio only video transcoding', function () {
18 let servers: PeerTubeServer[] = []
19 let videoUUID: string
20 let webtorrentAudioFileUrl: string
21 let fragmentedAudioFileUrl: string
22
23 before(async function () {
24 this.timeout(120000)
25
26 const configOverride = {
27 transcoding: {
28 enabled: true,
29 resolutions: {
30 '0p': true,
31 '144p': false,
32 '240p': true,
33 '360p': false,
34 '480p': false,
35 '720p': false,
36 '1080p': false,
37 '1440p': false,
38 '2160p': false
39 },
40 hls: {
41 enabled: true
42 },
43 webtorrent: {
44 enabled: true
45 }
46 }
47 }
48 servers = await createMultipleServers(2, configOverride)
49
50 // Get the access tokens
51 await setAccessTokensToServers(servers)
52
53 // Server 1 and server 2 follow each other
54 await doubleFollow(servers[0], servers[1])
55 })
56
57 it('Should upload a video and transcode it', async function () {
58 this.timeout(120000)
59
60 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'audio only' } })
61 videoUUID = uuid
62
63 await waitJobs(servers)
64
65 for (const server of servers) {
66 const video = await server.videos.get({ id: videoUUID })
67 expect(video.streamingPlaylists).to.have.lengthOf(1)
68
69 for (const files of [ video.files, video.streamingPlaylists[0].files ]) {
70 expect(files).to.have.lengthOf(3)
71 expect(files[0].resolution.id).to.equal(720)
72 expect(files[1].resolution.id).to.equal(240)
73 expect(files[2].resolution.id).to.equal(0)
74 }
75
76 if (server.serverNumber === 1) {
77 webtorrentAudioFileUrl = video.files[2].fileUrl
78 fragmentedAudioFileUrl = video.streamingPlaylists[0].files[2].fileUrl
79 }
80 }
81 })
82
83 it('0p transcoded video should not have video', async function () {
84 const paths = [
85 servers[0].servers.buildWebTorrentFilePath(webtorrentAudioFileUrl),
86 servers[0].servers.buildFragmentedFilePath(videoUUID, fragmentedAudioFileUrl)
87 ]
88
89 for (const path of paths) {
90 const { audioStream } = await getAudioStream(path)
91 expect(audioStream['codec_name']).to.be.equal('aac')
92 expect(audioStream['bit_rate']).to.be.at.most(384 * 8000)
93
94 const size = await getVideoStreamDimensionsInfo(path)
95 expect(size).to.not.exist
96 }
97 })
98
99 after(async function () {
100 await cleanupTests(servers)
101 })
102})
diff --git a/server/tests/api/transcoding/create-transcoding.ts b/server/tests/api/transcoding/create-transcoding.ts
new file mode 100644
index 000000000..a4defdf51
--- /dev/null
+++ b/server/tests/api/transcoding/create-transcoding.ts
@@ -0,0 +1,252 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import * as chai from 'chai'
5import { checkResolutionsInMasterPlaylist, expectStartWith } from '@server/tests/shared'
6import { areObjectStorageTestsDisabled } from '@shared/core-utils'
7import { HttpStatusCode, VideoDetails } from '@shared/models'
8import {
9 cleanupTests,
10 ConfigCommand,
11 createMultipleServers,
12 doubleFollow,
13 expectNoFailedTranscodingJob,
14 makeRawRequest,
15 ObjectStorageCommand,
16 PeerTubeServer,
17 setAccessTokensToServers,
18 waitJobs
19} from '@shared/server-commands'
20
21const expect = chai.expect
22
23async function checkFilesInObjectStorage (video: VideoDetails) {
24 for (const file of video.files) {
25 expectStartWith(file.fileUrl, ObjectStorageCommand.getWebTorrentBaseUrl())
26 await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200)
27 }
28
29 if (video.streamingPlaylists.length === 0) return
30
31 const hlsPlaylist = video.streamingPlaylists[0]
32 for (const file of hlsPlaylist.files) {
33 expectStartWith(file.fileUrl, ObjectStorageCommand.getPlaylistBaseUrl())
34 await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200)
35 }
36
37 expectStartWith(hlsPlaylist.playlistUrl, ObjectStorageCommand.getPlaylistBaseUrl())
38 await makeRawRequest(hlsPlaylist.playlistUrl, HttpStatusCode.OK_200)
39
40 expectStartWith(hlsPlaylist.segmentsSha256Url, ObjectStorageCommand.getPlaylistBaseUrl())
41 await makeRawRequest(hlsPlaylist.segmentsSha256Url, HttpStatusCode.OK_200)
42}
43
44function runTests (objectStorage: boolean) {
45 let servers: PeerTubeServer[] = []
46 let videoUUID: string
47 let publishedAt: string
48
49 before(async function () {
50 this.timeout(120000)
51
52 const config = objectStorage
53 ? ObjectStorageCommand.getDefaultConfig()
54 : {}
55
56 // Run server 2 to have transcoding enabled
57 servers = await createMultipleServers(2, config)
58 await setAccessTokensToServers(servers)
59
60 await servers[0].config.disableTranscoding()
61
62 await doubleFollow(servers[0], servers[1])
63
64 if (objectStorage) await ObjectStorageCommand.prepareDefaultBuckets()
65
66 const { shortUUID } = await servers[0].videos.quickUpload({ name: 'video' })
67 videoUUID = shortUUID
68
69 await waitJobs(servers)
70
71 const video = await servers[0].videos.get({ id: videoUUID })
72 publishedAt = video.publishedAt as string
73
74 await servers[0].config.enableTranscoding()
75 })
76
77 it('Should generate HLS', async function () {
78 this.timeout(60000)
79
80 await servers[0].videos.runTranscoding({
81 videoId: videoUUID,
82 transcodingType: 'hls'
83 })
84
85 await waitJobs(servers)
86 await expectNoFailedTranscodingJob(servers[0])
87
88 for (const server of servers) {
89 const videoDetails = await server.videos.get({ id: videoUUID })
90
91 expect(videoDetails.files).to.have.lengthOf(1)
92 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
93 expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(5)
94
95 if (objectStorage) await checkFilesInObjectStorage(videoDetails)
96 }
97 })
98
99 it('Should generate WebTorrent', async function () {
100 this.timeout(60000)
101
102 await servers[0].videos.runTranscoding({
103 videoId: videoUUID,
104 transcodingType: 'webtorrent'
105 })
106
107 await waitJobs(servers)
108
109 for (const server of servers) {
110 const videoDetails = await server.videos.get({ id: videoUUID })
111
112 expect(videoDetails.files).to.have.lengthOf(5)
113 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
114 expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(5)
115
116 if (objectStorage) await checkFilesInObjectStorage(videoDetails)
117 }
118 })
119
120 it('Should generate WebTorrent from HLS only video', async function () {
121 this.timeout(60000)
122
123 await servers[0].videos.removeWebTorrentFiles({ videoId: videoUUID })
124 await waitJobs(servers)
125
126 await servers[0].videos.runTranscoding({ videoId: videoUUID, transcodingType: 'webtorrent' })
127 await waitJobs(servers)
128
129 for (const server of servers) {
130 const videoDetails = await server.videos.get({ id: videoUUID })
131
132 expect(videoDetails.files).to.have.lengthOf(5)
133 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
134 expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(5)
135
136 if (objectStorage) await checkFilesInObjectStorage(videoDetails)
137 }
138 })
139
140 it('Should only generate WebTorrent', async function () {
141 this.timeout(60000)
142
143 await servers[0].videos.removeHLSFiles({ videoId: videoUUID })
144 await waitJobs(servers)
145
146 await servers[0].videos.runTranscoding({ videoId: videoUUID, transcodingType: 'webtorrent' })
147 await waitJobs(servers)
148
149 for (const server of servers) {
150 const videoDetails = await server.videos.get({ id: videoUUID })
151
152 expect(videoDetails.files).to.have.lengthOf(5)
153 expect(videoDetails.streamingPlaylists).to.have.lengthOf(0)
154
155 if (objectStorage) await checkFilesInObjectStorage(videoDetails)
156 }
157 })
158
159 it('Should correctly update HLS playlist on resolution change', async function () {
160 this.timeout(120000)
161
162 await servers[0].config.updateExistingSubConfig({
163 newConfig: {
164 transcoding: {
165 enabled: true,
166 resolutions: ConfigCommand.getCustomConfigResolutions(false),
167
168 webtorrent: {
169 enabled: true
170 },
171 hls: {
172 enabled: true
173 }
174 }
175 }
176 })
177
178 const { uuid } = await servers[0].videos.quickUpload({ name: 'quick' })
179
180 await waitJobs(servers)
181
182 for (const server of servers) {
183 const videoDetails = await server.videos.get({ id: uuid })
184
185 expect(videoDetails.files).to.have.lengthOf(1)
186 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
187 expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(1)
188
189 if (objectStorage) await checkFilesInObjectStorage(videoDetails)
190 }
191
192 await servers[0].config.updateExistingSubConfig({
193 newConfig: {
194 transcoding: {
195 enabled: true,
196 resolutions: ConfigCommand.getCustomConfigResolutions(true),
197
198 webtorrent: {
199 enabled: true
200 },
201 hls: {
202 enabled: true
203 }
204 }
205 }
206 })
207
208 await servers[0].videos.runTranscoding({ videoId: uuid, transcodingType: 'hls' })
209 await waitJobs(servers)
210
211 for (const server of servers) {
212 const videoDetails = await server.videos.get({ id: uuid })
213
214 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
215 expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(5)
216
217 if (objectStorage) {
218 await checkFilesInObjectStorage(videoDetails)
219
220 const hlsPlaylist = videoDetails.streamingPlaylists[0]
221 const resolutions = hlsPlaylist.files.map(f => f.resolution.id)
222 await checkResolutionsInMasterPlaylist({ server: servers[0], playlistUrl: hlsPlaylist.playlistUrl, resolutions })
223
224 const shaBody = await servers[0].streamingPlaylists.getSegmentSha256({ url: hlsPlaylist.segmentsSha256Url })
225 expect(Object.keys(shaBody)).to.have.lengthOf(5)
226 }
227 }
228 })
229
230 it('Should not have updated published at attributes', async function () {
231 const video = await servers[0].videos.get({ id: videoUUID })
232
233 expect(video.publishedAt).to.equal(publishedAt)
234 })
235
236 after(async function () {
237 await cleanupTests(servers)
238 })
239}
240
241describe('Test create transcoding jobs from API', function () {
242
243 describe('On filesystem', function () {
244 runTests(false)
245 })
246
247 describe('On object storage', function () {
248 if (areObjectStorageTestsDisabled()) return
249
250 runTests(true)
251 })
252})
diff --git a/server/tests/api/transcoding/hls.ts b/server/tests/api/transcoding/hls.ts
new file mode 100644
index 000000000..218ec08ae
--- /dev/null
+++ b/server/tests/api/transcoding/hls.ts
@@ -0,0 +1,289 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import * as chai from 'chai'
5import { basename, join } from 'path'
6import {
7 checkDirectoryIsEmpty,
8 checkResolutionsInMasterPlaylist,
9 checkSegmentHash,
10 checkTmpIsEmpty,
11 expectStartWith,
12 hlsInfohashExist
13} from '@server/tests/shared'
14import { areObjectStorageTestsDisabled, removeFragmentedMP4Ext, uuidRegex } from '@shared/core-utils'
15import { HttpStatusCode, VideoStreamingPlaylistType } from '@shared/models'
16import {
17 cleanupTests,
18 createMultipleServers,
19 doubleFollow,
20 makeRawRequest,
21 ObjectStorageCommand,
22 PeerTubeServer,
23 setAccessTokensToServers,
24 waitJobs,
25 webtorrentAdd
26} from '@shared/server-commands'
27import { DEFAULT_AUDIO_RESOLUTION } from '../../../initializers/constants'
28
29const expect = chai.expect
30
31async function checkHlsPlaylist (options: {
32 servers: PeerTubeServer[]
33 videoUUID: string
34 hlsOnly: boolean
35
36 resolutions?: number[]
37 objectStorageBaseUrl: string
38}) {
39 const { videoUUID, hlsOnly, objectStorageBaseUrl } = options
40
41 const resolutions = options.resolutions ?? [ 240, 360, 480, 720 ]
42
43 for (const server of options.servers) {
44 const videoDetails = await server.videos.get({ id: videoUUID })
45 const baseUrl = `http://${videoDetails.account.host}`
46
47 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
48
49 const hlsPlaylist = videoDetails.streamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS)
50 expect(hlsPlaylist).to.not.be.undefined
51
52 const hlsFiles = hlsPlaylist.files
53 expect(hlsFiles).to.have.lengthOf(resolutions.length)
54
55 if (hlsOnly) expect(videoDetails.files).to.have.lengthOf(0)
56 else expect(videoDetails.files).to.have.lengthOf(resolutions.length)
57
58 // Check JSON files
59 for (const resolution of resolutions) {
60 const file = hlsFiles.find(f => f.resolution.id === resolution)
61 expect(file).to.not.be.undefined
62
63 expect(file.magnetUri).to.have.lengthOf.above(2)
64 expect(file.torrentUrl).to.match(
65 new RegExp(`http://${server.host}/lazy-static/torrents/${uuidRegex}-${file.resolution.id}-hls.torrent`)
66 )
67
68 if (objectStorageBaseUrl) {
69 expectStartWith(file.fileUrl, objectStorageBaseUrl)
70 } else {
71 expect(file.fileUrl).to.match(
72 new RegExp(`${baseUrl}/static/streaming-playlists/hls/${videoDetails.uuid}/${uuidRegex}-${file.resolution.id}-fragmented.mp4`)
73 )
74 }
75
76 expect(file.resolution.label).to.equal(resolution + 'p')
77
78 await makeRawRequest(file.torrentUrl, HttpStatusCode.OK_200)
79 await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200)
80
81 const torrent = await webtorrentAdd(file.magnetUri, true)
82 expect(torrent.files).to.be.an('array')
83 expect(torrent.files.length).to.equal(1)
84 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
85 }
86
87 // Check master playlist
88 {
89 await checkResolutionsInMasterPlaylist({ server, playlistUrl: hlsPlaylist.playlistUrl, resolutions })
90
91 const masterPlaylist = await server.streamingPlaylists.get({ url: hlsPlaylist.playlistUrl })
92
93 let i = 0
94 for (const resolution of resolutions) {
95 expect(masterPlaylist).to.contain(`${resolution}.m3u8`)
96 expect(masterPlaylist).to.contain(`${resolution}.m3u8`)
97
98 const url = 'http://' + videoDetails.account.host
99 await hlsInfohashExist(url, hlsPlaylist.playlistUrl, i)
100
101 i++
102 }
103 }
104
105 // Check resolution playlists
106 {
107 for (const resolution of resolutions) {
108 const file = hlsFiles.find(f => f.resolution.id === resolution)
109 const playlistName = removeFragmentedMP4Ext(basename(file.fileUrl)) + '.m3u8'
110
111 const url = objectStorageBaseUrl
112 ? `${objectStorageBaseUrl}hls/${videoUUID}/${playlistName}`
113 : `${baseUrl}/static/streaming-playlists/hls/${videoUUID}/${playlistName}`
114
115 const subPlaylist = await server.streamingPlaylists.get({ url })
116
117 expect(subPlaylist).to.match(new RegExp(`${uuidRegex}-${resolution}-fragmented.mp4`))
118 expect(subPlaylist).to.contain(basename(file.fileUrl))
119 }
120 }
121
122 {
123 const baseUrlAndPath = objectStorageBaseUrl
124 ? objectStorageBaseUrl + 'hls/' + videoUUID
125 : baseUrl + '/static/streaming-playlists/hls/' + videoUUID
126
127 for (const resolution of resolutions) {
128 await checkSegmentHash({
129 server,
130 baseUrlPlaylist: baseUrlAndPath,
131 baseUrlSegment: baseUrlAndPath,
132 resolution,
133 hlsPlaylist
134 })
135 }
136 }
137 }
138}
139
140describe('Test HLS videos', function () {
141 let servers: PeerTubeServer[] = []
142 let videoUUID = ''
143 let videoAudioUUID = ''
144
145 function runTestSuite (hlsOnly: boolean, objectStorageBaseUrl?: string) {
146
147 it('Should upload a video and transcode it to HLS', async function () {
148 this.timeout(120000)
149
150 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video 1', fixture: 'video_short.webm' } })
151 videoUUID = uuid
152
153 await waitJobs(servers)
154
155 await checkHlsPlaylist({ servers, videoUUID, hlsOnly, objectStorageBaseUrl })
156 })
157
158 it('Should upload an audio file and transcode it to HLS', async function () {
159 this.timeout(120000)
160
161 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video audio', fixture: 'sample.ogg' } })
162 videoAudioUUID = uuid
163
164 await waitJobs(servers)
165
166 await checkHlsPlaylist({
167 servers,
168 videoUUID: videoAudioUUID,
169 hlsOnly,
170 resolutions: [ DEFAULT_AUDIO_RESOLUTION, 360, 240 ],
171 objectStorageBaseUrl
172 })
173 })
174
175 it('Should update the video', async function () {
176 this.timeout(30000)
177
178 await servers[0].videos.update({ id: videoUUID, attributes: { name: 'video 1 updated' } })
179
180 await waitJobs(servers)
181
182 await checkHlsPlaylist({ servers, videoUUID, hlsOnly, objectStorageBaseUrl })
183 })
184
185 it('Should delete videos', async function () {
186 this.timeout(10000)
187
188 await servers[0].videos.remove({ id: videoUUID })
189 await servers[0].videos.remove({ id: videoAudioUUID })
190
191 await waitJobs(servers)
192
193 for (const server of servers) {
194 await server.videos.get({ id: videoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
195 await server.videos.get({ id: videoAudioUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
196 }
197 })
198
199 it('Should have the playlists/segment deleted from the disk', async function () {
200 for (const server of servers) {
201 await checkDirectoryIsEmpty(server, 'videos')
202 await checkDirectoryIsEmpty(server, join('streaming-playlists', 'hls'))
203 }
204 })
205
206 it('Should have an empty tmp directory', async function () {
207 for (const server of servers) {
208 await checkTmpIsEmpty(server)
209 }
210 })
211 }
212
213 before(async function () {
214 this.timeout(120000)
215
216 const configOverride = {
217 transcoding: {
218 enabled: true,
219 allow_audio_files: true,
220 hls: {
221 enabled: true
222 }
223 }
224 }
225 servers = await createMultipleServers(2, configOverride)
226
227 // Get the access tokens
228 await setAccessTokensToServers(servers)
229
230 // Server 1 and server 2 follow each other
231 await doubleFollow(servers[0], servers[1])
232 })
233
234 describe('With WebTorrent & HLS enabled', function () {
235 runTestSuite(false)
236 })
237
238 describe('With only HLS enabled', function () {
239
240 before(async function () {
241 await servers[0].config.updateCustomSubConfig({
242 newConfig: {
243 transcoding: {
244 enabled: true,
245 allowAudioFiles: true,
246 resolutions: {
247 '144p': false,
248 '240p': true,
249 '360p': true,
250 '480p': true,
251 '720p': true,
252 '1080p': true,
253 '1440p': true,
254 '2160p': true
255 },
256 hls: {
257 enabled: true
258 },
259 webtorrent: {
260 enabled: false
261 }
262 }
263 }
264 })
265 })
266
267 runTestSuite(true)
268 })
269
270 describe('With object storage enabled', function () {
271 if (areObjectStorageTestsDisabled()) return
272
273 before(async function () {
274 this.timeout(120000)
275
276 const configOverride = ObjectStorageCommand.getDefaultConfig()
277 await ObjectStorageCommand.prepareDefaultBuckets()
278
279 await servers[0].kill()
280 await servers[0].run(configOverride)
281 })
282
283 runTestSuite(true, ObjectStorageCommand.getPlaylistBaseUrl())
284 })
285
286 after(async function () {
287 await cleanupTests(servers)
288 })
289})
diff --git a/server/tests/api/transcoding/index.ts b/server/tests/api/transcoding/index.ts
new file mode 100644
index 000000000..8a0a1d787
--- /dev/null
+++ b/server/tests/api/transcoding/index.ts
@@ -0,0 +1,5 @@
1export * from './audio-only'
2export * from './create-transcoding'
3export * from './hls'
4export * from './transcoder'
5export * from './video-editor'
diff --git a/server/tests/api/transcoding/transcoder.ts b/server/tests/api/transcoding/transcoder.ts
new file mode 100644
index 000000000..245c4c012
--- /dev/null
+++ b/server/tests/api/transcoding/transcoder.ts
@@ -0,0 +1,733 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import * as chai from 'chai'
5import { omit } from 'lodash'
6import { canDoQuickTranscode } from '@server/helpers/ffmpeg'
7import { generateHighBitrateVideo, generateVideoWithFramerate, getAllFiles } from '@server/tests/shared'
8import { buildAbsoluteFixturePath, getMaxBitrate, getMinLimitBitrate } from '@shared/core-utils'
9import {
10 getAudioStream,
11 buildFileMetadata,
12 getVideoStreamBitrate,
13 getVideoStreamFPS,
14 getVideoStreamDimensionsInfo,
15 hasAudioStream
16} from '@shared/extra-utils'
17import { HttpStatusCode, VideoState } from '@shared/models'
18import {
19 cleanupTests,
20 createMultipleServers,
21 doubleFollow,
22 makeGetRequest,
23 PeerTubeServer,
24 setAccessTokensToServers,
25 waitJobs,
26 webtorrentAdd
27} from '@shared/server-commands'
28
29const expect = chai.expect
30
31function updateConfigForTranscoding (server: PeerTubeServer) {
32 return server.config.updateCustomSubConfig({
33 newConfig: {
34 transcoding: {
35 enabled: true,
36 allowAdditionalExtensions: true,
37 allowAudioFiles: true,
38 hls: { enabled: true },
39 webtorrent: { enabled: true },
40 resolutions: {
41 '0p': false,
42 '144p': true,
43 '240p': true,
44 '360p': true,
45 '480p': true,
46 '720p': true,
47 '1080p': true,
48 '1440p': true,
49 '2160p': true
50 }
51 }
52 }
53 })
54}
55
56describe('Test video transcoding', function () {
57 let servers: PeerTubeServer[] = []
58 let video4k: string
59
60 before(async function () {
61 this.timeout(30_000)
62
63 // Run servers
64 servers = await createMultipleServers(2)
65
66 await setAccessTokensToServers(servers)
67
68 await doubleFollow(servers[0], servers[1])
69
70 await updateConfigForTranscoding(servers[1])
71 })
72
73 describe('Basic transcoding (or not)', function () {
74
75 it('Should not transcode video on server 1', async function () {
76 this.timeout(60_000)
77
78 const attributes = {
79 name: 'my super name for server 1',
80 description: 'my super description for server 1',
81 fixture: 'video_short.webm'
82 }
83 await servers[0].videos.upload({ attributes })
84
85 await waitJobs(servers)
86
87 for (const server of servers) {
88 const { data } = await server.videos.list()
89 const video = data[0]
90
91 const videoDetails = await server.videos.get({ id: video.id })
92 expect(videoDetails.files).to.have.lengthOf(1)
93
94 const magnetUri = videoDetails.files[0].magnetUri
95 expect(magnetUri).to.match(/\.webm/)
96
97 const torrent = await webtorrentAdd(magnetUri, true)
98 expect(torrent.files).to.be.an('array')
99 expect(torrent.files.length).to.equal(1)
100 expect(torrent.files[0].path).match(/\.webm$/)
101 }
102 })
103
104 it('Should transcode video on server 2', async function () {
105 this.timeout(120_000)
106
107 const attributes = {
108 name: 'my super name for server 2',
109 description: 'my super description for server 2',
110 fixture: 'video_short.webm'
111 }
112 await servers[1].videos.upload({ attributes })
113
114 await waitJobs(servers)
115
116 for (const server of servers) {
117 const { data } = await server.videos.list()
118
119 const video = data.find(v => v.name === attributes.name)
120 const videoDetails = await server.videos.get({ id: video.id })
121
122 expect(videoDetails.files).to.have.lengthOf(5)
123
124 const magnetUri = videoDetails.files[0].magnetUri
125 expect(magnetUri).to.match(/\.mp4/)
126
127 const torrent = await webtorrentAdd(magnetUri, true)
128 expect(torrent.files).to.be.an('array')
129 expect(torrent.files.length).to.equal(1)
130 expect(torrent.files[0].path).match(/\.mp4$/)
131 }
132 })
133
134 it('Should wait for transcoding before publishing the video', async function () {
135 this.timeout(160_000)
136
137 {
138 // Upload the video, but wait transcoding
139 const attributes = {
140 name: 'waiting video',
141 fixture: 'video_short1.webm',
142 waitTranscoding: true
143 }
144 const { uuid } = await servers[1].videos.upload({ attributes })
145 const videoId = uuid
146
147 // Should be in transcode state
148 const body = await servers[1].videos.get({ id: videoId })
149 expect(body.name).to.equal('waiting video')
150 expect(body.state.id).to.equal(VideoState.TO_TRANSCODE)
151 expect(body.state.label).to.equal('To transcode')
152 expect(body.waitTranscoding).to.be.true
153
154 {
155 // Should have my video
156 const { data } = await servers[1].videos.listMyVideos()
157 const videoToFindInMine = data.find(v => v.name === attributes.name)
158 expect(videoToFindInMine).not.to.be.undefined
159 expect(videoToFindInMine.state.id).to.equal(VideoState.TO_TRANSCODE)
160 expect(videoToFindInMine.state.label).to.equal('To transcode')
161 expect(videoToFindInMine.waitTranscoding).to.be.true
162 }
163
164 {
165 // Should not list this video
166 const { data } = await servers[1].videos.list()
167 const videoToFindInList = data.find(v => v.name === attributes.name)
168 expect(videoToFindInList).to.be.undefined
169 }
170
171 // Server 1 should not have the video yet
172 await servers[0].videos.get({ id: videoId, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
173 }
174
175 await waitJobs(servers)
176
177 for (const server of servers) {
178 const { data } = await server.videos.list()
179 const videoToFind = data.find(v => v.name === 'waiting video')
180 expect(videoToFind).not.to.be.undefined
181
182 const videoDetails = await server.videos.get({ id: videoToFind.id })
183
184 expect(videoDetails.state.id).to.equal(VideoState.PUBLISHED)
185 expect(videoDetails.state.label).to.equal('Published')
186 expect(videoDetails.waitTranscoding).to.be.true
187 }
188 })
189
190 it('Should accept and transcode additional extensions', async function () {
191 this.timeout(300_000)
192
193 for (const fixture of [ 'video_short.mkv', 'video_short.avi' ]) {
194 const attributes = {
195 name: fixture,
196 fixture
197 }
198
199 await servers[1].videos.upload({ attributes })
200
201 await waitJobs(servers)
202
203 for (const server of servers) {
204 const { data } = await server.videos.list()
205
206 const video = data.find(v => v.name === attributes.name)
207 const videoDetails = await server.videos.get({ id: video.id })
208 expect(videoDetails.files).to.have.lengthOf(5)
209
210 const magnetUri = videoDetails.files[0].magnetUri
211 expect(magnetUri).to.contain('.mp4')
212 }
213 }
214 })
215
216 it('Should transcode a 4k video', async function () {
217 this.timeout(200_000)
218
219 const attributes = {
220 name: '4k video',
221 fixture: 'video_short_4k.mp4'
222 }
223
224 const { uuid } = await servers[1].videos.upload({ attributes })
225 video4k = uuid
226
227 await waitJobs(servers)
228
229 const resolutions = [ 144, 240, 360, 480, 720, 1080, 1440, 2160 ]
230
231 for (const server of servers) {
232 const videoDetails = await server.videos.get({ id: video4k })
233 expect(videoDetails.files).to.have.lengthOf(resolutions.length)
234
235 for (const r of resolutions) {
236 expect(videoDetails.files.find(f => f.resolution.id === r)).to.not.be.undefined
237 expect(videoDetails.streamingPlaylists[0].files.find(f => f.resolution.id === r)).to.not.be.undefined
238 }
239 }
240 })
241 })
242
243 describe('Audio transcoding', function () {
244
245 it('Should transcode high bit rate mp3 to proper bit rate', async function () {
246 this.timeout(60_000)
247
248 const attributes = {
249 name: 'mp3_256k',
250 fixture: 'video_short_mp3_256k.mp4'
251 }
252 await servers[1].videos.upload({ attributes })
253
254 await waitJobs(servers)
255
256 for (const server of servers) {
257 const { data } = await server.videos.list()
258
259 const video = data.find(v => v.name === attributes.name)
260 const videoDetails = await server.videos.get({ id: video.id })
261
262 expect(videoDetails.files).to.have.lengthOf(5)
263
264 const file = videoDetails.files.find(f => f.resolution.id === 240)
265 const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
266 const probe = await getAudioStream(path)
267
268 if (probe.audioStream) {
269 expect(probe.audioStream['codec_name']).to.be.equal('aac')
270 expect(probe.audioStream['bit_rate']).to.be.at.most(384 * 8000)
271 } else {
272 this.fail('Could not retrieve the audio stream on ' + probe.absolutePath)
273 }
274 }
275 })
276
277 it('Should transcode video with no audio and have no audio itself', async function () {
278 this.timeout(60_000)
279
280 const attributes = {
281 name: 'no_audio',
282 fixture: 'video_short_no_audio.mp4'
283 }
284 await servers[1].videos.upload({ attributes })
285
286 await waitJobs(servers)
287
288 for (const server of servers) {
289 const { data } = await server.videos.list()
290
291 const video = data.find(v => v.name === attributes.name)
292 const videoDetails = await server.videos.get({ id: video.id })
293
294 const file = videoDetails.files.find(f => f.resolution.id === 240)
295 const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
296
297 expect(await hasAudioStream(path)).to.be.false
298 }
299 })
300
301 it('Should leave the audio untouched, but properly transcode the video', async function () {
302 this.timeout(60_000)
303
304 const attributes = {
305 name: 'untouched_audio',
306 fixture: 'video_short.mp4'
307 }
308 await servers[1].videos.upload({ attributes })
309
310 await waitJobs(servers)
311
312 for (const server of servers) {
313 const { data } = await server.videos.list()
314
315 const video = data.find(v => v.name === attributes.name)
316 const videoDetails = await server.videos.get({ id: video.id })
317
318 expect(videoDetails.files).to.have.lengthOf(5)
319
320 const fixturePath = buildAbsoluteFixturePath(attributes.fixture)
321 const fixtureVideoProbe = await getAudioStream(fixturePath)
322
323 const file = videoDetails.files.find(f => f.resolution.id === 240)
324 const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
325
326 const videoProbe = await getAudioStream(path)
327
328 if (videoProbe.audioStream && fixtureVideoProbe.audioStream) {
329 const toOmit = [ 'max_bit_rate', 'duration', 'duration_ts', 'nb_frames', 'start_time', 'start_pts' ]
330 expect(omit(videoProbe.audioStream, toOmit)).to.be.deep.equal(omit(fixtureVideoProbe.audioStream, toOmit))
331 } else {
332 this.fail('Could not retrieve the audio stream on ' + videoProbe.absolutePath)
333 }
334 }
335 })
336 })
337
338 describe('Audio upload', function () {
339
340 function runSuite (mode: 'legacy' | 'resumable') {
341
342 before(async function () {
343 await servers[1].config.updateCustomSubConfig({
344 newConfig: {
345 transcoding: {
346 hls: { enabled: true },
347 webtorrent: { enabled: true },
348 resolutions: {
349 '0p': false,
350 '144p': false,
351 '240p': false,
352 '360p': false,
353 '480p': false,
354 '720p': false,
355 '1080p': false,
356 '1440p': false,
357 '2160p': false
358 }
359 }
360 }
361 })
362 })
363
364 it('Should merge an audio file with the preview file', async function () {
365 this.timeout(60_000)
366
367 const attributes = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' }
368 await servers[1].videos.upload({ attributes, mode })
369
370 await waitJobs(servers)
371
372 for (const server of servers) {
373 const { data } = await server.videos.list()
374
375 const video = data.find(v => v.name === 'audio_with_preview')
376 const videoDetails = await server.videos.get({ id: video.id })
377
378 expect(videoDetails.files).to.have.lengthOf(1)
379
380 await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, expectedStatus: HttpStatusCode.OK_200 })
381 await makeGetRequest({ url: server.url, path: videoDetails.previewPath, expectedStatus: HttpStatusCode.OK_200 })
382
383 const magnetUri = videoDetails.files[0].magnetUri
384 expect(magnetUri).to.contain('.mp4')
385 }
386 })
387
388 it('Should upload an audio file and choose a default background image', async function () {
389 this.timeout(60_000)
390
391 const attributes = { name: 'audio_without_preview', fixture: 'sample.ogg' }
392 await servers[1].videos.upload({ attributes, mode })
393
394 await waitJobs(servers)
395
396 for (const server of servers) {
397 const { data } = await server.videos.list()
398
399 const video = data.find(v => v.name === 'audio_without_preview')
400 const videoDetails = await server.videos.get({ id: video.id })
401
402 expect(videoDetails.files).to.have.lengthOf(1)
403
404 await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, expectedStatus: HttpStatusCode.OK_200 })
405 await makeGetRequest({ url: server.url, path: videoDetails.previewPath, expectedStatus: HttpStatusCode.OK_200 })
406
407 const magnetUri = videoDetails.files[0].magnetUri
408 expect(magnetUri).to.contain('.mp4')
409 }
410 })
411
412 it('Should upload an audio file and create an audio version only', async function () {
413 this.timeout(60_000)
414
415 await servers[1].config.updateCustomSubConfig({
416 newConfig: {
417 transcoding: {
418 hls: { enabled: true },
419 webtorrent: { enabled: true },
420 resolutions: {
421 '0p': true,
422 '144p': false,
423 '240p': false,
424 '360p': false
425 }
426 }
427 }
428 })
429
430 const attributes = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' }
431 const { id } = await servers[1].videos.upload({ attributes, mode })
432
433 await waitJobs(servers)
434
435 for (const server of servers) {
436 const videoDetails = await server.videos.get({ id })
437
438 for (const files of [ videoDetails.files, videoDetails.streamingPlaylists[0].files ]) {
439 expect(files).to.have.lengthOf(2)
440 expect(files.find(f => f.resolution.id === 0)).to.not.be.undefined
441 }
442 }
443
444 await updateConfigForTranscoding(servers[1])
445 })
446 }
447
448 describe('Legacy upload', function () {
449 runSuite('legacy')
450 })
451
452 describe('Resumable upload', function () {
453 runSuite('resumable')
454 })
455 })
456
457 describe('Framerate', function () {
458
459 it('Should transcode a 60 FPS video', async function () {
460 this.timeout(60_000)
461
462 const attributes = {
463 name: 'my super 30fps name for server 2',
464 description: 'my super 30fps description for server 2',
465 fixture: '60fps_720p_small.mp4'
466 }
467 await servers[1].videos.upload({ attributes })
468
469 await waitJobs(servers)
470
471 for (const server of servers) {
472 const { data } = await server.videos.list()
473
474 const video = data.find(v => v.name === attributes.name)
475 const videoDetails = await server.videos.get({ id: video.id })
476
477 expect(videoDetails.files).to.have.lengthOf(5)
478 expect(videoDetails.files[0].fps).to.be.above(58).and.below(62)
479 expect(videoDetails.files[1].fps).to.be.below(31)
480 expect(videoDetails.files[2].fps).to.be.below(31)
481 expect(videoDetails.files[3].fps).to.be.below(31)
482 expect(videoDetails.files[4].fps).to.be.below(31)
483
484 for (const resolution of [ 144, 240, 360, 480 ]) {
485 const file = videoDetails.files.find(f => f.resolution.id === resolution)
486 const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
487 const fps = await getVideoStreamFPS(path)
488
489 expect(fps).to.be.below(31)
490 }
491
492 const file = videoDetails.files.find(f => f.resolution.id === 720)
493 const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
494 const fps = await getVideoStreamFPS(path)
495
496 expect(fps).to.be.above(58).and.below(62)
497 }
498 })
499
500 it('Should downscale to the closest divisor standard framerate', async function () {
501 this.timeout(200_000)
502
503 let tempFixturePath: string
504
505 {
506 tempFixturePath = await generateVideoWithFramerate(59)
507
508 const fps = await getVideoStreamFPS(tempFixturePath)
509 expect(fps).to.be.equal(59)
510 }
511
512 const attributes = {
513 name: '59fps video',
514 description: '59fps video',
515 fixture: tempFixturePath
516 }
517
518 await servers[1].videos.upload({ attributes })
519
520 await waitJobs(servers)
521
522 for (const server of servers) {
523 const { data } = await server.videos.list()
524
525 const { id } = data.find(v => v.name === attributes.name)
526 const video = await server.videos.get({ id })
527
528 {
529 const file = video.files.find(f => f.resolution.id === 240)
530 const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
531 const fps = await getVideoStreamFPS(path)
532 expect(fps).to.be.equal(25)
533 }
534
535 {
536 const file = video.files.find(f => f.resolution.id === 720)
537 const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
538 const fps = await getVideoStreamFPS(path)
539 expect(fps).to.be.equal(59)
540 }
541 }
542 })
543 })
544
545 describe('Bitrate control', function () {
546
547 it('Should respect maximum bitrate values', async function () {
548 this.timeout(160_000)
549
550 const tempFixturePath = await generateHighBitrateVideo()
551
552 const attributes = {
553 name: 'high bitrate video',
554 description: 'high bitrate video',
555 fixture: tempFixturePath
556 }
557
558 await servers[1].videos.upload({ attributes })
559
560 await waitJobs(servers)
561
562 for (const server of servers) {
563 const { data } = await server.videos.list()
564
565 const { id } = data.find(v => v.name === attributes.name)
566 const video = await server.videos.get({ id })
567
568 for (const resolution of [ 240, 360, 480, 720, 1080 ]) {
569 const file = video.files.find(f => f.resolution.id === resolution)
570 const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
571
572 const bitrate = await getVideoStreamBitrate(path)
573 const fps = await getVideoStreamFPS(path)
574 const dataResolution = await getVideoStreamDimensionsInfo(path)
575
576 expect(resolution).to.equal(resolution)
577
578 const maxBitrate = getMaxBitrate({ ...dataResolution, fps })
579 expect(bitrate).to.be.below(maxBitrate)
580 }
581 }
582 })
583
584 it('Should not transcode to an higher bitrate than the original file but above our low limit', async function () {
585 this.timeout(160_000)
586
587 const newConfig = {
588 transcoding: {
589 enabled: true,
590 resolutions: {
591 '144p': true,
592 '240p': true,
593 '360p': true,
594 '480p': true,
595 '720p': true,
596 '1080p': true,
597 '1440p': true,
598 '2160p': true
599 },
600 webtorrent: { enabled: true },
601 hls: { enabled: true }
602 }
603 }
604 await servers[1].config.updateCustomSubConfig({ newConfig })
605
606 const attributes = {
607 name: 'low bitrate',
608 fixture: 'low-bitrate.mp4'
609 }
610
611 const { id } = await servers[1].videos.upload({ attributes })
612
613 await waitJobs(servers)
614
615 const video = await servers[1].videos.get({ id })
616
617 const resolutions = [ 240, 360, 480, 720, 1080 ]
618 for (const r of resolutions) {
619 const file = video.files.find(f => f.resolution.id === r)
620
621 const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
622 const bitrate = await getVideoStreamBitrate(path)
623
624 const inputBitrate = 60_000
625 const limit = getMinLimitBitrate({ fps: 10, ratio: 1, resolution: r })
626 let belowValue = Math.max(inputBitrate, limit)
627 belowValue += belowValue * 0.20 // Apply 20% margin because bitrate control is not very precise
628
629 expect(bitrate, `${path} not below ${limit}`).to.be.below(belowValue)
630 }
631 })
632 })
633
634 describe('FFprobe', function () {
635
636 it('Should provide valid ffprobe data', async function () {
637 this.timeout(160_000)
638
639 const videoUUID = (await servers[1].videos.quickUpload({ name: 'ffprobe data' })).uuid
640 await waitJobs(servers)
641
642 {
643 const video = await servers[1].videos.get({ id: videoUUID })
644 const file = video.files.find(f => f.resolution.id === 240)
645 const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
646 const metadata = await buildFileMetadata(path)
647
648 // expected format properties
649 for (const p of [
650 'tags.encoder',
651 'format_long_name',
652 'size',
653 'bit_rate'
654 ]) {
655 expect(metadata.format).to.have.nested.property(p)
656 }
657
658 // expected stream properties
659 for (const p of [
660 'codec_long_name',
661 'profile',
662 'width',
663 'height',
664 'display_aspect_ratio',
665 'avg_frame_rate',
666 'pix_fmt'
667 ]) {
668 expect(metadata.streams[0]).to.have.nested.property(p)
669 }
670
671 expect(metadata).to.not.have.nested.property('format.filename')
672 }
673
674 for (const server of servers) {
675 const videoDetails = await server.videos.get({ id: videoUUID })
676
677 const videoFiles = getAllFiles(videoDetails)
678 expect(videoFiles).to.have.lengthOf(10)
679
680 for (const file of videoFiles) {
681 expect(file.metadata).to.be.undefined
682 expect(file.metadataUrl).to.exist
683 expect(file.metadataUrl).to.contain(servers[1].url)
684 expect(file.metadataUrl).to.contain(videoUUID)
685
686 const metadata = await server.videos.getFileMetadata({ url: file.metadataUrl })
687 expect(metadata).to.have.nested.property('format.size')
688 }
689 }
690 })
691
692 it('Should correctly detect if quick transcode is possible', async function () {
693 this.timeout(10_000)
694
695 expect(await canDoQuickTranscode(buildAbsoluteFixturePath('video_short.mp4'))).to.be.true
696 expect(await canDoQuickTranscode(buildAbsoluteFixturePath('video_short.webm'))).to.be.false
697 })
698 })
699
700 describe('Transcoding job queue', function () {
701
702 it('Should have the appropriate priorities for transcoding jobs', async function () {
703 const body = await servers[1].jobs.list({
704 start: 0,
705 count: 100,
706 sort: 'createdAt',
707 jobType: 'video-transcoding'
708 })
709
710 const jobs = body.data
711 const transcodingJobs = jobs.filter(j => j.data.videoUUID === video4k)
712
713 expect(transcodingJobs).to.have.lengthOf(16)
714
715 const hlsJobs = transcodingJobs.filter(j => j.data.type === 'new-resolution-to-hls')
716 const webtorrentJobs = transcodingJobs.filter(j => j.data.type === 'new-resolution-to-webtorrent')
717 const optimizeJobs = transcodingJobs.filter(j => j.data.type === 'optimize-to-webtorrent')
718
719 expect(hlsJobs).to.have.lengthOf(8)
720 expect(webtorrentJobs).to.have.lengthOf(7)
721 expect(optimizeJobs).to.have.lengthOf(1)
722
723 for (const j of optimizeJobs.concat(hlsJobs.concat(webtorrentJobs))) {
724 expect(j.priority).to.be.greaterThan(100)
725 expect(j.priority).to.be.lessThan(150)
726 }
727 })
728 })
729
730 after(async function () {
731 await cleanupTests(servers)
732 })
733})
diff --git a/server/tests/api/transcoding/video-editor.ts b/server/tests/api/transcoding/video-editor.ts
new file mode 100644
index 000000000..a9b6950cc
--- /dev/null
+++ b/server/tests/api/transcoding/video-editor.ts
@@ -0,0 +1,368 @@
1import { expect } from 'chai'
2import { expectStartWith, getAllFiles } from '@server/tests/shared'
3import { areObjectStorageTestsDisabled } from '@shared/core-utils'
4import { VideoEditorTask } from '@shared/models'
5import {
6 cleanupTests,
7 createMultipleServers,
8 doubleFollow,
9 ObjectStorageCommand,
10 PeerTubeServer,
11 setAccessTokensToServers,
12 setDefaultVideoChannel,
13 VideoEditorCommand,
14 waitJobs
15} from '@shared/server-commands'
16
17describe('Test video editor', function () {
18 let servers: PeerTubeServer[] = []
19 let videoUUID: string
20
21 async function checkDuration (server: PeerTubeServer, duration: number) {
22 const video = await server.videos.get({ id: videoUUID })
23
24 expect(video.duration).to.be.approximately(duration, 1)
25
26 for (const file of video.files) {
27 const metadata = await server.videos.getFileMetadata({ url: file.metadataUrl })
28
29 for (const stream of metadata.streams) {
30 expect(Math.round(stream.duration)).to.be.approximately(duration, 1)
31 }
32 }
33 }
34
35 async function renewVideo (fixture = 'video_short.webm') {
36 const video = await servers[0].videos.quickUpload({ name: 'video', fixture })
37 videoUUID = video.uuid
38
39 await waitJobs(servers)
40 }
41
42 async function createTasks (tasks: VideoEditorTask[]) {
43 await servers[0].videoEditor.createEditionTasks({ videoId: videoUUID, tasks })
44 await waitJobs(servers)
45 }
46
47 before(async function () {
48 this.timeout(120_000)
49
50 servers = await createMultipleServers(2)
51
52 await setAccessTokensToServers(servers)
53 await setDefaultVideoChannel(servers)
54
55 await doubleFollow(servers[0], servers[1])
56
57 await servers[0].config.enableMinimumTranscoding()
58
59 await servers[0].config.updateExistingSubConfig({
60 newConfig: {
61 videoEditor: {
62 enabled: true
63 }
64 }
65 })
66 })
67
68 describe('Cutting', function () {
69
70 it('Should cut the beginning of the video', async function () {
71 this.timeout(120_000)
72
73 await renewVideo()
74 await waitJobs(servers)
75
76 const beforeTasks = new Date()
77
78 await createTasks([
79 {
80 name: 'cut',
81 options: {
82 start: 2
83 }
84 }
85 ])
86
87 for (const server of servers) {
88 await checkDuration(server, 3)
89
90 const video = await server.videos.get({ id: videoUUID })
91 expect(new Date(video.publishedAt)).to.be.below(beforeTasks)
92 }
93 })
94
95 it('Should cut the end of the video', async function () {
96 this.timeout(120_000)
97 await renewVideo()
98
99 await createTasks([
100 {
101 name: 'cut',
102 options: {
103 end: 2
104 }
105 }
106 ])
107
108 for (const server of servers) {
109 await checkDuration(server, 2)
110 }
111 })
112
113 it('Should cut start/end of the video', async function () {
114 this.timeout(120_000)
115 await renewVideo('video_short1.webm') // 10 seconds video duration
116
117 await createTasks([
118 {
119 name: 'cut',
120 options: {
121 start: 2,
122 end: 6
123 }
124 }
125 ])
126
127 for (const server of servers) {
128 await checkDuration(server, 4)
129 }
130 })
131 })
132
133 describe('Intro/Outro', function () {
134
135 it('Should add an intro', async function () {
136 this.timeout(120_000)
137 await renewVideo()
138
139 await createTasks([
140 {
141 name: 'add-intro',
142 options: {
143 file: 'video_short.webm'
144 }
145 }
146 ])
147
148 for (const server of servers) {
149 await checkDuration(server, 10)
150 }
151 })
152
153 it('Should add an outro', async function () {
154 this.timeout(120_000)
155 await renewVideo()
156
157 await createTasks([
158 {
159 name: 'add-outro',
160 options: {
161 file: 'video_very_short_240p.mp4'
162 }
163 }
164 ])
165
166 for (const server of servers) {
167 await checkDuration(server, 7)
168 }
169 })
170
171 it('Should add an intro/outro', async function () {
172 this.timeout(120_000)
173 await renewVideo()
174
175 await createTasks([
176 {
177 name: 'add-intro',
178 options: {
179 file: 'video_very_short_240p.mp4'
180 }
181 },
182 {
183 name: 'add-outro',
184 options: {
185 // Different frame rate
186 file: 'video_short2.webm'
187 }
188 }
189 ])
190
191 for (const server of servers) {
192 await checkDuration(server, 12)
193 }
194 })
195
196 it('Should add an intro to a video without audio', async function () {
197 this.timeout(120_000)
198 await renewVideo('video_short_no_audio.mp4')
199
200 await createTasks([
201 {
202 name: 'add-intro',
203 options: {
204 file: 'video_very_short_240p.mp4'
205 }
206 }
207 ])
208
209 for (const server of servers) {
210 await checkDuration(server, 7)
211 }
212 })
213
214 it('Should add an outro without audio to a video with audio', async function () {
215 this.timeout(120_000)
216 await renewVideo()
217
218 await createTasks([
219 {
220 name: 'add-outro',
221 options: {
222 file: 'video_short_no_audio.mp4'
223 }
224 }
225 ])
226
227 for (const server of servers) {
228 await checkDuration(server, 10)
229 }
230 })
231
232 it('Should add an outro without audio to a video with audio', async function () {
233 this.timeout(120_000)
234 await renewVideo('video_short_no_audio.mp4')
235
236 await createTasks([
237 {
238 name: 'add-outro',
239 options: {
240 file: 'video_short_no_audio.mp4'
241 }
242 }
243 ])
244
245 for (const server of servers) {
246 await checkDuration(server, 10)
247 }
248 })
249 })
250
251 describe('Watermark', function () {
252
253 it('Should add a watermark to the video', async function () {
254 this.timeout(120_000)
255 await renewVideo()
256
257 const video = await servers[0].videos.get({ id: videoUUID })
258 const oldFileUrls = getAllFiles(video).map(f => f.fileUrl)
259
260 await createTasks([
261 {
262 name: 'add-watermark',
263 options: {
264 file: 'thumbnail.png'
265 }
266 }
267 ])
268
269 for (const server of servers) {
270 const video = await server.videos.get({ id: videoUUID })
271 const fileUrls = getAllFiles(video).map(f => f.fileUrl)
272
273 for (const oldUrl of oldFileUrls) {
274 expect(fileUrls).to.not.include(oldUrl)
275 }
276 }
277 })
278 })
279
280 describe('Complex tasks', function () {
281 it('Should run a complex task', async function () {
282 this.timeout(240_000)
283 await renewVideo()
284
285 await createTasks(VideoEditorCommand.getComplexTask())
286
287 for (const server of servers) {
288 await checkDuration(server, 9)
289 }
290 })
291 })
292
293 describe('HLS only video edition', function () {
294
295 before(async function () {
296 // Disable webtorrent
297 await servers[0].config.updateExistingSubConfig({
298 newConfig: {
299 transcoding: {
300 webtorrent: {
301 enabled: false
302 }
303 }
304 }
305 })
306 })
307
308 it('Should run a complex task on HLS only video', async function () {
309 this.timeout(240_000)
310 await renewVideo()
311
312 await createTasks(VideoEditorCommand.getComplexTask())
313
314 for (const server of servers) {
315 const video = await server.videos.get({ id: videoUUID })
316 expect(video.files).to.have.lengthOf(0)
317
318 await checkDuration(server, 9)
319 }
320 })
321 })
322
323 describe('Object storage video edition', function () {
324 if (areObjectStorageTestsDisabled()) return
325
326 before(async function () {
327 await ObjectStorageCommand.prepareDefaultBuckets()
328
329 await servers[0].kill()
330 await servers[0].run(ObjectStorageCommand.getDefaultConfig())
331
332 await servers[0].config.enableMinimumTranscoding()
333 })
334
335 it('Should run a complex task on a video in object storage', async function () {
336 this.timeout(240_000)
337 await renewVideo()
338
339 const video = await servers[0].videos.get({ id: videoUUID })
340 const oldFileUrls = getAllFiles(video).map(f => f.fileUrl)
341
342 await createTasks(VideoEditorCommand.getComplexTask())
343
344 for (const server of servers) {
345 const video = await server.videos.get({ id: videoUUID })
346 const files = getAllFiles(video)
347
348 for (const f of files) {
349 expect(oldFileUrls).to.not.include(f.fileUrl)
350 }
351
352 for (const webtorrentFile of video.files) {
353 expectStartWith(webtorrentFile.fileUrl, ObjectStorageCommand.getWebTorrentBaseUrl())
354 }
355
356 for (const hlsFile of video.streamingPlaylists[0].files) {
357 expectStartWith(hlsFile.fileUrl, ObjectStorageCommand.getPlaylistBaseUrl())
358 }
359
360 await checkDuration(server, 9)
361 }
362 })
363 })
364
365 after(async function () {
366 await cleanupTests(servers)
367 })
368})