]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/transcoding/video-studio.ts
2f64ef6bdb88c4f6019ff5012a61a99af563e625
[github/Chocobozzz/PeerTube.git] / server / tests / api / transcoding / video-studio.ts
1 import { expect } from 'chai'
2 import { checkPersistentTmpIsEmpty, checkVideoDuration, expectStartWith } from '@server/tests/shared'
3 import { areMockObjectStorageTestsDisabled, getAllFiles } from '@shared/core-utils'
4 import { VideoStudioTask } from '@shared/models'
5 import {
6 cleanupTests,
7 createMultipleServers,
8 doubleFollow,
9 ObjectStorageCommand,
10 PeerTubeServer,
11 setAccessTokensToServers,
12 setDefaultVideoChannel,
13 VideoStudioCommand,
14 waitJobs
15 } from '@shared/server-commands'
16
17 describe('Test video studio', function () {
18 let servers: PeerTubeServer[] = []
19 let videoUUID: string
20
21 async function renewVideo (fixture = 'video_short.webm') {
22 const video = await servers[0].videos.quickUpload({ name: 'video', fixture })
23 videoUUID = video.uuid
24
25 await waitJobs(servers)
26 }
27
28 async function createTasks (tasks: VideoStudioTask[]) {
29 await servers[0].videoStudio.createEditionTasks({ videoId: videoUUID, tasks })
30 await waitJobs(servers)
31 }
32
33 before(async function () {
34 this.timeout(120_000)
35
36 servers = await createMultipleServers(2)
37
38 await setAccessTokensToServers(servers)
39 await setDefaultVideoChannel(servers)
40
41 await doubleFollow(servers[0], servers[1])
42
43 await servers[0].config.enableMinimumTranscoding()
44
45 await servers[0].config.enableStudio()
46 })
47
48 describe('Cutting', function () {
49
50 it('Should cut the beginning of the video', async function () {
51 this.timeout(120_000)
52
53 await renewVideo()
54 await waitJobs(servers)
55
56 const beforeTasks = new Date()
57
58 await createTasks([
59 {
60 name: 'cut',
61 options: {
62 start: 2
63 }
64 }
65 ])
66
67 for (const server of servers) {
68 await checkVideoDuration(server, videoUUID, 3)
69
70 const video = await server.videos.get({ id: videoUUID })
71 expect(new Date(video.publishedAt)).to.be.below(beforeTasks)
72 }
73 })
74
75 it('Should cut the end of the video', async function () {
76 this.timeout(120_000)
77 await renewVideo()
78
79 await createTasks([
80 {
81 name: 'cut',
82 options: {
83 end: 2
84 }
85 }
86 ])
87
88 for (const server of servers) {
89 await checkVideoDuration(server, videoUUID, 2)
90 }
91 })
92
93 it('Should cut start/end of the video', async function () {
94 this.timeout(120_000)
95 await renewVideo('video_short1.webm') // 10 seconds video duration
96
97 await createTasks([
98 {
99 name: 'cut',
100 options: {
101 start: 2,
102 end: 6
103 }
104 }
105 ])
106
107 for (const server of servers) {
108 await checkVideoDuration(server, videoUUID, 4)
109 }
110 })
111 })
112
113 describe('Intro/Outro', function () {
114
115 it('Should add an intro', async function () {
116 this.timeout(120_000)
117 await renewVideo()
118
119 await createTasks([
120 {
121 name: 'add-intro',
122 options: {
123 file: 'video_short.webm'
124 }
125 }
126 ])
127
128 for (const server of servers) {
129 await checkVideoDuration(server, videoUUID, 10)
130 }
131 })
132
133 it('Should add an outro', async function () {
134 this.timeout(120_000)
135 await renewVideo()
136
137 await createTasks([
138 {
139 name: 'add-outro',
140 options: {
141 file: 'video_very_short_240p.mp4'
142 }
143 }
144 ])
145
146 for (const server of servers) {
147 await checkVideoDuration(server, videoUUID, 7)
148 }
149 })
150
151 it('Should add an intro/outro', async function () {
152 this.timeout(120_000)
153 await renewVideo()
154
155 await createTasks([
156 {
157 name: 'add-intro',
158 options: {
159 file: 'video_very_short_240p.mp4'
160 }
161 },
162 {
163 name: 'add-outro',
164 options: {
165 // Different frame rate
166 file: 'video_short2.webm'
167 }
168 }
169 ])
170
171 for (const server of servers) {
172 await checkVideoDuration(server, videoUUID, 12)
173 }
174 })
175
176 it('Should add an intro to a video without audio', async function () {
177 this.timeout(120_000)
178 await renewVideo('video_short_no_audio.mp4')
179
180 await createTasks([
181 {
182 name: 'add-intro',
183 options: {
184 file: 'video_very_short_240p.mp4'
185 }
186 }
187 ])
188
189 for (const server of servers) {
190 await checkVideoDuration(server, videoUUID, 7)
191 }
192 })
193
194 it('Should add an outro without audio to a video with audio', async function () {
195 this.timeout(120_000)
196 await renewVideo()
197
198 await createTasks([
199 {
200 name: 'add-outro',
201 options: {
202 file: 'video_short_no_audio.mp4'
203 }
204 }
205 ])
206
207 for (const server of servers) {
208 await checkVideoDuration(server, videoUUID, 10)
209 }
210 })
211
212 it('Should add an outro without audio to a video with audio', async function () {
213 this.timeout(120_000)
214 await renewVideo('video_short_no_audio.mp4')
215
216 await createTasks([
217 {
218 name: 'add-outro',
219 options: {
220 file: 'video_short_no_audio.mp4'
221 }
222 }
223 ])
224
225 for (const server of servers) {
226 await checkVideoDuration(server, videoUUID, 10)
227 }
228 })
229 })
230
231 describe('Watermark', function () {
232
233 it('Should add a watermark to the video', async function () {
234 this.timeout(120_000)
235 await renewVideo()
236
237 const video = await servers[0].videos.get({ id: videoUUID })
238 const oldFileUrls = getAllFiles(video).map(f => f.fileUrl)
239
240 await createTasks([
241 {
242 name: 'add-watermark',
243 options: {
244 file: 'thumbnail.png'
245 }
246 }
247 ])
248
249 for (const server of servers) {
250 const video = await server.videos.get({ id: videoUUID })
251 const fileUrls = getAllFiles(video).map(f => f.fileUrl)
252
253 for (const oldUrl of oldFileUrls) {
254 expect(fileUrls).to.not.include(oldUrl)
255 }
256 }
257 })
258 })
259
260 describe('Complex tasks', function () {
261 it('Should run a complex task', async function () {
262 this.timeout(240_000)
263 await renewVideo()
264
265 await createTasks(VideoStudioCommand.getComplexTask())
266
267 for (const server of servers) {
268 await checkVideoDuration(server, videoUUID, 9)
269 }
270 })
271 })
272
273 describe('HLS only video edition', function () {
274
275 before(async function () {
276 // Disable webtorrent
277 await servers[0].config.updateExistingSubConfig({
278 newConfig: {
279 transcoding: {
280 webtorrent: {
281 enabled: false
282 }
283 }
284 }
285 })
286 })
287
288 it('Should run a complex task on HLS only video', async function () {
289 this.timeout(240_000)
290 await renewVideo()
291
292 await createTasks(VideoStudioCommand.getComplexTask())
293
294 for (const server of servers) {
295 const video = await server.videos.get({ id: videoUUID })
296 expect(video.files).to.have.lengthOf(0)
297
298 await checkVideoDuration(server, videoUUID, 9)
299 }
300 })
301 })
302
303 describe('Object storage video edition', function () {
304 if (areMockObjectStorageTestsDisabled()) return
305
306 before(async function () {
307 await ObjectStorageCommand.prepareDefaultMockBuckets()
308
309 await servers[0].kill()
310 await servers[0].run(ObjectStorageCommand.getDefaultMockConfig())
311
312 await servers[0].config.enableMinimumTranscoding()
313 })
314
315 it('Should run a complex task on a video in object storage', async function () {
316 this.timeout(240_000)
317 await renewVideo()
318
319 const video = await servers[0].videos.get({ id: videoUUID })
320 const oldFileUrls = getAllFiles(video).map(f => f.fileUrl)
321
322 await createTasks(VideoStudioCommand.getComplexTask())
323
324 for (const server of servers) {
325 const video = await server.videos.get({ id: videoUUID })
326 const files = getAllFiles(video)
327
328 for (const f of files) {
329 expect(oldFileUrls).to.not.include(f.fileUrl)
330 }
331
332 for (const webtorrentFile of video.files) {
333 expectStartWith(webtorrentFile.fileUrl, ObjectStorageCommand.getMockWebTorrentBaseUrl())
334 }
335
336 for (const hlsFile of video.streamingPlaylists[0].files) {
337 expectStartWith(hlsFile.fileUrl, ObjectStorageCommand.getMockPlaylistBaseUrl())
338 }
339
340 await checkVideoDuration(server, videoUUID, 9)
341 }
342 })
343 })
344
345 describe('Server restart', function () {
346
347 it('Should still be able to run video edition after a server restart', async function () {
348 this.timeout(240_000)
349
350 await renewVideo()
351 await servers[0].videoStudio.createEditionTasks({ videoId: videoUUID, tasks: VideoStudioCommand.getComplexTask() })
352
353 await servers[0].kill()
354 await servers[0].run()
355
356 await waitJobs(servers)
357
358 for (const server of servers) {
359 await checkVideoDuration(server, videoUUID, 9)
360 }
361 })
362
363 it('Should have an empty persistent tmp directory', async function () {
364 await checkPersistentTmpIsEmpty(servers[0])
365 })
366 })
367
368 after(async function () {
369 await cleanupTests(servers)
370 })
371 })