Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Add config to generate podcast audio file

Chocobozzz9204d042b952
diff --git a/client/src/app/+admin/config/pages/admin-config-vod.component.html b/client/src/app/+admin/config/pages/admin-config-vod.component.html
index 375aa499ed..f6407c4ea9 100644
--- a/client/src/app/+admin/config/pages/admin-config-vod.component.html
+++ b/client/src/app/+admin/config/pages/admin-config-vod.component.html
@@ -80,12 +80,12 @@
<my-peertube-checkbox
inputName="transcodingWebVideosEnabled" formControlName="enabled"
i18n-labelText labelText="Web Videos enabled"
- >
- <ng-template ptTemplate="help">
+ >
+ <ng-container ngProjectAs="description">
<ng-container>
- <p i18n>If you also enabled HLS support, it will multiply videos storage by 2</p>
+ <div i18n>If you also enable HLS output, video storage will be multiplied by 2</div>
</ng-container>
- </ng-template>
+ </ng-container>
</my-peertube-checkbox>
</div>
</ng-container>
@@ -97,6 +97,10 @@
i18n-labelText labelText="HLS with P2P support enabled"
[recommended]="true"
>
+ <ng-container ngProjectAs="description">
+ <div i18n>If you also enable Web Videos output, video storage will be multiplied by 2</div>
+ </ng-container>
+
<ng-template ptTemplate="help">
<ng-container i18n>
<strong>Requires ffmpeg >= 4.1</strong>
@@ -107,14 +111,12 @@
<li>Faster playback especially with long videos</li>
<li>More stable playback (less bugs/infinite loading)</li>
</ul>
-
- <p>If you also enabled Web Videos support, it will multiply videos storage by 2</p>
</ng-container>
</ng-template>
<ng-container ngProjectAs="extra">
- <div class="form-group" [ngClass]="getHLSDisabledClass()">
+ <div class="form-group" class="mb-0" [ngClass]="getHLSDisabledClass()">
<my-peertube-checkbox
inputName="transcodingHlsSplitAudioAndVideo" formControlName="splitAudioAndVideo"
i18n-labelText labelText="Split audio and video streams"
@@ -135,6 +137,18 @@
</div>
</ng-container>
+ <div class="form-group">
+ <my-peertube-checkbox
+ inputName="transcodingAlwaysTranscodePodcastOptimizedAudio" formControlName="alwaysTranscodePodcastOptimizedAudio"
+ i18n-labelText labelText="Always generate an audio file optimized for podcast applications"
+ >
+ <ng-container ngProjectAs="description">
+ <div i18n>HLS audio files are not always played correctly by podcast applications</div>
+ <div i18n>This option ensures that an optimized audio file is generated for podcast applications, even if Web Videos output is disabled</div>
+ </ng-container>
+ </my-peertube-checkbox>
+ </div>
+
<div class="form-group" formGroupName="fps" [ngClass]="getTranscodingDisabledClass()">
<label i18n for="transcodingFPSMax">Max video FPS</label>
diff --git a/client/src/app/+admin/config/pages/admin-config-vod.component.ts b/client/src/app/+admin/config/pages/admin-config-vod.component.ts
index ee2f1de458..df82e6d787 100644
--- a/client/src/app/+admin/config/pages/admin-config-vod.component.ts
+++ b/client/src/app/+admin/config/pages/admin-config-vod.component.ts
@@ -1,5 +1,5 @@
import { CommonModule } from '@angular/common'
-import { Component, OnInit, OnDestroy, inject } from '@angular/core'
+import { Component, OnDestroy, OnInit, inject } from '@angular/core'
import { FormControl, FormGroup, FormsModule, ReactiveFormsModule } from '@angular/forms'
import { ActivatedRoute, RouterLink } from '@angular/router'
import { CanComponentDeactivate, Notifier, ServerService } from '@app/core'
@@ -50,6 +50,7 @@ type Form = {
resolutions: FormGroup<FormResolutions>
alwaysTranscodeOriginalResolution: FormControl<boolean>
+ alwaysTranscodePodcastOptimizedAudio: FormControl<boolean>
remoteRunners: FormGroup<{
enabled: FormControl<boolean>
@@ -158,6 +159,7 @@ export class AdminConfigVODComponent implements OnInit, OnDestroy, CanComponentD
resolutions: this.adminConfigService.buildFormResolutions('vod'),
alwaysTranscodeOriginalResolution: null,
+ alwaysTranscodePodcastOptimizedAudio: null,
remoteRunners: {
enabled: null
diff --git a/client/src/app/shared/shared-main/video/video-details.model.ts b/client/src/app/shared/shared-main/video/video-details.model.ts
index 2e39ad4fe7..5f13e7a450 100644
--- a/client/src/app/shared/shared-main/video/video-details.model.ts
+++ b/client/src/app/shared/shared-main/video/video-details.model.ts
@@ -73,4 +73,18 @@ export class VideoDetails extends Video implements VideoDetailsServerModel {
hasEmbedRestrictions () {
return this.embedPrivacyPolicy.id !== VideoEmbedPrivacyPolicy.ALL_ALLOWED
}
+
+ // Try to find the best video file to download
+ // It builds an array and prioritises web videos that play on more third-party players.
+ getFilesForDownload () {
+ const store = this.files
+
+ for (const file of (this.getHlsPlaylist()?.files || [])) {
+ if (!store.some(f => f.resolution.id === file.resolution.id && f.fps === file.fps)) {
+ store.push(file)
+ }
+ }
+
+ return store
+ }
}
diff --git a/client/src/app/shared/shared-video-miniature/download/video-files-download.component.ts b/client/src/app/shared/shared-video-miniature/download/video-files-download.component.ts
index f28043db86..b51935b6de 100644
--- a/client/src/app/shared/shared-video-miniature/download/video-files-download.component.ts
+++ b/client/src/app/shared/shared-video-miniature/download/video-files-download.component.ts
@@ -64,21 +64,10 @@ export class VideoFilesDownloadComponent implements OnInit {
ngOnInit () {
if (this.hasFiles()) {
- this.onResolutionIdChange(this.getVideoFiles()[0].resolution.id)
+ this.onResolutionIdChange(this.video().getFilesForDownload()[0].resolution.id)
}
}
- getVideoFiles () {
- const video = this.video()
- if (!video) return []
- if (video.files.length !== 0) return video.files
-
- const hls = video.getHlsPlaylist()
- if (hls) return hls.files
-
- return []
- }
-
// ---------------------------------------------------------------------------
download () {
@@ -117,13 +106,13 @@ export class VideoFilesDownloadComponent implements OnInit {
// ---------------------------------------------------------------------------
hasFiles () {
- return this.getVideoFiles().length !== 0
+ return this.video().getFilesForDownload().length !== 0
}
getVideoFile () {
if (this.activeResolutionId === 'original') return undefined
- const file = this.getVideoFiles()
+ const file = this.video().getFilesForDownload()
.find(f => f.resolution.id === this.activeResolutionId)
if (!file) {
diff --git a/client/src/app/shared/shared-video-miniature/download/video-generate-download.component.ts b/client/src/app/shared/shared-video-miniature/download/video-generate-download.component.ts
index 06e867a7c6..5a64e83a54 100644
--- a/client/src/app/shared/shared-video-miniature/download/video-generate-download.component.ts
+++ b/client/src/app/shared/shared-video-miniature/download/video-generate-download.component.ts
@@ -1,4 +1,3 @@
-
import { Component, OnInit, inject, input, output } from '@angular/core'
import { FormsModule } from '@angular/forms'
import { PeertubeCheckboxComponent } from '@app/shared/shared-forms/peertube-checkbox.component'
@@ -21,7 +20,7 @@ import { VideoDetails } from '../../shared-main/video/video-details.model'
PeertubeCheckboxComponent,
NgbTooltip,
BytesPipe
-]
+ ]
})
export class VideoGenerateDownloadComponent implements OnInit {
private videoService = inject(VideoService)
@@ -37,7 +36,7 @@ export class VideoGenerateDownloadComponent implements OnInit {
videoFiles: VideoFile[]
ngOnInit () {
- this.videoFiles = this.buildVideoFiles()
+ this.videoFiles = this.video().getFilesForDownload()
if (this.videoFiles.length === 0) return
this.videoFileChosen = 'file-' + maxBy(this.videoFiles, 'resolution').id
@@ -106,16 +105,6 @@ export class VideoGenerateDownloadComponent implements OnInit {
// ---------------------------------------------------------------------------
- private buildVideoFiles () {
- const video = this.video()
- if (!video) return []
-
- const hls = video.getHlsPlaylist()
- if (hls) return hls.files
-
- return video.files
- }
-
private findCurrentFile () {
return this.videoFiles.find(f => this.videoFileChosen === 'file-' + f.id)
}
diff --git a/client/src/standalone/player/src/shared/player-options-builder/web-video-options-builder.ts b/client/src/standalone/player/src/shared/player-options-builder/web-video-options-builder.ts
index b69ab1d34f..bf4327a51e 100644
--- a/client/src/standalone/player/src/shared/player-options-builder/web-video-options-builder.ts
+++ b/client/src/standalone/player/src/shared/player-options-builder/web-video-options-builder.ts
@@ -1,20 +1,29 @@
+import { VideoResolution } from '@peertube/peertube-models'
import { PeerTubePlayerLoadOptions, WebVideoPluginOptions } from '../../types'
type ConstructorOptions = Pick<PeerTubePlayerLoadOptions, 'videoFileToken' | 'webVideo' | 'hls'>
export class WebVideoOptionsBuilder {
-
constructor (private options: ConstructorOptions) {
-
}
getPluginOptions (): WebVideoPluginOptions {
- return {
- videoFileToken: this.options.videoFileToken,
+ const videoFileToken = this.options.videoFileToken
+
+ const hlsFiles = this.options.hls?.videoFiles || []
+ const webVideoFiles = this.options.webVideo.videoFiles || []
- videoFiles: this.options.webVideo.videoFiles.length !== 0
- ? this.options.webVideo.videoFiles
- : this.options.hls?.videoFiles || []
+ // We have web video files, that aren't "audio only" files
+ if (webVideoFiles.length !== 0 && webVideoFiles.some(f => f.resolution.id !== VideoResolution.H_NOVIDEO)) {
+ return { videoFileToken, videoFiles: webVideoFiles }
}
+
+ // Not ideal because HLS files are fragmented, but better than nothing
+ if (hlsFiles.length !== 0 && hlsFiles.some(f => f.resolution.id !== VideoResolution.H_NOVIDEO)) {
+ return { videoFileToken, videoFiles: hlsFiles }
+ }
+
+ // Fallback to video files anyway
+ return { videoFileToken, videoFiles: webVideoFiles }
}
}
diff --git a/config/default.yaml b/config/default.yaml
index a0e3c42bbb..66d880674d 100644
--- a/config/default.yaml
+++ b/config/default.yaml
@@ -657,6 +657,11 @@ transcoding:
# Transcode and keep original resolution, even if it's above your maximum enabled resolution
always_transcode_original_resolution: true
+ # If web_videos transcoding is not enabled, some podcast applications may not be able to correctly play the HLS audio file
+ # Enabling this option ensures that PeerTube always produces an audio file in a format compatible with podcasts
+ # even if web_videos transcoding or audio resolution are disabled
+ always_transcode_podcast_optimized_audio: true
+
fps:
# Cap transcoded video FPS
# Max resolution file still keeps the original FPS
diff --git a/config/production.yaml.example b/config/production.yaml.example
index 31cf4a9e08..088df584d3 100644
--- a/config/production.yaml.example
+++ b/config/production.yaml.example
@@ -667,6 +667,11 @@ transcoding:
# Transcode and keep original resolution, even if it's above your maximum enabled resolution
always_transcode_original_resolution: true
+ # If web_videos transcoding is not enabled, some podcast applications may not be able to correctly play the HLS audio file
+ # Enabling this option ensures that PeerTube always produces an audio file in a format compatible with podcasts
+ # even if web_videos transcoding or audio resolution are disabled
+ always_transcode_podcast_optimized_audio: true
+
fps:
# Cap transcoded video FPS
# Max resolution file still keeps the original FPS
diff --git a/config/test.yaml b/config/test.yaml
index 14a3dcb04c..5836255aed 100644
--- a/config/test.yaml
+++ b/config/test.yaml
@@ -85,6 +85,7 @@ transcoding:
enabled: true
allow_additional_extensions: false
allow_audio_files: false
+ always_transcode_podcast_optimized_audio: false
threads: 2
concurrency: 2
resolutions:
diff --git a/packages/ffmpeg/src/ffmpeg-vod.ts b/packages/ffmpeg/src/ffmpeg-vod.ts
index a688bc04e6..0c7cbc340d 100644
--- a/packages/ffmpeg/src/ffmpeg-vod.ts
+++ b/packages/ffmpeg/src/ffmpeg-vod.ts
@@ -131,9 +131,7 @@ export class FFmpegVOD {
const probe = await ffprobePromise(videoInputPath)
const videoStreamInfo = await getVideoStreamDimensionsInfo(videoInputPath, probe)
- scaleFilterValue = videoStreamInfo?.isPortraitMode === true
- ? `w=${resolution}:h=-2`
- : `w=-2:h=${resolution}`
+ scaleFilterValue = this.getScaleFilterValue({ resolution, portraitMode: videoStreamInfo?.isPortraitMode === true })
}
await presetVOD({
@@ -179,7 +177,7 @@ export class FFmpegVOD {
canCopyVideo: true,
videoStreamOnly: false,
fps: options.fps,
- scaleFilterValue: this.getMergeAudioScaleFilterValue()
+ scaleFilterValue: this.getScaleFilterValue({ resolution: options.resolution, portraitMode: false })
})
command.outputOption('-preset:v veryfast')
@@ -190,8 +188,15 @@ export class FFmpegVOD {
}
// Avoid "height not divisible by 2" error
- private getMergeAudioScaleFilterValue () {
- return 'trunc(iw/2)*2:trunc(ih/2)*2'
+ private getScaleFilterValue (options: {
+ resolution: number
+ portraitMode: boolean
+ }) {
+ const { resolution, portraitMode } = options
+
+ return portraitMode === true
+ ? `w=${resolution}:h=-2`
+ : `w=-2:h=${resolution}`
}
// ---------------------------------------------------------------------------
diff --git a/packages/models/src/server/custom-config.model.ts b/packages/models/src/server/custom-config.model.ts
index c23dcae090..975e0f1533 100644
--- a/packages/models/src/server/custom-config.model.ts
+++ b/packages/models/src/server/custom-config.model.ts
@@ -169,6 +169,7 @@ export interface CustomConfig {
resolutions: ConfigResolutions
alwaysTranscodeOriginalResolution: boolean
+ alwaysTranscodePodcastOptimizedAudio: boolean
fps: {
max: number
diff --git a/packages/tests/src/api/server/config.ts b/packages/tests/src/api/server/config.ts
index a5e5aa0e9b..9173e725c2 100644
--- a/packages/tests/src/api/server/config.ts
+++ b/packages/tests/src/api/server/config.ts
@@ -88,6 +88,7 @@ function checkInitialConfig (server: PeerTubeServer, data: CustomConfig) {
expect(data.transcoding.alwaysTranscodeOriginalResolution).to.be.true
expect(data.transcoding.fps.max).to.equal(60)
expect(data.transcoding.webVideos.enabled).to.be.true
+ expect(data.transcoding.alwaysTranscodePodcastOptimizedAudio).to.be.true
expect(data.transcoding.hls.enabled).to.be.true
expect(data.transcoding.hls.splitAudioAndVideo).to.be.false
expect(data.transcoding.originalFile.keep).to.be.false
@@ -295,6 +296,7 @@ function buildNewCustomConfig (server: PeerTubeServer): CustomConfig {
'2160p': false
},
alwaysTranscodeOriginalResolution: false,
+ alwaysTranscodePodcastOptimizedAudio: false,
fps: {
max: 120
},
diff --git a/packages/tests/src/api/transcoding/force-audio-web-video-transcoding.ts b/packages/tests/src/api/transcoding/force-audio-web-video-transcoding.ts
new file mode 100644
index 0000000000..344bfffc99
--- /dev/null
+++ b/packages/tests/src/api/transcoding/force-audio-web-video-transcoding.ts
@@ -0,0 +1,117 @@
+/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
+
+import {
+ cleanupTests,
+ ConfigCommand,
+ createMultipleServers,
+ doubleFollow,
+ PeerTubeServer,
+ setAccessTokensToServers,
+ waitJobs
+} from '@peertube/peertube-server-commands'
+import { expect } from 'chai'
+
+describe('Test force audio web video transcoding', function () {
+ let servers: PeerTubeServer[] = []
+ let videoId1: string
+ let videoId2: string
+
+ before(async function () {
+ servers = await createMultipleServers(2)
+
+ // Get the access tokens
+ await setAccessTokensToServers(servers)
+
+ // Server 1 and server 2 follow each other
+ await doubleFollow(servers[0], servers[1])
+
+ {
+ const { uuid } = await servers[0].videos.quickUpload({ name: 'video 1' })
+ videoId1 = uuid
+ }
+
+ {
+ const { uuid } = await servers[0].videos.quickUpload({ name: 'video 2' })
+ videoId2 = uuid
+ }
+
+ await servers[0].config.updateExistingConfig({
+ newConfig: {
+ transcoding: {
+ enabled: true,
+ originalFile: {
+ keep: false
+ },
+
+ allowAudioFiles: true,
+ allowAdditionalExtensions: true,
+
+ resolutions: ConfigCommand.getCustomConfigResolutions([ 240, 720, 1080 ]),
+
+ alwaysTranscodeOriginalResolution: true,
+ alwaysTranscodePodcastOptimizedAudio: true,
+
+ webVideos: {
+ enabled: false
+ },
+
+ hls: {
+ enabled: true,
+ splitAudioAndVideo: false
+ }
+ }
+ }
+ })
+ })
+
+ it('Should enable some web video resolutions and override global configuration for audio resolution', async function () {
+ const { uuid } = await servers[0].videos.quickUpload({ name: 'video' })
+
+ await waitJobs(servers)
+
+ for (const server of servers) {
+ const video = await server.videos.get({ id: uuid })
+
+ expect(video.files.map(f => f.resolution.id)).to.have.members([ 0 ])
+ expect(video.streamingPlaylists[0].files.map(f => f.resolution.id)).to.have.members([ 240, 720 ])
+ }
+ })
+
+ it('Should force the audio resolution on manual web video transcoding', async function () {
+ {
+ const video = await servers[0].videos.get({ id: videoId1 })
+ expect(video.files.map(f => f.resolution.id)).to.have.members([ 720 ])
+ expect(video.streamingPlaylists).to.have.lengthOf(0)
+ }
+
+ await servers[0].videos.runTranscoding({ transcodingType: 'web-video', videoId: videoId1 })
+ await waitJobs(servers)
+
+ for (const server of servers) {
+ const video = await server.videos.get({ id: videoId1 })
+ expect(video.files.map(f => f.resolution.id)).to.have.members([ 0, 240, 720 ])
+ expect(video.streamingPlaylists).to.have.lengthOf(0)
+ }
+ })
+
+ it('Should not force the audio resolution on manual hls transcoding', async function () {
+ {
+ const video = await servers[0].videos.get({ id: videoId2 })
+ expect(video.files.map(f => f.resolution.id)).to.have.members([ 720 ])
+ expect(video.streamingPlaylists).to.have.lengthOf(0)
+ }
+
+ await servers[0].videos.runTranscoding({ transcodingType: 'hls', videoId: videoId2 })
+ await waitJobs(servers)
+
+ for (const server of servers) {
+ const video = await server.videos.get({ id: videoId2 })
+ expect(video.files.map(f => f.resolution.id)).to.have.members([ 720 ])
+ expect(video.streamingPlaylists[0].files.map(f => f.resolution.id)).to.have.members([ 240, 720 ])
+ }
+ })
+
+ after(async function () {
+ await cleanupTests(servers)
+ })
+})
diff --git a/packages/tests/src/api/transcoding/index.ts b/packages/tests/src/api/transcoding/index.ts
index 003c172596..285f7ee6f5 100644
--- a/packages/tests/src/api/transcoding/index.ts
+++ b/packages/tests/src/api/transcoding/index.ts
@@ -1,5 +1,6 @@
export * from './audio-only.js'
export * from './create-transcoding.js'
+export * from './force-audio-web-video-transcoding.js'
export * from './hls.js'
export * from './split-audio-and-video.js'
export * from './transcoder-limits.js'
diff --git a/packages/tests/src/feeds/feeds.ts b/packages/tests/src/feeds/feeds.ts
index 9e6fe39b67..7c33239c61 100644
--- a/packages/tests/src/feeds/feeds.ts
+++ b/packages/tests/src/feeds/feeds.ts
@@ -108,7 +108,16 @@ describe('Test syndication feeds', () => {
await servers[0].comments.createThread({ videoId: id, text: 'comment on password protected video' })
}
- await serverHLSOnly.videos.upload({ attributes: { name: 'hls only video', nsfw: true } })
+ {
+ await serverHLSOnly.config.updateExistingConfig({
+ newConfig: {
+ transcoding: {
+ alwaysTranscodePodcastOptimizedAudio: true
+ }
+ }
+ })
+ await serverHLSOnly.videos.upload({ attributes: { name: 'hls only video', nsfw: true } })
+ }
await waitJobs([ ...servers, serverHLSOnly ])
@@ -201,7 +210,7 @@ describe('Test syndication feeds', () => {
const enclosure = xmlDoc.rss.channel.item.enclosure
expect(enclosure).to.exist
- expectStartWith(enclosure['@_url'], `${serverHLSOnly.url}/download/videos/generate/`)
+ expectStartWith(enclosure['@_url'], `${serverHLSOnly.url}/static/web-videos/`)
expect(enclosure['@_url']).to.contain('.m4a')
expect(enclosure['@_type']).to.equal('audio/x-m4a')
@@ -217,6 +226,11 @@ describe('Test syndication feeds', () => {
expect(audioEnclosure['@_default']).to.equal(true)
expect(audioEnclosure['podcast:source']['@_uri']).to.equal(enclosure['@_url'])
+ const videoEnclosure = alternateEnclosures.find(e => e['@_type'] === 'video/mp4')
+ expect(videoEnclosure).to.exist
+ expect(videoEnclosure['@_default']).to.equal(false)
+ expectStartWith(videoEnclosure['podcast:source']['@_uri'], `${serverHLSOnly.url}/download/videos/generate/`)
+
const hlsEnclosure = alternateEnclosures.find(e => e['@_type'] === 'application/x-mpegURL')
expect(hlsEnclosure).to.exist
expect(hlsEnclosure['@_lang']).to.equal('zh')
@@ -475,9 +489,9 @@ describe('Test syndication feeds', () => {
const jsonObj = JSON.parse(json)
expect(jsonObj.items.length).to.be.equal(1)
expect(jsonObj.items[0].attachments).to.exist
- expect(jsonObj.items[0].attachments.length).to.be.eq(6)
+ expect(jsonObj.items[0].attachments.length).to.be.eq(12)
- for (let i = 0; i < 6; i++) {
+ for (let i = 0; i < 12; i++) {
expect(jsonObj.items[0].attachments[i].mime_type).to.be.eq('application/x-bittorrent')
expect(jsonObj.items[0].attachments[i].size_in_bytes).to.be.greaterThan(0)
expect(jsonObj.items[0].attachments[i].url).to.exist
diff --git a/packages/tests/src/peertube-runner/video-transcription.ts b/packages/tests/src/peertube-runner/video-transcription.ts
index ddb305b261..1f2c38239b 100644
--- a/packages/tests/src/peertube-runner/video-transcription.ts
+++ b/packages/tests/src/peertube-runner/video-transcription.ts
@@ -86,6 +86,9 @@ describe('Test transcription in peertube-runner program', function () {
})
})
+ describe('With custom web video transcoding configuration', function () {
+
+
describe('On object storage', function () {
if (areMockObjectStorageTestsDisabled()) return
@@ -161,6 +164,7 @@ describe('Test transcription in peertube-runner program', function () {
})
})
+
describe('Check cleanup', function () {
it('Should have an empty cache directory', async function () {
await checkPeerTubeRunnerCacheIsEmpty(peertubeRunner, 'transcription')
diff --git a/packages/tests/src/peertube-runner/vod-transcoding.ts b/packages/tests/src/peertube-runner/vod-transcoding.ts
index d5ff0bf95a..2c67473139 100644
--- a/packages/tests/src/peertube-runner/vod-transcoding.ts
+++ b/packages/tests/src/peertube-runner/vod-transcoding.ts
@@ -4,6 +4,7 @@ import { VideoPrivacy, VideoResolution } from '@peertube/peertube-models'
import { areMockObjectStorageTestsDisabled } from '@peertube/peertube-node-utils'
import {
cleanupTests,
+ ConfigCommand,
createMultipleServers,
doubleFollow,
ObjectStorageCommand,
@@ -392,6 +393,45 @@ describe('Test VOD transcoding in peertube-runner program', function () {
const resolutions = getAllFiles(video).map(f => f.resolution.id)
expect(resolutions).to.have.members([ 240, 240, 480, 480 ])
})
+
+ it('Should have a custom web video transcoding configuration', async function () {
+ await servers[0].config.updateExistingConfig({
+ newConfig: {
+ transcoding: {
+ enabled: true,
+ originalFile: {
+ keep: false
+ },
+
+ allowAudioFiles: true,
+ allowAdditionalExtensions: true,
+
+ resolutions: ConfigCommand.getCustomConfigResolutions([ 240, 720, 1080 ]),
+
+ alwaysTranscodeOriginalResolution: true,
+ alwaysTranscodePodcastOptimizedAudio: true,
+
+ hls: {
+ enabled: true,
+ splitAudioAndVideo: false
+ },
+
+ webVideos: {
+ enabled: false
+ }
+ }
+ }
+ })
+
+ const { uuid } = await servers[0].videos.quickUpload({ name: 'video' })
+
+ await waitJobs(servers, { runnerJobs: true })
+
+ const video = await servers[0].videos.get({ id: uuid })
+
+ expect(video.files.map(f => f.resolution.id)).to.have.members([ 0 ])
+ expect(video.streamingPlaylists[0].files.map(f => f.resolution.id)).to.have.members([ 240, 720 ])
+ })
})
})
diff --git a/server/core/controllers/api/config.ts b/server/core/controllers/api/config.ts
index 8faf45591a..e2c3605fc9 100644
--- a/server/core/controllers/api/config.ts
+++ b/server/core/controllers/api/config.ts
@@ -429,6 +429,7 @@ function customConfig (): CustomConfig {
'2160p': CONFIG.TRANSCODING.RESOLUTIONS['2160p']
},
alwaysTranscodeOriginalResolution: CONFIG.TRANSCODING.ALWAYS_TRANSCODE_ORIGINAL_RESOLUTION,
+ alwaysTranscodePodcastOptimizedAudio: CONFIG.TRANSCODING.ALWAYS_TRANSCODE_PODCAST_OPTIMIZED_AUDIO,
fps: {
max: CONFIG.TRANSCODING.FPS.MAX
},
diff --git a/server/core/controllers/api/videos/transcoding.ts b/server/core/controllers/api/videos/transcoding.ts
index b533b80ca8..496243fc2f 100644
--- a/server/core/controllers/api/videos/transcoding.ts
+++ b/server/core/controllers/api/videos/transcoding.ts
@@ -1,5 +1,6 @@
import { HttpStatusCode, UserRight, VideoState, VideoTranscodingCreate } from '@peertube/peertube-models'
import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { CONFIG } from '@server/initializers/config.js'
import { Hooks } from '@server/lib/plugins/hooks.js'
import { createTranscodingJobs } from '@server/lib/transcoding/create-transcoding-job.js'
import { computeResolutionsToTranscode } from '@server/lib/transcoding/transcoding-resolutions.js'
@@ -10,7 +11,8 @@ import { asyncMiddleware, authenticate, createTranscodingValidator, ensureUserHa
const lTags = loggerTagsFactory('api', 'video')
const transcodingRouter = express.Router()
-transcodingRouter.post('/:videoId/transcoding',
+transcodingRouter.post(
+ '/:videoId/transcoding',
authenticate,
ensureUserHasRight(UserRight.RUN_VIDEO_TRANSCODING),
asyncMiddleware(createTranscodingValidator),
@@ -37,11 +39,24 @@ async function createTranscoding (req: express.Request, res: express.Response) {
const hasAudio = video.hasAudio()
const resolutions = await Hooks.wrapObject(
- computeResolutionsToTranscode({ input: maxResolution, type: 'vod', includeInput: true, strictLower: false, hasAudio }),
+ computeResolutionsToTranscode({
+ input: maxResolution,
+ type: 'vod',
+ includeInput: true,
+ strictLower: false,
+ hasAudio,
+ forceAudioResolution: body.transcodingType === 'web-video' && CONFIG.TRANSCODING.ALWAYS_TRANSCODE_PODCAST_OPTIMIZED_AUDIO
+ }),
'filter:transcoding.manual.resolutions-to-transcode.result',
body
)
+ logger.debug(`Resolutions built for manual transcoding ${body.transcodingType} for video ${video.uuid}`, {
+ resolutions,
+
+ ...lTags(video.uuid)
+ })
+
if (resolutions.length === 0) {
return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
}
diff --git a/server/core/initializers/checker-before-init.ts b/server/core/initializers/checker-before-init.ts
index faff91b667..edae92211e 100644
--- a/server/core/initializers/checker-before-init.ts
+++ b/server/core/initializers/checker-before-init.ts
@@ -89,6 +89,7 @@ export function checkMissedConfig () {
'transcoding.original_file.keep',
'transcoding.threads',
'transcoding.allow_additional_extensions',
+ 'transcoding.always_transcode_podcast_optimized_audio',
'transcoding.web_videos.enabled',
'transcoding.hls.enabled',
'transcoding.profile',
diff --git a/server/core/initializers/config.ts b/server/core/initializers/config.ts
index 5e59609f7c..c1b0840c5b 100644
--- a/server/core/initializers/config.ts
+++ b/server/core/initializers/config.ts
@@ -643,6 +643,9 @@ const CONFIG = {
get ALWAYS_TRANSCODE_ORIGINAL_RESOLUTION () {
return config.get<boolean>('transcoding.always_transcode_original_resolution')
},
+ get ALWAYS_TRANSCODE_PODCAST_OPTIMIZED_AUDIO () {
+ return config.get<boolean>('transcoding.always_transcode_podcast_optimized_audio')
+ },
RESOLUTIONS: {
get '0p' () {
return config.get<boolean>('transcoding.resolutions.0p')
diff --git a/server/core/lib/job-queue/handlers/video-transcoding.ts b/server/core/lib/job-queue/handlers/video-transcoding.ts
index 829e8d0060..12ae734a66 100644
--- a/server/core/lib/job-queue/handlers/video-transcoding.ts
+++ b/server/core/lib/job-queue/handlers/video-transcoding.ts
@@ -3,8 +3,10 @@ import {
MergeAudioTranscodingPayload,
NewWebVideoResolutionTranscodingPayload,
OptimizeTranscodingPayload,
+ VideoResolution,
VideoTranscodingPayload
} from '@peertube/peertube-models'
+import { CONFIG } from '@server/initializers/config.js'
import { hasMissingHLSStreams } from '@server/lib/runners/job-handlers/shared/utils.js'
import { onTranscodingEnded } from '@server/lib/transcoding/ended-transcoding.js'
import { generateHlsPlaylistResolution } from '@server/lib/transcoding/hls-transcoding.js'
@@ -153,9 +155,16 @@ async function handleHLSJob (job: Job, payload: HLSTranscodingPayload, videoArg:
})
if (!missingStream && payload.deleteWebVideoFiles === true) {
- logger.info('Removing Web Video files of %s now we have a HLS version of it.', video.uuid, lTags(video.uuid))
+ const resolutionExceptions = CONFIG.TRANSCODING.ALWAYS_TRANSCODE_PODCAST_OPTIMIZED_AUDIO
+ ? [ VideoResolution.H_NOVIDEO ]
+ : []
- await removeAllWebVideoFiles(video)
+ logger.info('Removing Web Video files of %s now we have a HLS version of it.', video.uuid, {
+ resolutionExceptions,
+ ...lTags(video.uuid)
+ })
+
+ await removeAllWebVideoFiles(video, { resolutionExceptions })
}
// Splitted audio, wait audio & video generation before moving the video in its next state
diff --git a/server/core/lib/runners/job-handlers/vod-hls-transcoding-job-handler.ts b/server/core/lib/runners/job-handlers/vod-hls-transcoding-job-handler.ts
index bee6b8376e..8cebf992e0 100644
--- a/server/core/lib/runners/job-handlers/vod-hls-transcoding-job-handler.ts
+++ b/server/core/lib/runners/job-handlers/vod-hls-transcoding-job-handler.ts
@@ -4,10 +4,12 @@ import {
RunnerJobVODHLSTranscodingPayload,
RunnerJobVODHLSTranscodingPrivatePayload,
VideoFileStreamType,
+ VideoResolution,
VODHLSTranscodingSuccess
} from '@peertube/peertube-models'
import { buildUUID } from '@peertube/peertube-node-utils'
import { logger } from '@server/helpers/logger.js'
+import { CONFIG } from '@server/initializers/config.js'
import { onTranscodingEnded } from '@server/lib/transcoding/ended-transcoding.js'
import { onHLSVideoFileTranscoding } from '@server/lib/transcoding/hls-transcoding.js'
import { removeAllWebVideoFiles } from '@server/lib/video-file.js'
@@ -109,9 +111,16 @@ export class VODHLSTranscodingJobHandler
})
if (!missingStream && privatePayload.deleteWebVideoFiles === true) {
- logger.info('Removing web video files of %s now we have a HLS version of it.', video.uuid, this.lTags(video.uuid))
+ const resolutionExceptions = CONFIG.TRANSCODING.ALWAYS_TRANSCODE_PODCAST_OPTIMIZED_AUDIO
+ ? [ VideoResolution.H_NOVIDEO ]
+ : []
- await removeAllWebVideoFiles(video)
+ logger.info('Removing web video files of %s now we have a HLS version of it.', video.uuid, {
+ resolutionExceptions,
+ ...this.lTags(video.uuid)
+ })
+
+ await removeAllWebVideoFiles(video, { resolutionExceptions })
}
await onTranscodingEnded({
diff --git a/server/core/lib/schedulers/videos-redundancy-scheduler.ts b/server/core/lib/schedulers/videos-redundancy-scheduler.ts
index 4d988560d5..3a8bf67157 100644
--- a/server/core/lib/schedulers/videos-redundancy-scheduler.ts
+++ b/server/core/lib/schedulers/videos-redundancy-scheduler.ts
@@ -65,7 +65,6 @@ export class VideosRedundancyScheduler extends AbstractScheduler {
const candidateToDuplicate = {
video: videoToDuplicate,
redundancy: redundancyConfig,
- files: videoToDuplicate.VideoFiles,
streamingPlaylists: videoToDuplicate.VideoStreamingPlaylists
}
diff --git a/server/core/lib/transcoding/shared/job-builders/abstract-job-builder.ts b/server/core/lib/transcoding/shared/job-builders/abstract-job-builder.ts
index b972205a88..ee1a96d188 100644
--- a/server/core/lib/transcoding/shared/job-builders/abstract-job-builder.ts
+++ b/server/core/lib/transcoding/shared/job-builders/abstract-job-builder.ts
@@ -234,8 +234,17 @@ export abstract class AbstractJobBuilder<P extends { transcodingPriority: Transc
} = options
// Create transcoding jobs if there are enabled resolutions
+ const computeResolutionsOptions = {
+ input: inputVideoResolution,
+ type: 'vod' as const,
+ includeInput: false,
+ strictLower: true,
+ hasAudio,
+ forceAudioResolution: CONFIG.TRANSCODING.ALWAYS_TRANSCODE_PODCAST_OPTIMIZED_AUDIO
+ }
+
const resolutionsEnabled = await Hooks.wrapObject(
- computeResolutionsToTranscode({ input: inputVideoResolution, type: 'vod', includeInput: false, strictLower: true, hasAudio }),
+ computeResolutionsToTranscode(computeResolutionsOptions),
'filter:transcoding.auto.resolutions-to-transcode.result',
options
)
@@ -252,12 +261,12 @@ export abstract class AbstractJobBuilder<P extends { transcodingPriority: Transc
type: 'vod'
})
- let generateHLS = CONFIG.TRANSCODING.HLS.ENABLED
- if (resolution === VideoResolution.H_NOVIDEO && hlsAudioAlreadyGenerated) generateHLS = false
-
const parallelPayloads: P[] = []
- if (CONFIG.TRANSCODING.WEB_VIDEOS.ENABLED) {
+ if (
+ CONFIG.TRANSCODING.WEB_VIDEOS.ENABLED ||
+ (resolution === VideoResolution.H_NOVIDEO && CONFIG.TRANSCODING.ALWAYS_TRANSCODE_PODCAST_OPTIMIZED_AUDIO)
+ ) {
parallelPayloads.push(
this.buildWebVideoJobPayload({
video,
@@ -271,6 +280,14 @@ export abstract class AbstractJobBuilder<P extends { transcodingPriority: Transc
}
// Create a subsequent job to create HLS resolution that will just copy web video codecs
+ let generateHLS = CONFIG.TRANSCODING.HLS.ENABLED
+
+ if (resolution === VideoResolution.H_NOVIDEO && (hlsAudioAlreadyGenerated || CONFIG.TRANSCODING.RESOLUTIONS['0p'] !== true)) {
+ // Audio already generated
+ // Or the global audio resolution is not enabled (can still be in that case if ALWAYS_TRANSCODE_PODCAST_OPTIMIZED_AUDIO is enabled)
+ generateHLS = false
+ }
+
if (generateHLS) {
parallelPayloads.push(
this.buildHLSJobPayload({
diff --git a/server/core/lib/transcoding/transcoding-resolutions.ts b/server/core/lib/transcoding/transcoding-resolutions.ts
index 93c58491eb..1b5724ccb6 100644
--- a/server/core/lib/transcoding/transcoding-resolutions.ts
+++ b/server/core/lib/transcoding/transcoding-resolutions.ts
@@ -32,8 +32,9 @@ export function computeResolutionsToTranscode (options: {
includeInput: boolean
strictLower: boolean
hasAudio: boolean
+ forceAudioResolution?: boolean
}) {
- const { input, type, includeInput, strictLower, hasAudio } = options
+ const { input, type, includeInput, strictLower, hasAudio, forceAudioResolution } = options
const configResolutions = type === 'vod'
? CONFIG.TRANSCODING.RESOLUTIONS
@@ -72,5 +73,9 @@ export function computeResolutionsToTranscode (options: {
resolutionsEnabled.add(toEven(input))
}
+ if (forceAudioResolution === true && hasAudio) {
+ resolutionsEnabled.add(VideoResolution.H_NOVIDEO)
+ }
+
return Array.from(resolutionsEnabled)
}
diff --git a/server/core/lib/video-file.ts b/server/core/lib/video-file.ts
index f00a6e1acc..404776a933 100644
--- a/server/core/lib/video-file.ts
+++ b/server/core/lib/video-file.ts
@@ -114,16 +114,22 @@ export async function removeHLSFile (video: MVideoWithAllFiles, fileToDeleteId:
// ---------------------------------------------------------------------------
-export async function removeAllWebVideoFiles (video: MVideoWithAllFiles) {
+export async function removeAllWebVideoFiles (video: MVideoWithAllFiles, options: {
+ resolutionExceptions?: number[]
+} = {}) {
+ const { resolutionExceptions = [] } = options
+
const videoFileMutexReleaser = await VideoPathManager.Instance.lockFiles(video.uuid)
try {
for (const file of video.VideoFiles) {
+ if (resolutionExceptions.includes(file.resolution)) continue
+
await video.removeWebVideoFile(file)
await file.destroy()
- }
- video.VideoFiles = []
+ video.VideoFiles = video.VideoFiles.filter(f => f.id !== file.id)
+ }
} finally {
videoFileMutexReleaser()
}