mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-03 09:49:20 +02:00
Separate HLS audio and video streams
Allows: * The HLS player to propose an "Audio only" resolution * The live to output an "Audio only" resolution * The live to ingest and output an "Audio only" stream This feature is under a config for VOD videos and is enabled by default for lives In the future we can imagine: * To propose multiple audio streams for a specific video * To ingest an audio only VOD and just output an audio only "video" (the player would play the audio file and PeerTube would not generate additional resolutions) This commit introduce a new way to download videos: * Add "/download/videos/generate/:videoId" endpoint where PeerTube can mux an audio only and a video only file to a mp4 container * The download client modal introduces a new default panel where the user can choose resolutions it wants to download
This commit is contained in:
parent
e77ba2dfbc
commit
816f346a60
186 changed files with 5748 additions and 2807 deletions
95
server/scripts/migrations/peertube-6.3.ts
Normal file
95
server/scripts/migrations/peertube-6.3.ts
Normal file
|
@ -0,0 +1,95 @@
|
|||
import { ffprobePromise, getVideoStreamFPS } from '@peertube/peertube-ffmpeg'
|
||||
import { VideoFileStream } from '@peertube/peertube-models'
|
||||
import { initDatabaseModels } from '@server/initializers/database.js'
|
||||
import { buildFileMetadata } from '@server/lib/video-file.js'
|
||||
import { VideoPathManager } from '@server/lib/video-path-manager.js'
|
||||
import { VideoFileModel } from '@server/models/video/video-file.js'
|
||||
import { VideoModel } from '@server/models/video/video.js'
|
||||
import Bluebird from 'bluebird'
|
||||
import { pathExists } from 'fs-extra/esm'
|
||||
|
||||
run()
|
||||
.then(() => process.exit(0))
|
||||
.catch(err => {
|
||||
console.error(err)
|
||||
process.exit(-1)
|
||||
})
|
||||
|
||||
async function run () {
|
||||
console.log('## Assigning metadata information to local video files ##\n')
|
||||
|
||||
await initDatabaseModels(true)
|
||||
|
||||
const ids = await VideoModel.listLocalIds()
|
||||
|
||||
await Bluebird.map(ids, async id => {
|
||||
try {
|
||||
await processVideo(id)
|
||||
} catch (err) {
|
||||
console.error('Cannot process video ' + id, err)
|
||||
}
|
||||
}, { concurrency: 5 })
|
||||
|
||||
console.log('\n## Migration finished! ##')
|
||||
}
|
||||
|
||||
async function processVideo (videoId: number) {
|
||||
const video = await VideoModel.loadWithFiles(videoId)
|
||||
if (video.isLive) return
|
||||
|
||||
const files = await Promise.all(video.getAllFiles().map(f => VideoFileModel.loadWithMetadata(f.id)))
|
||||
|
||||
if (!files.some(f => f.fps === -1 || !f.metadata || !f.streams || f.width === null || f.height === null)) return
|
||||
|
||||
console.log('Processing video "' + video.name + '"')
|
||||
|
||||
for (const file of files) {
|
||||
if (!file.metadata || file.fps === -1) {
|
||||
const fileWithVideoOrPlaylist = file.videoStreamingPlaylistId
|
||||
? file.withVideoOrPlaylist(video.getHLSPlaylist())
|
||||
: file.withVideoOrPlaylist(video)
|
||||
|
||||
await VideoPathManager.Instance.makeAvailableVideoFile(fileWithVideoOrPlaylist, async path => {
|
||||
if (!await pathExists(path)) {
|
||||
console.error(
|
||||
`Skipping processing file ${file.id} because ${path} does not exist on disk for video "${video.name}" (uuid: ${video.uuid})`
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
console.log(`Filling metadata field of video "${video.name}" - file ${file.id} because it is missing in database`)
|
||||
|
||||
const probe = await ffprobePromise(path)
|
||||
|
||||
file.metadata = await buildFileMetadata(path, probe)
|
||||
file.fps = await getVideoStreamFPS(path, probe)
|
||||
|
||||
await file.save()
|
||||
})
|
||||
}
|
||||
|
||||
if (!file.metadata) continue
|
||||
|
||||
file.streams = VideoFileStream.NONE
|
||||
|
||||
const videoStream = file.metadata.streams.find(s => s.codec_type === 'video')
|
||||
|
||||
if (videoStream) {
|
||||
file.streams |= VideoFileStream.VIDEO
|
||||
|
||||
file.width = videoStream.width
|
||||
file.height = videoStream.height
|
||||
} else {
|
||||
file.width = 0
|
||||
file.height = 0
|
||||
}
|
||||
|
||||
if (file.metadata.streams.some(s => s.codec_type === 'audio')) {
|
||||
file.streams |= VideoFileStream.AUDIO
|
||||
}
|
||||
|
||||
await file.save()
|
||||
}
|
||||
|
||||
console.log('Successfully processed video "' + video.name + '"')
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue