1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
5 import { VideoDetails, VideoState } from '../../../../shared/models/videos'
6 import { getVideoFileFPS } from '../../../helpers/ffmpeg-utils'
9 flushAndRunMultipleServers,
16 setAccessTokensToServers,
20 import { join } from 'path'
21 import { waitJobs } from '../../utils/server/jobs'
23 const expect = chai.expect
25 describe('Test video transcoding', function () {
26 let servers: ServerInfo[] = []
28 before(async function () {
32 servers = await flushAndRunMultipleServers(2)
34 await setAccessTokensToServers(servers)
37 it('Should not transcode video on server 1', async function () {
40 const videoAttributes = {
41 name: 'my super name for server 1',
42 description: 'my super description for server 1',
43 fixture: 'video_short.webm'
45 await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
47 await waitJobs(servers)
49 const res = await getVideosList(servers[0].url)
50 const video = res.body.data[0]
52 const res2 = await getVideo(servers[0].url, video.id)
53 const videoDetails = res2.body
54 expect(videoDetails.files).to.have.lengthOf(1)
56 const magnetUri = videoDetails.files[0].magnetUri
57 expect(magnetUri).to.match(/\.webm/)
59 const torrent = await webtorrentAdd(magnetUri)
60 expect(torrent.files).to.be.an('array')
61 expect(torrent.files.length).to.equal(1)
62 expect(torrent.files[0].path).match(/\.webm$/)
65 it('Should transcode video on server 2', async function () {
68 const videoAttributes = {
69 name: 'my super name for server 2',
70 description: 'my super description for server 2',
71 fixture: 'video_short.webm'
73 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes)
75 await waitJobs(servers)
77 const res = await getVideosList(servers[1].url)
79 const video = res.body.data[0]
80 const res2 = await getVideo(servers[1].url, video.id)
81 const videoDetails = res2.body
83 expect(videoDetails.files).to.have.lengthOf(4)
85 const magnetUri = videoDetails.files[0].magnetUri
86 expect(magnetUri).to.match(/\.mp4/)
88 const torrent = await webtorrentAdd(magnetUri)
89 expect(torrent.files).to.be.an('array')
90 expect(torrent.files.length).to.equal(1)
91 expect(torrent.files[0].path).match(/\.mp4$/)
94 it('Should transcode to 30 FPS', async function () {
97 const videoAttributes = {
98 name: 'my super 30fps name for server 2',
99 description: 'my super 30fps description for server 2',
100 fixture: 'video_60fps_short.mp4'
102 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes)
104 await waitJobs(servers)
106 const res = await getVideosList(servers[1].url)
108 const video = res.body.data[0]
109 const res2 = await getVideo(servers[1].url, video.id)
110 const videoDetails: VideoDetails = res2.body
112 expect(videoDetails.files).to.have.lengthOf(1)
114 for (const resolution of [ '240' ]) {
115 const path = join(root(), 'test2', 'videos', video.uuid + '-' + resolution + '.mp4')
116 const fps = await getVideoFileFPS(path)
118 expect(fps).to.be.below(31)
122 it('Should wait transcoding before publishing the video', async function () {
125 await doubleFollow(servers[0], servers[1])
127 await waitJobs(servers)
130 // Upload the video, but wait transcoding
131 const videoAttributes = {
132 name: 'waiting video',
133 fixture: 'video_short1.webm',
134 waitTranscoding: true
136 const resVideo = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, videoAttributes)
137 const videoId = resVideo.body.video.uuid
139 // Should be in transcode state
140 const { body } = await getVideo(servers[ 1 ].url, videoId)
141 expect(body.name).to.equal('waiting video')
142 expect(body.state.id).to.equal(VideoState.TO_TRANSCODE)
143 expect(body.state.label).to.equal('To transcode')
144 expect(body.waitTranscoding).to.be.true
146 // Should have my video
147 const resMyVideos = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 10)
148 const videoToFindInMine = resMyVideos.body.data.find(v => v.name === 'waiting video')
149 expect(videoToFindInMine).not.to.be.undefined
150 expect(videoToFindInMine.state.id).to.equal(VideoState.TO_TRANSCODE)
151 expect(videoToFindInMine.state.label).to.equal('To transcode')
152 expect(videoToFindInMine.waitTranscoding).to.be.true
154 // Should not list this video
155 const resVideos = await getVideosList(servers[1].url)
156 const videoToFindInList = resVideos.body.data.find(v => v.name === 'waiting video')
157 expect(videoToFindInList).to.be.undefined
159 // Server 1 should not have the video yet
160 await getVideo(servers[0].url, videoId, 404)
163 await waitJobs(servers)
165 for (const server of servers) {
166 const res = await getVideosList(server.url)
167 const videoToFind = res.body.data.find(v => v.name === 'waiting video')
168 expect(videoToFind).not.to.be.undefined
170 const res2 = await getVideo(server.url, videoToFind.id)
171 const videoDetails: VideoDetails = res2.body
173 expect(videoDetails.state.id).to.equal(VideoState.PUBLISHED)
174 expect(videoDetails.state.label).to.equal('Published')
175 expect(videoDetails.waitTranscoding).to.be.true
179 after(async function () {
180 killallServers(servers)