ActivityPub-federated video streaming platform using P2P directly in your web browser
Send file directly if possible
Chocobozzz681f2859bb8e
diff --git a/client/src/app/shared/shared-video-miniature/download/video-files-download.component.html b/client/src/app/shared/shared-video-miniature/download/video-files-download.component.htmlindex 9264e931e2..396b7489df 100644--- a/client/src/app/shared/shared-video-miniature/download/video-files-download.component.html+++ b/client/src/app/shared/shared-video-miniature/download/video-files-download.component.html@@ -28,7 +28,7 @@</ng-container>}- @for (file of getVideoFiles(); track file) {+ @for (file of video().getFilesForDownload(); track file) {<ng-container [ngbNavItem]="file.resolution.id"><a ngbNavLink>{{ file.resolution.label }}</a><ng-template ngbNavContent>diff --git a/packages/tests/src/api/server/config.ts b/packages/tests/src/api/server/config.tsindex 9173e725c2..d5daa99f8b 100644--- a/packages/tests/src/api/server/config.ts+++ b/packages/tests/src/api/server/config.ts@@ -88,7 +88,7 @@ function checkInitialConfig (server: PeerTubeServer, data: CustomConfig) {expect(data.transcoding.alwaysTranscodeOriginalResolution).to.be.trueexpect(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.alwaysTranscodePodcastOptimizedAudio).to.be.falseexpect(data.transcoding.hls.enabled).to.be.trueexpect(data.transcoding.hls.splitAudioAndVideo).to.be.falseexpect(data.transcoding.originalFile.keep).to.be.falsediff --git a/packages/tests/src/api/videos/generate-download.ts b/packages/tests/src/api/videos/generate-download.tsindex 3ed15170b1..9120b7012b 100644--- a/packages/tests/src/api/videos/generate-download.ts+++ b/packages/tests/src/api/videos/generate-download.ts@@ -84,46 +84,52 @@ describe('Test generate download', function () {return probeResBody(body)}- function checkProbe (probe: FfprobeData, options: { hasVideo: boolean, hasAudio: boolean, hasImage: boolean }) {+ function checkProbe (probe: FfprobeData, options: { hasVideo: boolean, hasAudio: boolean, hasImage: boolean, muxed: boolean }) {expect(probe.streams.some(s => s.codec_type === 'video' && s.codec_name !== 'mjpeg')).to.equal(options.hasVideo)expect(probe.streams.some(s => s.codec_type === 'audio')).to.equal(options.hasAudio)expect(probe.streams.some(s => s.codec_name === 'mjpeg')).to.equal(options.hasImage)++ if (options.muxed) {+ expect(probe.format.tags.compatible_brands).to.include('iso6')+ } else {+ expect(probe.format.tags.compatible_brands).to.not.include('iso6')+ }}it('Should generate a classic web video file', async function () {const probe = await getProbe('common', video => [ getVideoFile(video.files).id ])- checkProbe(probe, { hasAudio: true, hasVideo: true, hasImage: false })+ checkProbe(probe, { hasAudio: true, hasVideo: true, hasImage: false, muxed: false })})it('Should generate a classic HLS file', async function () {const probe = await getProbe('common', video => [ getVideoFile(getHLS(video).files).id ])- checkProbe(probe, { hasAudio: true, hasVideo: true, hasImage: false })+ checkProbe(probe, { hasAudio: true, hasVideo: true, hasImage: false, muxed: true })})it('Should generate an audio only web video file', async function () {const probe = await getProbe('common', video => [ getAudioOnlyFile(video.files).id ])- checkProbe(probe, { hasAudio: true, hasVideo: false, hasImage: true })+ checkProbe(probe, { hasAudio: true, hasVideo: false, hasImage: true, muxed: true })})it('Should generate an audio only HLS file', async function () {const probe = await getProbe('common', video => [ getAudioOnlyFile(getHLS(video).files).id ])- checkProbe(probe, { hasAudio: true, hasVideo: false, hasImage: true })+ checkProbe(probe, { hasAudio: true, hasVideo: false, hasImage: true, muxed: true })})it('Should generate a video only file', async function () {const probe = await getProbe('splitted', video => [ getVideoFile(getHLS(video).files).id ])- checkProbe(probe, { hasAudio: false, hasVideo: true, hasImage: false })+ checkProbe(probe, { hasAudio: false, hasVideo: true, hasImage: false, muxed: true })})it('Should merge audio and video files', async function () {const probe = await getProbe('splitted', video => [ getVideoFile(getHLS(video).files).id, getAudioFile(getHLS(video).files).id ])- checkProbe(probe, { hasAudio: true, hasVideo: true, hasImage: false })+ checkProbe(probe, { hasAudio: true, hasVideo: true, hasImage: false, muxed: true })})it('Should have cleaned the TMP directory', async function () {diff --git a/packages/tests/src/feeds/feeds.ts b/packages/tests/src/feeds/feeds.tsindex 7c33239c61..38bbaacc04 100644--- a/packages/tests/src/feeds/feeds.ts+++ b/packages/tests/src/feeds/feeds.ts@@ -211,20 +211,22 @@ describe('Test syndication feeds', () => {const enclosure = xmlDoc.rss.channel.item.enclosureexpect(enclosure).to.existexpectStartWith(enclosure['@_url'], `${serverHLSOnly.url}/static/web-videos/`)- expect(enclosure['@_url']).to.contain('.m4a')+ expect(enclosure['@_url']).to.contain('.mp4')expect(enclosure['@_type']).to.equal('audio/x-m4a')const res = await makeRawRequest({ url: enclosure['@_url'], expectedStatus: HttpStatusCode.OK_200 })- expect(res.headers['content-type']).to.equal('audio/mp4')+ expect(res.headers['content-type']).to.equal('video/mp4')expect(res.headers['content-disposition']).to.not.existconst alternateEnclosures = xmlDoc.rss.channel.item['podcast:alternateEnclosure']expect(alternateEnclosures).to.be.an('array')+ expect(alternateEnclosures.length).to.equal(7) // Web video audio + HLS (144p, 240p, 360p, 480p, 720p) + m3u8 master playlist+const audioEnclosure = alternateEnclosures.find(e => e['@_type'] === 'audio/x-m4a')expect(audioEnclosure).to.existexpect(audioEnclosure['@_default']).to.equal(true)- expect(audioEnclosure['podcast:source']['@_uri']).to.equal(enclosure['@_url'])+ expect(audioEnclosure['podcast:source'][0]['@_uri']).to.equal(enclosure['@_url'])const videoEnclosure = alternateEnclosures.find(e => e['@_type'] === 'video/mp4')expect(videoEnclosure).to.exist@@ -489,9 +491,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(12)+ expect(jsonObj.items[0].attachments.length).to.be.eq(7)- for (let i = 0; i < 12; i++) {+ for (let i = 0; i < 7; 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.existdiff --git a/packages/tests/src/peertube-runner/video-transcription.ts b/packages/tests/src/peertube-runner/video-transcription.tsindex 1f2c38239b..ddb305b261 100644--- a/packages/tests/src/peertube-runner/video-transcription.ts+++ b/packages/tests/src/peertube-runner/video-transcription.ts@@ -86,9 +86,6 @@ describe('Test transcription in peertube-runner program', function () {})})- describe('With custom web video transcoding configuration', function () {--describe('On object storage', function () {if (areMockObjectStorageTestsDisabled()) return@@ -164,7 +161,6 @@ 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/server/core/controllers/feeds/video-podcast-feeds.ts b/server/core/controllers/feeds/video-podcast-feeds.tsindex 20ae0bb3d3..c84179c883 100644--- a/server/core/controllers/feeds/video-podcast-feeds.ts+++ b/server/core/controllers/feeds/video-podcast-feeds.ts@@ -217,7 +217,7 @@ async function addVODPodcastItem (options: {.map(f => buildVODWebVideoFile(video, f)).sort(sortObjectComparator('bitrate', 'asc'))- const streamingPlaylistFiles = buildVODStreamingPlaylists(video)+ const streamingPlaylistFiles = buildVODStreamingPlaylistsIfMissingWebVideoFile(video)// Order matters here, the first media URI will be the "default"// So web videos are default if enabled@@ -273,7 +273,7 @@ function buildVODWebVideoFile (video: MVideo, videoFile: VideoFile) {}}-function buildVODStreamingPlaylists (video: MVideoFullLight) {+function buildVODStreamingPlaylistsIfMissingWebVideoFile (video: MVideoFullLight) {const hls = video.getHLSPlaylist()if (!hls) return []@@ -281,6 +281,7 @@ function buildVODStreamingPlaylists (video: MVideoFullLight) {return [...hls.VideoFiles+ .filter(videoFile => !video.VideoFiles.some(f => f.fps === videoFile.fps && f.resolution === videoFile.resolution)).sort(sortObjectComparator('resolution', 'asc')).map(videoFile => {const files = [ videoFile ]diff --git a/server/core/lib/video-download.ts b/server/core/lib/video-download.tsindex 594d27c234..c0ca4a698b 100644--- a/server/core/lib/video-download.ts+++ b/server/core/lib/video-download.ts@@ -4,9 +4,10 @@ import { getFFmpegCommandWrapperOptions } from '@server/helpers/ffmpeg/ffmpeg-opimport { logger } from '@server/helpers/logger.js'import { buildRequestError, doRequestAndSaveToFile, generateRequestStream } from '@server/helpers/requests.js'import { REQUEST_TIMEOUTS } from '@server/initializers/constants.js'-import { MVideoFile, MVideoThumbnail } from '@server/types/models/index.js'+import { isWebVideoFile, MVideoFile, MVideoThumbnail } from '@server/types/models/index.js'import { remove } from 'fs-extra/esm'import { Readable, Writable } from 'stream'+import { pipeline } from 'stream/promises'import { lTags } from './object-storage/shared/index.js'import {getHLSFileReadStream,@@ -15,6 +16,7 @@ import {makeWebVideoFileAvailable} from './object-storage/videos.js'import { VideoPathManager } from './video-path-manager.js'+import { createReadStream } from 'fs'export class VideoDownload {static totalDownloads = 0@@ -27,6 +29,8 @@ export class VideoDownload {private readonly video: MVideoThumbnailprivate readonly videoFiles: MVideoFile[]+ private allowDirectSending = true+constructor (options: {video: MVideoThumbnailvideoFiles: MVideoFile[]@@ -51,40 +55,51 @@ export class VideoDownload {this.tmpDestinations.push(coverPath)}- logger.info(`Muxing files for video ${this.video.url}`, { inputs: this.inputsToLog(), ...lTags(this.video.uuid) })+ // Prefer sending the file directly if possible+ if (this.allowDirectSending && !coverPath && this.inputs.length === 1) {+ logger.info(`Piping single file for video ${this.video.url}`, { input: this.inputsToLog()[0], ...lTags(this.video.uuid) })- this.ffmpegContainer = new FFmpegContainer(getFFmpegCommandWrapperOptions('vod'))+ const input = typeof this.inputs[0] === 'string'+ ? createReadStream(this.inputs[0])+ : this.inputs[0]- try {- await this.ffmpegContainer.mergeInputs({- inputs: this.inputs,- output,- logError: false,+ await pipeline(input, output)+ } else {+ logger.info(`Muxing files for video ${this.video.url}`, { inputs: this.inputsToLog(), ...lTags(this.video.uuid) })- // Include a cover if this is an audio file- coverPath- })+ this.ffmpegContainer = new FFmpegContainer(getFFmpegCommandWrapperOptions('vod'))- logger.info(`Mux ended for video ${this.video.url}`, { inputs: this.inputsToLog(), ...lTags(this.video.uuid) })+ try {+ await this.ffmpegContainer.mergeInputs({+ inputs: this.inputs,+ output,+ logError: false,- res()- } catch (err) {- const message = err?.message || ''+ // Include a cover if this is an audio file+ coverPath+ })- if (message.includes('Output stream closed')) {- logger.info(`Client aborted mux for video ${this.video.url}`, lTags(this.video.uuid))- return- }+ logger.info(`Mux ended for video ${this.video.url}`, { inputs: this.inputsToLog(), ...lTags(this.video.uuid) })- if (err.inputStreamError) {- err.inputStreamError = buildRequestError(err.inputStreamError)- }+ res()+ } catch (err) {+ const message = err?.message || ''++ if (message.includes('Output stream closed')) {+ logger.info(`Client aborted mux for video ${this.video.url}`, lTags(this.video.uuid))+ return+ }- logger.warn(`Cannot mux files of video ${this.video.url}`, { err, inputs: this.inputsToLog(), ...lTags(this.video.uuid) })+ if (err.inputStreamError) {+ err.inputStreamError = buildRequestError(err.inputStreamError)+ }- throw err- } finally {- this.ffmpegContainer.forceKill()+ logger.warn(`Cannot mux files of video ${this.video.url}`, { err, inputs: this.inputsToLog(), ...lTags(this.video.uuid) })++ throw err+ } finally {+ this.ffmpegContainer.forceKill()+ }}} catch (err) {rej(err)@@ -105,6 +120,10 @@ export class VideoDownload {for (const videoFile of this.videoFiles) {if (!videoFile) continue+ if (!isWebVideoFile(videoFile)) {+ this.allowDirectSending = false+ }+maxResolution = Math.max(maxResolution, videoFile.resolution)const { input, isTmpDestination } = await this.buildMuxInput(