aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/videos/audio-only.ts
blob: 7ddbd5cd9c701736e04e6ed1c976711e30cbe73f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */

import 'mocha'
import * as chai from 'chai'
import { join } from 'path'
import { getAudioStream, getVideoStreamSize } from '@server/helpers/ffprobe-utils'
import {
  buildServerDirectory,
  cleanupTests,
  doubleFollow,
  flushAndRunMultipleServers,
  getVideo,
  ServerInfo,
  setAccessTokensToServers,
  uploadVideo,
  waitJobs
} from '../../../../shared/extra-utils'
import { VideoDetails } from '../../../../shared/models/videos'

const expect = chai.expect

describe('Test audio only video transcoding', function () {
  let servers: ServerInfo[] = []
  let videoUUID: string

  before(async function () {
    this.timeout(120000)

    const configOverride = {
      transcoding: {
        enabled: true,
        resolutions: {
          '0p': true,
          '240p': true,
          '360p': false,
          '480p': false,
          '720p': false,
          '1080p': false,
          '1440p': false,
          '2160p': false
        },
        hls: {
          enabled: true
        },
        webtorrent: {
          enabled: true
        }
      }
    }
    servers = await flushAndRunMultipleServers(2, configOverride)

    // Get the access tokens
    await setAccessTokensToServers(servers)

    // Server 1 and server 2 follow each other
    await doubleFollow(servers[0], servers[1])
  })

  it('Should upload a video and transcode it', async function () {
    this.timeout(120000)

    const resUpload = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'audio only' })
    videoUUID = resUpload.body.video.uuid

    await waitJobs(servers)

    for (const server of servers) {
      const res = await getVideo(server.url, videoUUID)
      const video: VideoDetails = res.body

      expect(video.streamingPlaylists).to.have.lengthOf(1)

      for (const files of [ video.files, video.streamingPlaylists[0].files ]) {
        expect(files).to.have.lengthOf(3)
        expect(files[0].resolution.id).to.equal(720)
        expect(files[1].resolution.id).to.equal(240)
        expect(files[2].resolution.id).to.equal(0)
      }
    }
  })

  it('0p transcoded video should not have video', async function () {
    const paths = [
      buildServerDirectory(servers[0], join('videos', videoUUID + '-0.mp4')),
      buildServerDirectory(servers[0], join('streaming-playlists', 'hls', videoUUID, videoUUID + '-0-fragmented.mp4'))
    ]

    for (const path of paths) {
      const { audioStream } = await getAudioStream(path)
      expect(audioStream['codec_name']).to.be.equal('aac')
      expect(audioStream['bit_rate']).to.be.at.most(384 * 8000)

      const size = await getVideoStreamSize(path)
      expect(size.height).to.equal(0)
      expect(size.width).to.equal(0)
    }
  })

  after(async function () {
    await cleanupTests(servers)
  })
})