1
0
Fork 0

Added 144p encoding (#4492)

* Added 144p encoding

Implements https://github.com/Chocobozzz/PeerTube/issues/4428

* Fixed typo in core-utils

* Increased BitPerPixel for 144p

* Disabled 144p by default in test.yaml

* Another try at fixing tests

* Fixed test in video-transcoder (api-3)

* Fixed test in video-imports (api-4)

* Fixed test in live-constraints (api-2)

* Tried to fix tests in api-3 again

* Revert "Tried to fix tests in api-3 again"

This reverts commit 266e1143fa37f333d149c2c2791c7bd33621ac14.

* Fixed test in config.ts (api-2)

* Try to fix test in video-hls.ts (api-3)

* Fixed test in video-transcoder.ts (api-3)

* Fix tests

Co-authored-by: Chocobozzz <me@florianbigard.com>
This commit is contained in:
Florian CUNY 2021-11-05 10:23:02 +01:00 committed by GitHub
parent dd6d2a7ce5
commit 8dd754c767
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 74 additions and 23 deletions

View file

@ -17,6 +17,10 @@ export class EditConfigurationService {
label: $localize`Audio-only`,
description: $localize`A <code>.mp4</code> that keeps the original audio track, with no video`
},
{
id: '144p',
label: $localize`144p`
},
{
id: '240p',
label: $localize`240p`

View file

@ -323,6 +323,7 @@ transcoding:
resolutions: # Only created if the original video has a higher resolution, uses more storage!
0p: false # audio-only (creates mp4 without video stream, always created when enabled)
144p: false
240p: false
360p: false
480p: false
@ -382,6 +383,7 @@ live:
profile: 'default'
resolutions:
144p: false
240p: false
360p: false
480p: false

View file

@ -333,6 +333,7 @@ transcoding:
resolutions: # Only created if the original video has a higher resolution, uses more storage!
0p: false # audio-only (creates mp4 without video stream, always created when enabled)
144p: false
240p: false
360p: false
480p: false
@ -392,6 +393,7 @@ live:
profile: 'default'
resolutions:
144p: false
240p: false
360p: false
480p: false

View file

@ -80,6 +80,7 @@ transcoding:
concurrency: 2
resolutions:
0p: false
144p: false
240p: true
360p: true
480p: true
@ -105,6 +106,7 @@ live:
threads: 2
resolutions:
144p: false
240p: false
360p: false
480p: false

View file

@ -208,6 +208,7 @@ function customConfig (): CustomConfig {
profile: CONFIG.TRANSCODING.PROFILE,
resolutions: {
'0p': CONFIG.TRANSCODING.RESOLUTIONS['0p'],
'144p': CONFIG.TRANSCODING.RESOLUTIONS['144p'],
'240p': CONFIG.TRANSCODING.RESOLUTIONS['240p'],
'360p': CONFIG.TRANSCODING.RESOLUTIONS['360p'],
'480p': CONFIG.TRANSCODING.RESOLUTIONS['480p'],
@ -234,6 +235,7 @@ function customConfig (): CustomConfig {
threads: CONFIG.LIVE.TRANSCODING.THREADS,
profile: CONFIG.LIVE.TRANSCODING.PROFILE,
resolutions: {
'144p': CONFIG.LIVE.TRANSCODING.RESOLUTIONS['144p'],
'240p': CONFIG.LIVE.TRANSCODING.RESOLUTIONS['240p'],
'360p': CONFIG.LIVE.TRANSCODING.RESOLUTIONS['360p'],
'480p': CONFIG.LIVE.TRANSCODING.RESOLUTIONS['480p'],

View file

@ -220,6 +220,7 @@ function computeResolutionsToTranscode (videoFileResolution: number, type: 'vod'
VideoResolution.H_360P,
VideoResolution.H_720P,
VideoResolution.H_240P,
VideoResolution.H_144P,
VideoResolution.H_1080P,
VideoResolution.H_1440P,
VideoResolution.H_4K

View file

@ -28,8 +28,9 @@ function checkMissedConfig () {
'redundancy.videos.strategies', 'redundancy.videos.check_interval',
'transcoding.enabled', 'transcoding.threads', 'transcoding.allow_additional_extensions', 'transcoding.hls.enabled',
'transcoding.profile', 'transcoding.concurrency',
'transcoding.resolutions.0p', 'transcoding.resolutions.240p', 'transcoding.resolutions.360p', 'transcoding.resolutions.480p',
'transcoding.resolutions.720p', 'transcoding.resolutions.1080p', 'transcoding.resolutions.1440p', 'transcoding.resolutions.2160p',
'transcoding.resolutions.0p', 'transcoding.resolutions.144p', 'transcoding.resolutions.240p', 'transcoding.resolutions.360p',
'transcoding.resolutions.480p', 'transcoding.resolutions.720p', 'transcoding.resolutions.1080p', 'transcoding.resolutions.1440p',
'transcoding.resolutions.2160p',
'import.videos.http.enabled', 'import.videos.torrent.enabled', 'import.videos.concurrency', 'auto_blacklist.videos.of_users.enabled',
'trending.videos.interval_days',
'instance.name', 'instance.short_description', 'instance.description', 'instance.terms', 'instance.default_client_route',
@ -47,9 +48,9 @@ function checkMissedConfig () {
'search.search_index.disable_local_search', 'search.search_index.is_default_search',
'live.enabled', 'live.allow_replay', 'live.max_duration', 'live.max_user_lives', 'live.max_instance_lives',
'live.transcoding.enabled', 'live.transcoding.threads', 'live.transcoding.profile',
'live.transcoding.resolutions.240p', 'live.transcoding.resolutions.360p', 'live.transcoding.resolutions.480p',
'live.transcoding.resolutions.720p', 'live.transcoding.resolutions.1080p', 'live.transcoding.resolutions.1440p',
'live.transcoding.resolutions.2160p'
'live.transcoding.resolutions.144p', 'live.transcoding.resolutions.240p', 'live.transcoding.resolutions.360p',
'live.transcoding.resolutions.480p', 'live.transcoding.resolutions.720p', 'live.transcoding.resolutions.1080p',
'live.transcoding.resolutions.1440p', 'live.transcoding.resolutions.2160p'
]
const requiredAlternatives = [

View file

@ -245,6 +245,7 @@ const CONFIG = {
get PROFILE () { return config.get<string>('transcoding.profile') },
RESOLUTIONS: {
get '0p' () { return config.get<boolean>('transcoding.resolutions.0p') },
get '144p' () { return config.get<boolean>('transcoding.resolutions.144p') },
get '240p' () { return config.get<boolean>('transcoding.resolutions.240p') },
get '360p' () { return config.get<boolean>('transcoding.resolutions.360p') },
get '480p' () { return config.get<boolean>('transcoding.resolutions.480p') },
@ -279,6 +280,7 @@ const CONFIG = {
get PROFILE () { return config.get<string>('live.transcoding.profile') },
RESOLUTIONS: {
get '144p' () { return config.get<boolean>('live.transcoding.resolutions.144p') },
get '240p' () { return config.get<boolean>('live.transcoding.resolutions.240p') },
get '360p' () { return config.get<boolean>('live.transcoding.resolutions.360p') },
get '480p' () { return config.get<boolean>('live.transcoding.resolutions.480p') },

View file

@ -45,6 +45,7 @@ const customConfigUpdateValidator = [
body('transcoding.threads').isInt().withMessage('Should have a valid transcoding threads number'),
body('transcoding.concurrency').isInt({ min: 1 }).withMessage('Should have a valid transcoding concurrency number'),
body('transcoding.resolutions.0p').isBoolean().withMessage('Should have a valid transcoding 0p resolution enabled boolean'),
body('transcoding.resolutions.144p').isBoolean().withMessage('Should have a valid transcoding 144p resolution enabled boolean'),
body('transcoding.resolutions.240p').isBoolean().withMessage('Should have a valid transcoding 240p resolution enabled boolean'),
body('transcoding.resolutions.360p').isBoolean().withMessage('Should have a valid transcoding 360p resolution enabled boolean'),
body('transcoding.resolutions.480p').isBoolean().withMessage('Should have a valid transcoding 480p resolution enabled boolean'),
@ -80,6 +81,7 @@ const customConfigUpdateValidator = [
body('live.maxUserLives').custom(isIntOrNull).withMessage('Should have a valid max user lives'),
body('live.transcoding.enabled').isBoolean().withMessage('Should have a valid live transcoding enabled boolean'),
body('live.transcoding.threads').isInt().withMessage('Should have a valid live transcoding threads'),
body('live.transcoding.resolutions.144p').isBoolean().withMessage('Should have a valid transcoding 144p resolution enabled boolean'),
body('live.transcoding.resolutions.240p').isBoolean().withMessage('Should have a valid transcoding 240p resolution enabled boolean'),
body('live.transcoding.resolutions.360p').isBoolean().withMessage('Should have a valid transcoding 360p resolution enabled boolean'),
body('live.transcoding.resolutions.480p').isBoolean().withMessage('Should have a valid transcoding 480p resolution enabled boolean'),

View file

@ -93,6 +93,7 @@ describe('Test config API validators', function () {
profile: 'vod_profile',
resolutions: {
'0p': false,
'144p': false,
'240p': false,
'360p': true,
'480p': true,
@ -121,6 +122,7 @@ describe('Test config API validators', function () {
threads: 4,
profile: 'live_profile',
resolutions: {
'144p': true,
'240p': true,
'360p': true,
'480p': true,

View file

@ -168,7 +168,7 @@ describe('Test live constraints', function () {
await waitUntilLivePublishedOnAllServers(userVideoLiveoId)
await waitJobs(servers)
await checkSaveReplay(userVideoLiveoId, [ 720, 480, 360, 240 ])
await checkSaveReplay(userVideoLiveoId, [ 720, 480, 360, 240, 144 ])
})
after(async function () {

View file

@ -421,6 +421,7 @@ describe('Test live', function () {
transcoding: {
enabled: true,
resolutions: {
'144p': resolutions.includes(144),
'240p': resolutions.includes(240),
'360p': resolutions.includes(360),
'480p': resolutions.includes(480),

View file

@ -123,7 +123,7 @@ describe('Object storage for lives', function () {
expect(video.streamingPlaylists).to.have.lengthOf(1)
const files = video.streamingPlaylists[0].files
expect(files).to.have.lengthOf(4)
expect(files).to.have.lengthOf(5)
await checkFiles(files)
}

View file

@ -88,9 +88,9 @@ describe('Object storage for video import', function () {
const video = await server.videos.get({ id: uuid })
expect(video.files).to.have.lengthOf(4)
expect(video.files).to.have.lengthOf(5)
expect(video.streamingPlaylists).to.have.lengthOf(1)
expect(video.streamingPlaylists[0].files).to.have.lengthOf(4)
expect(video.streamingPlaylists[0].files).to.have.lengthOf(5)
for (const file of video.files) {
expectStartWith(file.fileUrl, ObjectStorageCommand.getWebTorrentBaseUrl())

View file

@ -66,6 +66,7 @@ function checkInitialConfig (server: PeerTubeServer, data: CustomConfig) {
expect(data.transcoding.threads).to.equal(2)
expect(data.transcoding.concurrency).to.equal(2)
expect(data.transcoding.profile).to.equal('default')
expect(data.transcoding.resolutions['144p']).to.be.false
expect(data.transcoding.resolutions['240p']).to.be.true
expect(data.transcoding.resolutions['360p']).to.be.true
expect(data.transcoding.resolutions['480p']).to.be.true
@ -84,6 +85,7 @@ function checkInitialConfig (server: PeerTubeServer, data: CustomConfig) {
expect(data.live.transcoding.enabled).to.be.false
expect(data.live.transcoding.threads).to.equal(2)
expect(data.live.transcoding.profile).to.equal('default')
expect(data.live.transcoding.resolutions['144p']).to.be.false
expect(data.live.transcoding.resolutions['240p']).to.be.false
expect(data.live.transcoding.resolutions['360p']).to.be.false
expect(data.live.transcoding.resolutions['480p']).to.be.false
@ -163,6 +165,7 @@ function checkUpdatedConfig (data: CustomConfig) {
expect(data.transcoding.allowAdditionalExtensions).to.be.true
expect(data.transcoding.allowAudioFiles).to.be.true
expect(data.transcoding.profile).to.equal('vod_profile')
expect(data.transcoding.resolutions['144p']).to.be.false
expect(data.transcoding.resolutions['240p']).to.be.false
expect(data.transcoding.resolutions['360p']).to.be.true
expect(data.transcoding.resolutions['480p']).to.be.true
@ -180,6 +183,7 @@ function checkUpdatedConfig (data: CustomConfig) {
expect(data.live.transcoding.enabled).to.be.true
expect(data.live.transcoding.threads).to.equal(4)
expect(data.live.transcoding.profile).to.equal('live_profile')
expect(data.live.transcoding.resolutions['144p']).to.be.true
expect(data.live.transcoding.resolutions['240p']).to.be.true
expect(data.live.transcoding.resolutions['360p']).to.be.true
expect(data.live.transcoding.resolutions['480p']).to.be.true
@ -281,6 +285,7 @@ const newCustomConfig: CustomConfig = {
profile: 'vod_profile',
resolutions: {
'0p': false,
'144p': false,
'240p': false,
'360p': true,
'480p': true,
@ -307,6 +312,7 @@ const newCustomConfig: CustomConfig = {
threads: 4,
profile: 'live_profile',
resolutions: {
'144p': true,
'240p': true,
'360p': true,
'480p': true,

View file

@ -198,6 +198,7 @@ describe('Test stats (excluding redundancy)', function () {
},
resolutions: {
'0p': false,
'144p': false,
'240p': false,
'360p': false,
'480p': false,

View file

@ -21,6 +21,7 @@ describe('Test audio only video transcoding', function () {
enabled: true,
resolutions: {
'0p': true,
'144p': false,
'240p': true,
'360p': false,
'480p': false,

View file

@ -243,6 +243,7 @@ describe('Test HLS videos', function () {
enabled: true,
allowAudioFiles: true,
resolutions: {
'144p': false,
'240p': true,
'360p': true,
'480p': true,

View file

@ -300,6 +300,7 @@ describe('Test video imports', function () {
transcoding: {
enabled: true,
resolutions: {
'144p': true,
'240p': true,
'360p': false,
'480p': false,

View file

@ -40,6 +40,7 @@ function updateConfigForTranscoding (server: PeerTubeServer) {
webtorrent: { enabled: true },
resolutions: {
'0p': false,
'144p': true,
'240p': true,
'360p': true,
'480p': true,
@ -119,7 +120,7 @@ describe('Test video transcoding', function () {
const video = data.find(v => v.name === attributes.name)
const videoDetails = await server.videos.get({ id: video.id })
expect(videoDetails.files).to.have.lengthOf(4)
expect(videoDetails.files).to.have.lengthOf(5)
const magnetUri = videoDetails.files[0].magnetUri
expect(magnetUri).to.match(/\.mp4/)
@ -205,7 +206,7 @@ describe('Test video transcoding', function () {
const video = data.find(v => v.name === attributes.name)
const videoDetails = await server.videos.get({ id: video.id })
expect(videoDetails.files).to.have.lengthOf(4)
expect(videoDetails.files).to.have.lengthOf(5)
const magnetUri = videoDetails.files[0].magnetUri
expect(magnetUri).to.contain('.mp4')
@ -226,7 +227,7 @@ describe('Test video transcoding', function () {
await waitJobs(servers)
const resolutions = [ 240, 360, 480, 720, 1080, 1440, 2160 ]
const resolutions = [ 144, 240, 360, 480, 720, 1080, 1440, 2160 ]
for (const server of servers) {
const videoDetails = await server.videos.get({ id: video4k })
@ -259,7 +260,7 @@ describe('Test video transcoding', function () {
const video = data.find(v => v.name === attributes.name)
const videoDetails = await server.videos.get({ id: video.id })
expect(videoDetails.files).to.have.lengthOf(4)
expect(videoDetails.files).to.have.lengthOf(5)
const file = videoDetails.files.find(f => f.resolution.id === 240)
const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
@ -316,7 +317,7 @@ describe('Test video transcoding', function () {
const video = data.find(v => v.name === attributes.name)
const videoDetails = await server.videos.get({ id: video.id })
expect(videoDetails.files).to.have.lengthOf(4)
expect(videoDetails.files).to.have.lengthOf(5)
const fixturePath = buildAbsoluteFixturePath(attributes.fixture)
const fixtureVideoProbe = await getAudioStream(fixturePath)
@ -348,6 +349,7 @@ describe('Test video transcoding', function () {
webtorrent: { enabled: true },
resolutions: {
'0p': false,
'144p': false,
'240p': false,
'360p': false,
'480p': false,
@ -419,6 +421,7 @@ describe('Test video transcoding', function () {
webtorrent: { enabled: true },
resolutions: {
'0p': true,
'144p': false,
'240p': false,
'360p': false
}
@ -473,13 +476,14 @@ describe('Test video transcoding', function () {
const video = data.find(v => v.name === attributes.name)
const videoDetails = await server.videos.get({ id: video.id })
expect(videoDetails.files).to.have.lengthOf(4)
expect(videoDetails.files).to.have.lengthOf(5)
expect(videoDetails.files[0].fps).to.be.above(58).and.below(62)
expect(videoDetails.files[1].fps).to.be.below(31)
expect(videoDetails.files[2].fps).to.be.below(31)
expect(videoDetails.files[3].fps).to.be.below(31)
expect(videoDetails.files[4].fps).to.be.below(31)
for (const resolution of [ 240, 360, 480 ]) {
for (const resolution of [ 144, 240, 360, 480 ]) {
const file = videoDetails.files.find(f => f.resolution.id === resolution)
const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
const fps = await getVideoFileFPS(path)
@ -586,6 +590,7 @@ describe('Test video transcoding', function () {
transcoding: {
enabled: true,
resolutions: {
'144p': true,
'240p': true,
'360p': true,
'480p': true,
@ -667,7 +672,7 @@ describe('Test video transcoding', function () {
const videoFiles = videoDetails.files
.concat(videoDetails.streamingPlaylists[0].files)
expect(videoFiles).to.have.lengthOf(8)
expect(videoFiles).to.have.lengthOf(10)
for (const file of videoFiles) {
expect(file.metadata).to.be.undefined
@ -695,21 +700,21 @@ describe('Test video transcoding', function () {
const body = await servers[1].jobs.list({
start: 0,
count: 100,
sort: '-createdAt',
sort: 'createdAt',
jobType: 'video-transcoding'
})
const jobs = body.data
const transcodingJobs = jobs.filter(j => j.data.videoUUID === video4k)
expect(transcodingJobs).to.have.lengthOf(14)
expect(transcodingJobs).to.have.lengthOf(16)
const hlsJobs = transcodingJobs.filter(j => j.data.type === 'new-resolution-to-hls')
const webtorrentJobs = transcodingJobs.filter(j => j.data.type === 'new-resolution-to-webtorrent')
const optimizeJobs = transcodingJobs.filter(j => j.data.type === 'optimize-to-webtorrent')
expect(hlsJobs).to.have.lengthOf(7)
expect(webtorrentJobs).to.have.lengthOf(6)
expect(hlsJobs).to.have.lengthOf(8)
expect(webtorrentJobs).to.have.lengthOf(7)
expect(optimizeJobs).to.have.lengthOf(1)
for (const j of optimizeJobs.concat(hlsJobs.concat(webtorrentJobs))) {

View file

@ -220,9 +220,9 @@ function runTests (objectStorage: boolean) {
for (const server of servers) {
const videoDetails = await server.videos.get({ id: videosUUID[4] })
expect(videoDetails.files).to.have.lengthOf(4)
expect(videoDetails.files).to.have.lengthOf(5)
expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(4)
expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(5)
if (objectStorage) {
await checkFilesInObjectStorage(videoDetails.files, 'webtorrent')

View file

@ -104,6 +104,7 @@ describe('Bitrate', function () {
it('Should get appropriate max bitrate', function () {
const tests = [
{ resolution: VideoResolution.H_144P, ratio: 16 / 9, fps: 24, min: 200, max: 400 },
{ resolution: VideoResolution.H_240P, ratio: 16 / 9, fps: 24, min: 600, max: 800 },
{ resolution: VideoResolution.H_360P, ratio: 16 / 9, fps: 24, min: 1200, max: 1600 },
{ resolution: VideoResolution.H_480P, ratio: 16 / 9, fps: 24, min: 2000, max: 2300 },
@ -119,6 +120,7 @@ describe('Bitrate', function () {
it('Should get appropriate average bitrate', function () {
const tests = [
{ resolution: VideoResolution.H_144P, ratio: 16 / 9, fps: 24, min: 50, max: 300 },
{ resolution: VideoResolution.H_240P, ratio: 16 / 9, fps: 24, min: 350, max: 450 },
{ resolution: VideoResolution.H_360P, ratio: 16 / 9, fps: 24, min: 700, max: 900 },
{ resolution: VideoResolution.H_480P, ratio: 16 / 9, fps: 24, min: 1100, max: 1300 },

View file

@ -6,6 +6,7 @@ type BitPerPixel = { [ id in VideoResolution ]: number }
const averageBitPerPixel: BitPerPixel = {
[VideoResolution.H_NOVIDEO]: 0,
[VideoResolution.H_144P]: 0.19,
[VideoResolution.H_240P]: 0.17,
[VideoResolution.H_360P]: 0.15,
[VideoResolution.H_480P]: 0.12,
@ -17,6 +18,7 @@ const averageBitPerPixel: BitPerPixel = {
const maxBitPerPixel: BitPerPixel = {
[VideoResolution.H_NOVIDEO]: 0,
[VideoResolution.H_144P]: 0.32,
[VideoResolution.H_240P]: 0.29,
[VideoResolution.H_360P]: 0.26,
[VideoResolution.H_480P]: 0.22,
@ -73,6 +75,7 @@ function calculateBitrate (options: {
VideoResolution.H_480P,
VideoResolution.H_360P,
VideoResolution.H_240P,
VideoResolution.H_144P,
VideoResolution.H_NOVIDEO
]

View file

@ -8,6 +8,7 @@ export class ConfigCommand extends AbstractCommand {
static getCustomConfigResolutions (enabled: boolean) {
return {
'144p': enabled,
'240p': enabled,
'360p': enabled,
'480p': enabled,
@ -232,6 +233,7 @@ export class ConfigCommand extends AbstractCommand {
profile: 'default',
resolutions: {
'0p': false,
'144p': false,
'240p': false,
'360p': true,
'480p': true,
@ -258,6 +260,7 @@ export class ConfigCommand extends AbstractCommand {
threads: 4,
profile: 'default',
resolutions: {
'144p': true,
'240p': true,
'360p': true,
'480p': true,

View file

@ -2,6 +2,7 @@ import { NSFWPolicyType } from '../videos/nsfw-policy.type'
import { BroadcastMessageLevel } from './broadcast-message-level.type'
export type ConfigResolutions = {
'144p': boolean
'240p': boolean
'360p': boolean
'480p': boolean

View file

@ -1,5 +1,6 @@
export const enum VideoResolution {
H_NOVIDEO = 0,
H_144P = 144,
H_240P = 240,
H_360P = 360,
H_480P = 480,

View file

@ -6167,6 +6167,8 @@ components:
properties:
0p:
type: boolean
144p:
type: boolean
240p:
type: boolean
360p:

View file

@ -130,6 +130,9 @@ transcoding:
__name: "PEERTUBE_TRANSCODING_THREADS"
__format: "json"
resolutions:
144p:
__name: "PEERTUBE_TRANSCODING_144P"
__format: "json"
240p:
__name: "PEERTUBE_TRANSCODING_240P"
__format: "json"