PeerTube/server/tests/api/transcoding/audio-only.ts

105 lines
2.9 KiB
TypeScript
Raw Normal View History

2020-01-31 09:56:52 -06:00
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2019-11-22 04:43:17 -06:00
2022-08-17 08:44:32 -05:00
import { expect } from 'chai'
2023-04-21 08:00:01 -05:00
import { getAudioStream, getVideoStreamDimensionsInfo } from '@shared/ffmpeg'
import {
cleanupTests,
createMultipleServers,
doubleFollow,
PeerTubeServer,
setAccessTokensToServers,
waitJobs
} from '@shared/server-commands'
2019-11-22 04:43:17 -06:00
describe('Test audio only video transcoding', function () {
2021-07-16 02:47:51 -05:00
let servers: PeerTubeServer[] = []
2019-11-22 04:43:17 -06:00
let videoUUID: string
let webVideoAudioFileUrl: string
2021-07-22 07:28:03 -05:00
let fragmentedAudioFileUrl: string
2019-11-22 04:43:17 -06:00
before(async function () {
this.timeout(120000)
const configOverride = {
transcoding: {
enabled: true,
resolutions: {
'0p': true,
'144p': false,
2019-11-22 04:43:17 -06:00
'240p': true,
'360p': false,
'480p': false,
'720p': false,
'1080p': false,
'1440p': false,
2019-11-22 04:43:17 -06:00
'2160p': false
},
hls: {
enabled: true
},
2023-07-11 02:52:14 -05:00
web_videos: {
2019-11-22 04:43:17 -06:00
enabled: true
}
}
}
2021-07-16 02:47:51 -05:00
servers = await createMultipleServers(2, configOverride)
2019-11-22 04:43:17 -06:00
// 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)
2021-07-16 02:04:35 -05:00
const { uuid } = await servers[0].videos.upload({ attributes: { name: 'audio only' } })
2021-07-15 03:02:54 -05:00
videoUUID = uuid
2019-11-22 04:43:17 -06:00
await waitJobs(servers)
for (const server of servers) {
2021-07-16 02:04:35 -05:00
const video = await server.videos.get({ id: videoUUID })
2019-11-22 04:43:17 -06:00
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)
}
2021-07-22 07:28:03 -05:00
if (server.serverNumber === 1) {
webVideoAudioFileUrl = video.files[2].fileUrl
2021-07-22 07:28:03 -05:00
fragmentedAudioFileUrl = video.streamingPlaylists[0].files[2].fileUrl
}
2019-11-22 04:43:17 -06:00
}
})
it('0p transcoded video should not have video', async function () {
const paths = [
servers[0].servers.buildWebVideoFilePath(webVideoAudioFileUrl),
2021-07-22 07:28:03 -05:00
servers[0].servers.buildFragmentedFilePath(videoUUID, fragmentedAudioFileUrl)
2019-11-22 04:43:17 -06:00
]
for (const path of paths) {
2020-11-20 10:16:55 -06:00
const { audioStream } = await getAudioStream(path)
2020-01-31 09:56:52 -06:00
expect(audioStream['codec_name']).to.be.equal('aac')
expect(audioStream['bit_rate']).to.be.at.most(384 * 8000)
2019-11-22 04:43:17 -06:00
2022-02-11 03:51:33 -06:00
const size = await getVideoStreamDimensionsInfo(path)
2022-11-14 07:34:22 -06:00
expect(size.height).to.equal(0)
expect(size.width).to.equal(0)
expect(size.isPortraitMode).to.be.false
expect(size.ratio).to.equal(0)
expect(size.resolution).to.equal(0)
2019-11-22 04:43:17 -06:00
}
})
after(async function () {
await cleanupTests(servers)
})
})