// Constrained Encoding (VBV)
// https://slhck.info/video/2017/03/01/rate-control.html
// https://trac.ffmpeg.org/wiki/Limiting%20the%20output%20bitrate
- const targetBitrate = getTargetBitrate(resolution, fps, VIDEO_TRANSCODING_FPS)
+ let targetBitrate = getTargetBitrate(resolution, fps, VIDEO_TRANSCODING_FPS)
+
+ // Don't transcode to an higher bitrate than the original file
+ const fileBitrate = await getVideoFileBitrate(input)
+ targetBitrate = Math.min(targetBitrate, fileBitrate)
+
localCommand = localCommand.outputOptions([ `-maxrate ${targetBitrate}`, `-bufsize ${targetBitrate * 2}` ])
// Keyframe interval of 2 seconds for faster seeking and resolution switching.
generateHighBitrateVideo,
generateVideoWithFramerate,
getMyVideos,
+ getServerFileSize,
getVideo,
getVideoFileMetadataUrl,
getVideosList,
root,
ServerInfo,
setAccessTokensToServers,
+ updateCustomSubConfig,
uploadVideo, uploadVideoAndGetId,
waitJobs,
webtorrentAdd
}
})
+ it('Should not transcode to an higher bitrate than the original file', async function () {
+ this.timeout(160000)
+
+ const config = {
+ transcoding: {
+ enabled: true,
+ resolutions: {
+ '240p': true,
+ '360p': true,
+ '480p': true,
+ '720p': true,
+ '1080p': true
+ },
+ webtorrent: { enabled: true },
+ hls: { enabled: true }
+ }
+ }
+ await updateCustomSubConfig(servers[1].url, servers[1].accessToken, config)
+
+ const videoAttributes = {
+ name: 'low bitrate',
+ fixture: 'low-bitrate.mp4'
+ }
+
+ const resUpload = await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes)
+ const videoUUID = resUpload.body.video.uuid
+
+ await waitJobs(servers)
+
+ const resolutions = [ 240, 360, 480, 720, 1080 ]
+ for (const r of resolutions) {
+ expect(await getServerFileSize(servers[1], `videos/${videoUUID}-${r}.mp4`)).to.be.below(43)
+ }
+ })
+
it('Should provide valid ffprobe data', async function () {
this.timeout(160000)
import { basename, dirname, isAbsolute, join, resolve } from 'path'
import * as request from 'supertest'
import * as WebTorrent from 'webtorrent'
-import { ensureDir, pathExists, readFile } from 'fs-extra'
+import { ensureDir, pathExists, readFile, stat } from 'fs-extra'
import * as ffmpeg from 'fluent-ffmpeg'
const expect = chai.expect
return tempFixturePath
}
+async function getFileSize (path: string) {
+ const stats = await stat(path)
+
+ return stats.size
+}
+
// ---------------------------------------------------------------------------
export {
areHttpImportTestsDisabled,
buildServerDirectory,
webtorrentAdd,
+ getFileSize,
immutableAssign,
testImage,
buildAbsoluteFixturePath,
import { join } from 'path'
import { randomInt } from '../../core-utils/miscs/miscs'
import { VideoChannel } from '../../models/videos'
-import { root, wait } from '../miscs/miscs'
+import { getFileSize, root, wait } from '../miscs/miscs'
interface ServerInfo {
app: ChildProcess
}
}
+async function getServerFileSize (server: ServerInfo, subPath: string) {
+ const path = join(root(), 'test' + server.internalServerNumber, subPath)
+
+ return getFileSize(path)
+}
+
// ---------------------------------------------------------------------------
export {
checkDirectoryIsEmpty,
checkTmpIsEmpty,
+ getServerFileSize,
ServerInfo,
parallelTests,
cleanupTests,