]>
Commit | Line | Data |
---|---|---|
1 | /* tslint:disable:no-unused-expression */ | |
2 | ||
3 | import * as chai from 'chai' | |
4 | import 'mocha' | |
5 | import { omit } from 'lodash' | |
6 | import * as ffmpeg from 'fluent-ffmpeg' | |
7 | import { VideoDetails, VideoState } from '../../../../shared/models/videos' | |
8 | import { getVideoFileFPS, audio } from '../../../helpers/ffmpeg-utils' | |
9 | import { | |
10 | buildAbsoluteFixturePath, | |
11 | doubleFollow, | |
12 | flushAndRunMultipleServers, | |
13 | getMyVideos, | |
14 | getVideo, | |
15 | getVideosList, | |
16 | killallServers, | |
17 | root, | |
18 | ServerInfo, | |
19 | setAccessTokensToServers, | |
20 | uploadVideo, | |
21 | webtorrentAdd | |
22 | } from '../../utils' | |
23 | import { join } from 'path' | |
24 | import { waitJobs } from '../../utils/server/jobs' | |
25 | ||
26 | const expect = chai.expect | |
27 | ||
28 | describe('Test video transcoding', function () { | |
29 | let servers: ServerInfo[] = [] | |
30 | ||
31 | before(async function () { | |
32 | this.timeout(30000) | |
33 | ||
34 | // Run servers | |
35 | servers = await flushAndRunMultipleServers(2) | |
36 | ||
37 | await setAccessTokensToServers(servers) | |
38 | ||
39 | await doubleFollow(servers[0], servers[1]) | |
40 | }) | |
41 | ||
42 | it('Should not transcode video on server 1', async function () { | |
43 | this.timeout(60000) | |
44 | ||
45 | const videoAttributes = { | |
46 | name: 'my super name for server 1', | |
47 | description: 'my super description for server 1', | |
48 | fixture: 'video_short.webm' | |
49 | } | |
50 | await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) | |
51 | ||
52 | await waitJobs(servers) | |
53 | ||
54 | for (const server of servers) { | |
55 | const res = await getVideosList(server.url) | |
56 | const video = res.body.data[ 0 ] | |
57 | ||
58 | const res2 = await getVideo(server.url, video.id) | |
59 | const videoDetails = res2.body | |
60 | expect(videoDetails.files).to.have.lengthOf(1) | |
61 | ||
62 | const magnetUri = videoDetails.files[ 0 ].magnetUri | |
63 | expect(magnetUri).to.match(/\.webm/) | |
64 | ||
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 | } | |
70 | }) | |
71 | ||
72 | it('Should transcode video on server 2', async function () { | |
73 | this.timeout(60000) | |
74 | ||
75 | const videoAttributes = { | |
76 | name: 'my super name for server 2', | |
77 | description: 'my super description for server 2', | |
78 | fixture: 'video_short.webm' | |
79 | } | |
80 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) | |
81 | ||
82 | await waitJobs(servers) | |
83 | ||
84 | for (const server of servers) { | |
85 | const res = await getVideosList(server.url) | |
86 | ||
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 | |
90 | ||
91 | expect(videoDetails.files).to.have.lengthOf(4) | |
92 | ||
93 | const magnetUri = videoDetails.files[ 0 ].magnetUri | |
94 | expect(magnetUri).to.match(/\.mp4/) | |
95 | ||
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 | } | |
101 | }) | |
102 | ||
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 | ||
114 | for (const server of servers) { | |
115 | const res = await getVideosList(server.url) | |
116 | ||
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 | |
120 | ||
121 | expect(videoDetails.files).to.have.lengthOf(4) | |
122 | ||
123 | const path = join(root(), 'test2', 'videos', video.uuid + '-240.mp4') | |
124 | const probe = await audio.get(ffmpeg, path) | |
125 | ||
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 | } | |
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 | ||
146 | for (const server of servers) { | |
147 | const res = await getVideosList(server.url) | |
148 | ||
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 | |
152 | ||
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 | } | |
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 | ||
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 | } | |
189 | } | |
190 | }) | |
191 | ||
192 | it('Should transcode a 60 FPS video', async function () { | |
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', | |
198 | fixture: '60fps_720p_small.mp4' | |
199 | } | |
200 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) | |
201 | ||
202 | await waitJobs(servers) | |
203 | ||
204 | for (const server of servers) { | |
205 | const res = await getVideosList(server.url) | |
206 | ||
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 | |
210 | ||
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) | |
216 | ||
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) | |
220 | ||
221 | expect(fps).to.be.below(31) | |
222 | } | |
223 | ||
224 | const path = join(root(), 'test2', 'videos', video.uuid + '-720.mp4') | |
225 | const fps = await getVideoFileFPS(path) | |
226 | ||
227 | expect(fps).to.be.above(58).and.below(62) | |
228 | } | |
229 | }) | |
230 | ||
231 | it('Should wait transcoding before publishing the video', async function () { | |
232 | this.timeout(80000) | |
233 | ||
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) | |
253 | const videoToFindInMine = resMyVideos.body.data.find(v => v.name === videoAttributes.name) | |
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) | |
261 | const videoToFindInList = resVideos.body.data.find(v => v.name === videoAttributes.name) | |
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 | ||
268 | await waitJobs(servers) | |
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 | ||
284 | after(async function () { | |
285 | killallServers(servers) | |
286 | }) | |
287 | }) |