]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/videos/video-transcoder.ts
Update the api documentation
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / video-transcoder.ts
CommitLineData
0e1dc3e7
C
1/* tslint:disable:no-unused-expression */
2
0e1dc3e7 3import * as chai from 'chai'
a7ba16b6 4import 'mocha'
73c69591
C
5import { VideoDetails } from '../../../../shared/models/videos'
6import { getVideoFileFPS } from '../../../helpers/ffmpeg-utils'
0e1dc3e7 7import {
73c69591 8 flushAndRunMultipleServers, flushTests, getVideo, getVideosList, killallServers, root, ServerInfo, setAccessTokensToServers, uploadVideo,
a7ba16b6
C
9 wait, webtorrentAdd
10} from '../../utils'
73c69591 11import { join } from 'path'
a7ba16b6
C
12
13const expect = chai.expect
0e1dc3e7
C
14
15describe('Test video transcoding', function () {
16 let servers: ServerInfo[] = []
17
18 before(async function () {
e212f887 19 this.timeout(30000)
0e1dc3e7
C
20
21 // Run servers
22 servers = await flushAndRunMultipleServers(2)
23
24 await setAccessTokensToServers(servers)
25 })
26
27 it('Should not transcode video on server 1', async function () {
28 this.timeout(60000)
29
30 const videoAttributes = {
975e6e0e
C
31 name: 'my super name for server 1',
32 description: 'my super description for server 1',
0e1dc3e7
C
33 fixture: 'video_short.webm'
34 }
35 await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
36
572f8d3d 37 await wait(10000)
0e1dc3e7
C
38
39 const res = await getVideosList(servers[0].url)
40 const video = res.body.data[0]
40298b02 41
5f04dd2f
C
42 const res2 = await getVideo(servers[0].url, video.id)
43 const videoDetails = res2.body
44 expect(videoDetails.files).to.have.lengthOf(1)
45
46 const magnetUri = videoDetails.files[0].magnetUri
0e1dc3e7
C
47 expect(magnetUri).to.match(/\.webm/)
48
49 const torrent = await webtorrentAdd(magnetUri)
50 expect(torrent.files).to.be.an('array')
51 expect(torrent.files.length).to.equal(1)
52 expect(torrent.files[0].path).match(/\.webm$/)
53 })
54
55 it('Should transcode video on server 2', async function () {
56 this.timeout(60000)
57
58 const videoAttributes = {
975e6e0e
C
59 name: 'my super name for server 2',
60 description: 'my super description for server 2',
0e1dc3e7
C
61 fixture: 'video_short.webm'
62 }
63 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes)
64
5e3bb76c 65 await wait(20000)
0e1dc3e7
C
66
67 const res = await getVideosList(servers[1].url)
68
69 const video = res.body.data[0]
5f04dd2f
C
70 const res2 = await getVideo(servers[1].url, video.id)
71 const videoDetails = res2.body
72
73 expect(videoDetails.files).to.have.lengthOf(4)
40298b02 74
5f04dd2f 75 const magnetUri = videoDetails.files[0].magnetUri
0e1dc3e7
C
76 expect(magnetUri).to.match(/\.mp4/)
77
78 const torrent = await webtorrentAdd(magnetUri)
79 expect(torrent.files).to.be.an('array')
80 expect(torrent.files.length).to.equal(1)
81 expect(torrent.files[0].path).match(/\.mp4$/)
82 })
83
73c69591
C
84 it('Should transcode to 30 FPS', async function () {
85 this.timeout(60000)
86
87 const videoAttributes = {
88 name: 'my super 30fps name for server 2',
89 description: 'my super 30fps description for server 2',
90 fixture: 'video_60fps_short.mp4'
91 }
92 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes)
93
94 await wait(20000)
95
96 const res = await getVideosList(servers[1].url)
97
98 const video = res.body.data[0]
99 const res2 = await getVideo(servers[1].url, video.id)
100 const videoDetails: VideoDetails = res2.body
101
102 expect(videoDetails.files).to.have.lengthOf(1)
103
104 for (const resolution of [ '240' ]) {
105 const path = join(root(), 'test2', 'videos', video.uuid + '-' + resolution + '.mp4')
106 const fps = await getVideoFileFPS(path)
107
108 expect(fps).to.be.below(31)
109 }
110 })
111
0e1dc3e7
C
112 after(async function () {
113 killallServers(servers)
114
115 // Keep the logs if the test failed
116 if (this['ok']) {
117 await flushTests()
118 }
119 })
120})