]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/videos/audio-only.ts
Merge branch 'checkbox-input-plugin' into 'develop'
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / audio-only.ts
CommitLineData
3a149e9f
C
1/* tslint:disable:no-unused-expression */
2
3import * as chai from 'chai'
4import 'mocha'
5import {
6 checkDirectoryIsEmpty,
7 checkSegmentHash,
8 checkTmpIsEmpty,
9 cleanupTests,
10 doubleFollow,
11 flushAndRunMultipleServers,
12 getPlaylist,
13 getVideo, makeGetRequest, makeRawRequest,
14 removeVideo, root,
15 ServerInfo,
16 setAccessTokensToServers, updateCustomSubConfig,
17 updateVideo,
18 uploadVideo,
19 waitJobs, webtorrentAdd
20} from '../../../../shared/extra-utils'
21import { VideoDetails } from '../../../../shared/models/videos'
22import { VideoStreamingPlaylistType } from '../../../../shared/models/videos/video-streaming-playlist.type'
23import { join } from 'path'
24import { DEFAULT_AUDIO_RESOLUTION } from '../../../initializers/constants'
25import { getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution, audio, getVideoFileSize } from '@server/helpers/ffmpeg-utils'
26
27const expect = chai.expect
28
29describe('Test audio only video transcoding', function () {
30 let servers: ServerInfo[] = []
31 let videoUUID: string
32
33 before(async function () {
34 this.timeout(120000)
35
36 const configOverride = {
37 transcoding: {
38 enabled: true,
39 resolutions: {
40 '0p': true,
41 '240p': true,
42 '360p': false,
43 '480p': false,
44 '720p': false,
45 '1080p': false,
46 '2160p': false
47 },
48 hls: {
49 enabled: true
50 },
51 webtorrent: {
52 enabled: true
53 }
54 }
55 }
56 servers = await flushAndRunMultipleServers(2, configOverride)
57
58 // Get the access tokens
59 await setAccessTokensToServers(servers)
60
61 // Server 1 and server 2 follow each other
62 await doubleFollow(servers[0], servers[1])
63 })
64
65 it('Should upload a video and transcode it', async function () {
66 this.timeout(120000)
67
68 const resUpload = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'audio only'})
69 videoUUID = resUpload.body.video.uuid
70
71 await waitJobs(servers)
72
73 for (const server of servers) {
74 const res = await getVideo(server.url, videoUUID)
75 const video: VideoDetails = res.body
76
77 expect(video.streamingPlaylists).to.have.lengthOf(1)
78
79 for (const files of [ video.files, video.streamingPlaylists[0].files ]) {
80 expect(files).to.have.lengthOf(3)
81 expect(files[0].resolution.id).to.equal(720)
82 expect(files[1].resolution.id).to.equal(240)
83 expect(files[2].resolution.id).to.equal(0)
84 }
85 }
86 })
87
88 it('0p transcoded video should not have video', async function () {
89 const paths = [
90 join(root(), 'test' + servers[ 0 ].internalServerNumber, 'videos', videoUUID + '-0.mp4'),
91 join(root(), 'test' + servers[ 0 ].internalServerNumber, 'streaming-playlists', 'hls', videoUUID, videoUUID + '-0-fragmented.mp4')
92 ]
93
94 for (const path of paths) {
95 const { audioStream } = await audio.get(path)
96 expect(audioStream[ 'codec_name' ]).to.be.equal('aac')
97 expect(audioStream[ 'bit_rate' ]).to.be.at.most(384 * 8000)
98
99 const size = await getVideoFileSize(path)
100 expect(size.height).to.equal(0)
101 expect(size.width).to.equal(0)
102 }
103 })
104
105 after(async function () {
106 await cleanupTests(servers)
107 })
108})