816f346a60
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
95 lines
2.9 KiB
TypeScript
95 lines
2.9 KiB
TypeScript
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 + '"')
|
|
}
|