]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/videos/audio-only.ts
shared/ typescript types dir server-commands
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / audio-only.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4 import * as chai from 'chai'
5 import { getAudioStream, getVideoStreamSize } from '@server/helpers/ffprobe-utils'
6 import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/server-commands'
7
8 const expect = chai.expect
9
10 describe('Test audio only video transcoding', function () {
11 let servers: PeerTubeServer[] = []
12 let videoUUID: string
13 let webtorrentAudioFileUrl: string
14 let fragmentedAudioFileUrl: string
15
16 before(async function () {
17 this.timeout(120000)
18
19 const configOverride = {
20 transcoding: {
21 enabled: true,
22 resolutions: {
23 '0p': true,
24 '144p': false,
25 '240p': true,
26 '360p': false,
27 '480p': false,
28 '720p': false,
29 '1080p': false,
30 '1440p': false,
31 '2160p': false
32 },
33 hls: {
34 enabled: true
35 },
36 webtorrent: {
37 enabled: true
38 }
39 }
40 }
41 servers = await createMultipleServers(2, configOverride)
42
43 // Get the access tokens
44 await setAccessTokensToServers(servers)
45
46 // Server 1 and server 2 follow each other
47 await doubleFollow(servers[0], servers[1])
48 })
49
50 it('Should upload a video and transcode it', async function () {
51 this.timeout(120000)
52
53 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'audio only' } })
54 videoUUID = uuid
55
56 await waitJobs(servers)
57
58 for (const server of servers) {
59 const video = await server.videos.get({ id: videoUUID })
60 expect(video.streamingPlaylists).to.have.lengthOf(1)
61
62 for (const files of [ video.files, video.streamingPlaylists[0].files ]) {
63 expect(files).to.have.lengthOf(3)
64 expect(files[0].resolution.id).to.equal(720)
65 expect(files[1].resolution.id).to.equal(240)
66 expect(files[2].resolution.id).to.equal(0)
67 }
68
69 if (server.serverNumber === 1) {
70 webtorrentAudioFileUrl = video.files[2].fileUrl
71 fragmentedAudioFileUrl = video.streamingPlaylists[0].files[2].fileUrl
72 }
73 }
74 })
75
76 it('0p transcoded video should not have video', async function () {
77 const paths = [
78 servers[0].servers.buildWebTorrentFilePath(webtorrentAudioFileUrl),
79 servers[0].servers.buildFragmentedFilePath(videoUUID, fragmentedAudioFileUrl)
80 ]
81
82 for (const path of paths) {
83 const { audioStream } = await getAudioStream(path)
84 expect(audioStream['codec_name']).to.be.equal('aac')
85 expect(audioStream['bit_rate']).to.be.at.most(384 * 8000)
86
87 const size = await getVideoStreamSize(path)
88 expect(size.height).to.equal(0)
89 expect(size.width).to.equal(0)
90 }
91 })
92
93 after(async function () {
94 await cleanupTests(servers)
95 })
96 })