Add video file metadata to download modal, via ffprobe (#2411)

* Add video file metadata via ffprobe

* Federate video file metadata

* Add tests for file metadata generation

* Complete tests for videoFile metadata federation

* Lint migration and video-file for metadata

* Objectify metadata from getter in ffmpeg-utils

* Add metadataUrl to all videoFiles

* Simplify metadata API middleware

* Load playlist in videoFile when requesting metadata
This commit is contained in:
Rigel Kent 2020-03-10 14:39:40 +01:00 committed by GitHub
parent edb868655e
commit 8319d6ae72
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 553 additions and 52 deletions

View file

@ -7,6 +7,7 @@ import { logger } from './logger'
import { checkFFmpegEncoders } from '../initializers/checker-before-init'
import { readFile, remove, writeFile } from 'fs-extra'
import { CONFIG } from '../initializers/config'
import { VideoFileMetadata } from '@shared/models/videos/video-file-metadata'
/**
* A toolbox to play with audio
@ -169,24 +170,26 @@ async function getVideoFileFPS (path: string) {
return 0
}
async function getVideoFileBitrate (path: string) {
return new Promise<number>((res, rej) => {
async function getMetadataFromFile<T> (path: string, cb = metadata => metadata) {
return new Promise<T>((res, rej) => {
ffmpeg.ffprobe(path, (err, metadata) => {
if (err) return rej(err)
return res(metadata.format.bit_rate)
return res(cb(new VideoFileMetadata(metadata)))
})
})
}
function getDurationFromVideoFile (path: string) {
return new Promise<number>((res, rej) => {
ffmpeg.ffprobe(path, (err, metadata) => {
if (err) return rej(err)
async function getVideoFileBitrate (path: string) {
return getMetadataFromFile<number>(path, metadata => metadata.format.bit_rate)
}
return res(Math.floor(metadata.format.duration))
})
})
function getDurationFromVideoFile (path: string) {
return getMetadataFromFile<number>(path, metadata => Math.floor(metadata.format.duration))
}
function getVideoStreamFromFile (path: string) {
return getMetadataFromFile<any>(path, metadata => metadata.streams.find(s => s.codec_type === 'video') || null)
}
async function generateImageFromVideoFile (fromPath: string, folder: string, imageName: string, size: { width: number, height: number }) {
@ -341,6 +344,7 @@ export {
getAudioStreamCodec,
getVideoStreamSize,
getVideoFileResolution,
getMetadataFromFile,
getDurationFromVideoFile,
generateImageFromVideoFile,
TranscodeOptions,
@ -450,17 +454,6 @@ async function fixHLSPlaylistIfNeeded (options: TranscodeOptions) {
await writeFile(options.outputPath, newContent)
}
function getVideoStreamFromFile (path: string) {
return new Promise<any>((res, rej) => {
ffmpeg.ffprobe(path, (err, metadata) => {
if (err) return rej(err)
const videoStream = metadata.streams.find(s => s.codec_type === 'video')
return res(videoStream || null)
})
})
}
/**
* A slightly customised version of the 'veryfast' x264 preset
*