]>
Commit | Line | Data |
---|---|---|
0e1dc3e7 C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
0e1dc3e7 | 3 | import * as chai from 'chai' |
a7ba16b6 | 4 | import 'mocha' |
7160878c RK |
5 | import { omit } from 'lodash' |
6 | import * as ffmpeg from 'fluent-ffmpeg' | |
2186386c | 7 | import { VideoDetails, VideoState } from '../../../../shared/models/videos' |
7160878c | 8 | import { getVideoFileFPS, audio } from '../../../helpers/ffmpeg-utils' |
0e1dc3e7 | 9 | import { |
7160878c | 10 | buildAbsoluteFixturePath, |
2186386c C |
11 | doubleFollow, |
12 | flushAndRunMultipleServers, | |
2186386c C |
13 | getMyVideos, |
14 | getVideo, | |
15 | getVideosList, | |
16 | killallServers, | |
17 | root, | |
18 | ServerInfo, | |
19 | setAccessTokensToServers, | |
20 | uploadVideo, | |
2186386c | 21 | webtorrentAdd |
a7ba16b6 | 22 | } from '../../utils' |
73c69591 | 23 | import { join } from 'path' |
3cd0734f | 24 | import { waitJobs } from '../../utils/server/jobs' |
a7ba16b6 C |
25 | |
26 | const expect = chai.expect | |
0e1dc3e7 C |
27 | |
28 | describe('Test video transcoding', function () { | |
29 | let servers: ServerInfo[] = [] | |
30 | ||
31 | before(async function () { | |
e212f887 | 32 | this.timeout(30000) |
0e1dc3e7 C |
33 | |
34 | // Run servers | |
35 | servers = await flushAndRunMultipleServers(2) | |
36 | ||
37 | await setAccessTokensToServers(servers) | |
b2977eec C |
38 | |
39 | await doubleFollow(servers[0], servers[1]) | |
0e1dc3e7 C |
40 | }) |
41 | ||
42 | it('Should not transcode video on server 1', async function () { | |
43 | this.timeout(60000) | |
44 | ||
45 | const videoAttributes = { | |
975e6e0e C |
46 | name: 'my super name for server 1', |
47 | description: 'my super description for server 1', | |
0e1dc3e7 C |
48 | fixture: 'video_short.webm' |
49 | } | |
50 | await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) | |
51 | ||
3cd0734f | 52 | await waitJobs(servers) |
0e1dc3e7 | 53 | |
b2977eec C |
54 | for (const server of servers) { |
55 | const res = await getVideosList(server.url) | |
56 | const video = res.body.data[ 0 ] | |
40298b02 | 57 | |
b2977eec C |
58 | const res2 = await getVideo(server.url, video.id) |
59 | const videoDetails = res2.body | |
60 | expect(videoDetails.files).to.have.lengthOf(1) | |
5f04dd2f | 61 | |
b2977eec C |
62 | const magnetUri = videoDetails.files[ 0 ].magnetUri |
63 | expect(magnetUri).to.match(/\.webm/) | |
0e1dc3e7 | 64 | |
b2977eec C |
65 | const torrent = await webtorrentAdd(magnetUri, true) |
66 | expect(torrent.files).to.be.an('array') | |
67 | expect(torrent.files.length).to.equal(1) | |
68 | expect(torrent.files[ 0 ].path).match(/\.webm$/) | |
69 | } | |
0e1dc3e7 C |
70 | }) |
71 | ||
72 | it('Should transcode video on server 2', async function () { | |
73 | this.timeout(60000) | |
74 | ||
75 | const videoAttributes = { | |
975e6e0e C |
76 | name: 'my super name for server 2', |
77 | description: 'my super description for server 2', | |
0e1dc3e7 C |
78 | fixture: 'video_short.webm' |
79 | } | |
80 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) | |
81 | ||
3cd0734f | 82 | await waitJobs(servers) |
0e1dc3e7 | 83 | |
b2977eec C |
84 | for (const server of servers) { |
85 | const res = await getVideosList(server.url) | |
0e1dc3e7 | 86 | |
b2977eec C |
87 | const video = res.body.data.find(v => v.name === videoAttributes.name) |
88 | const res2 = await getVideo(server.url, video.id) | |
89 | const videoDetails = res2.body | |
5f04dd2f | 90 | |
b2977eec | 91 | expect(videoDetails.files).to.have.lengthOf(4) |
40298b02 | 92 | |
b2977eec C |
93 | const magnetUri = videoDetails.files[ 0 ].magnetUri |
94 | expect(magnetUri).to.match(/\.mp4/) | |
0e1dc3e7 | 95 | |
b2977eec C |
96 | const torrent = await webtorrentAdd(magnetUri, true) |
97 | expect(torrent.files).to.be.an('array') | |
98 | expect(torrent.files.length).to.equal(1) | |
99 | expect(torrent.files[ 0 ].path).match(/\.mp4$/) | |
100 | } | |
0e1dc3e7 C |
101 | }) |
102 | ||
7160878c RK |
103 | it('Should transcode high bit rate mp3 to proper bit rate', async function () { |
104 | this.timeout(60000) | |
105 | ||
106 | const videoAttributes = { | |
107 | name: 'mp3_256k', | |
108 | fixture: 'video_short_mp3_256k.mp4' | |
109 | } | |
110 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) | |
111 | ||
112 | await waitJobs(servers) | |
113 | ||
b2977eec C |
114 | for (const server of servers) { |
115 | const res = await getVideosList(server.url) | |
7160878c | 116 | |
b2977eec C |
117 | const video = res.body.data.find(v => v.name === videoAttributes.name) |
118 | const res2 = await getVideo(server.url, video.id) | |
119 | const videoDetails: VideoDetails = res2.body | |
7160878c | 120 | |
b2977eec | 121 | expect(videoDetails.files).to.have.lengthOf(4) |
7160878c | 122 | |
b2977eec C |
123 | const path = join(root(), 'test2', 'videos', video.uuid + '-240.mp4') |
124 | const probe = await audio.get(ffmpeg, path) | |
7160878c | 125 | |
b2977eec C |
126 | if (probe.audioStream) { |
127 | expect(probe.audioStream[ 'codec_name' ]).to.be.equal('aac') | |
128 | expect(probe.audioStream[ 'bit_rate' ]).to.be.at.most(384 * 8000) | |
129 | } else { | |
130 | this.fail('Could not retrieve the audio stream on ' + probe.absolutePath) | |
131 | } | |
7160878c RK |
132 | } |
133 | }) | |
134 | ||
135 | it('Should transcode video with no audio and have no audio itself', async function () { | |
136 | this.timeout(60000) | |
137 | ||
138 | const videoAttributes = { | |
139 | name: 'no_audio', | |
140 | fixture: 'video_short_no_audio.mp4' | |
141 | } | |
142 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) | |
143 | ||
144 | await waitJobs(servers) | |
145 | ||
b2977eec C |
146 | for (const server of servers) { |
147 | const res = await getVideosList(server.url) | |
7160878c | 148 | |
b2977eec C |
149 | const video = res.body.data.find(v => v.name === videoAttributes.name) |
150 | const res2 = await getVideo(server.url, video.id) | |
151 | const videoDetails: VideoDetails = res2.body | |
7160878c | 152 | |
b2977eec C |
153 | expect(videoDetails.files).to.have.lengthOf(4) |
154 | const path = join(root(), 'test2', 'videos', video.uuid + '-240.mp4') | |
155 | const probe = await audio.get(ffmpeg, path) | |
156 | expect(probe).to.not.have.property('audioStream') | |
157 | } | |
7160878c RK |
158 | }) |
159 | ||
160 | it('Should leave the audio untouched, but properly transcode the video', async function () { | |
161 | this.timeout(60000) | |
162 | ||
163 | const videoAttributes = { | |
164 | name: 'untouched_audio', | |
165 | fixture: 'video_short.mp4' | |
166 | } | |
167 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) | |
168 | ||
169 | await waitJobs(servers) | |
170 | ||
b2977eec C |
171 | for (const server of servers) { |
172 | const res = await getVideosList(server.url) | |
173 | ||
174 | const video = res.body.data.find(v => v.name === videoAttributes.name) | |
175 | const res2 = await getVideo(server.url, video.id) | |
176 | const videoDetails: VideoDetails = res2.body | |
177 | ||
178 | expect(videoDetails.files).to.have.lengthOf(4) | |
179 | const fixturePath = buildAbsoluteFixturePath(videoAttributes.fixture) | |
180 | const fixtureVideoProbe = await audio.get(ffmpeg, fixturePath) | |
181 | const path = join(root(), 'test2', 'videos', video.uuid + '-240.mp4') | |
182 | const videoProbe = await audio.get(ffmpeg, path) | |
183 | if (videoProbe.audioStream && fixtureVideoProbe.audioStream) { | |
184 | const toOmit = [ 'max_bit_rate', 'duration', 'duration_ts', 'nb_frames', 'start_time', 'start_pts' ] | |
185 | expect(omit(videoProbe.audioStream, toOmit)).to.be.deep.equal(omit(fixtureVideoProbe.audioStream, toOmit)) | |
186 | } else { | |
187 | this.fail('Could not retrieve the audio stream on ' + videoProbe.absolutePath) | |
188 | } | |
7160878c RK |
189 | } |
190 | }) | |
191 | ||
3a6f351b | 192 | it('Should transcode a 60 FPS video', async function () { |
73c69591 C |
193 | this.timeout(60000) |
194 | ||
195 | const videoAttributes = { | |
196 | name: 'my super 30fps name for server 2', | |
197 | description: 'my super 30fps description for server 2', | |
3a6f351b | 198 | fixture: '60fps_720p_small.mp4' |
73c69591 C |
199 | } |
200 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) | |
201 | ||
3cd0734f | 202 | await waitJobs(servers) |
73c69591 | 203 | |
b2977eec C |
204 | for (const server of servers) { |
205 | const res = await getVideosList(server.url) | |
73c69591 | 206 | |
b2977eec C |
207 | const video = res.body.data.find(v => v.name === videoAttributes.name) |
208 | const res2 = await getVideo(server.url, video.id) | |
209 | const videoDetails: VideoDetails = res2.body | |
73c69591 | 210 | |
b2977eec C |
211 | expect(videoDetails.files).to.have.lengthOf(4) |
212 | expect(videoDetails.files[ 0 ].fps).to.be.above(58).and.below(62) | |
213 | expect(videoDetails.files[ 1 ].fps).to.be.below(31) | |
214 | expect(videoDetails.files[ 2 ].fps).to.be.below(31) | |
215 | expect(videoDetails.files[ 3 ].fps).to.be.below(31) | |
73c69591 | 216 | |
b2977eec C |
217 | for (const resolution of [ '240', '360', '480' ]) { |
218 | const path = join(root(), 'test2', 'videos', video.uuid + '-' + resolution + '.mp4') | |
219 | const fps = await getVideoFileFPS(path) | |
73c69591 | 220 | |
b2977eec C |
221 | expect(fps).to.be.below(31) |
222 | } | |
3a6f351b | 223 | |
b2977eec C |
224 | const path = join(root(), 'test2', 'videos', video.uuid + '-720.mp4') |
225 | const fps = await getVideoFileFPS(path) | |
3a6f351b | 226 | |
b2977eec C |
227 | expect(fps).to.be.above(58).and.below(62) |
228 | } | |
73c69591 C |
229 | }) |
230 | ||
2186386c C |
231 | it('Should wait transcoding before publishing the video', async function () { |
232 | this.timeout(80000) | |
233 | ||
2186386c C |
234 | { |
235 | // Upload the video, but wait transcoding | |
236 | const videoAttributes = { | |
237 | name: 'waiting video', | |
238 | fixture: 'video_short1.webm', | |
239 | waitTranscoding: true | |
240 | } | |
241 | const resVideo = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, videoAttributes) | |
242 | const videoId = resVideo.body.video.uuid | |
243 | ||
244 | // Should be in transcode state | |
245 | const { body } = await getVideo(servers[ 1 ].url, videoId) | |
246 | expect(body.name).to.equal('waiting video') | |
247 | expect(body.state.id).to.equal(VideoState.TO_TRANSCODE) | |
248 | expect(body.state.label).to.equal('To transcode') | |
249 | expect(body.waitTranscoding).to.be.true | |
250 | ||
251 | // Should have my video | |
252 | const resMyVideos = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 10) | |
7160878c | 253 | const videoToFindInMine = resMyVideos.body.data.find(v => v.name === videoAttributes.name) |
2186386c C |
254 | expect(videoToFindInMine).not.to.be.undefined |
255 | expect(videoToFindInMine.state.id).to.equal(VideoState.TO_TRANSCODE) | |
256 | expect(videoToFindInMine.state.label).to.equal('To transcode') | |
257 | expect(videoToFindInMine.waitTranscoding).to.be.true | |
258 | ||
259 | // Should not list this video | |
260 | const resVideos = await getVideosList(servers[1].url) | |
7160878c | 261 | const videoToFindInList = resVideos.body.data.find(v => v.name === videoAttributes.name) |
2186386c C |
262 | expect(videoToFindInList).to.be.undefined |
263 | ||
264 | // Server 1 should not have the video yet | |
265 | await getVideo(servers[0].url, videoId, 404) | |
266 | } | |
267 | ||
3cd0734f | 268 | await waitJobs(servers) |
2186386c C |
269 | |
270 | for (const server of servers) { | |
271 | const res = await getVideosList(server.url) | |
272 | const videoToFind = res.body.data.find(v => v.name === 'waiting video') | |
273 | expect(videoToFind).not.to.be.undefined | |
274 | ||
275 | const res2 = await getVideo(server.url, videoToFind.id) | |
276 | const videoDetails: VideoDetails = res2.body | |
277 | ||
278 | expect(videoDetails.state.id).to.equal(VideoState.PUBLISHED) | |
279 | expect(videoDetails.state.label).to.equal('Published') | |
280 | expect(videoDetails.waitTranscoding).to.be.true | |
281 | } | |
282 | }) | |
283 | ||
0e1dc3e7 C |
284 | after(async function () { |
285 | killallServers(servers) | |
0e1dc3e7 C |
286 | }) |
287 | }) |