mirror of https://github.com/Chocobozzz/PeerTube
Fix thumbnail generation when on bad input seek
parent
c93b7088c2
commit
7b23f24b24
|
@ -79,6 +79,10 @@ export class FFmpegCommandWrapper {
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
resetCommand () {
|
||||||
|
this.command = undefined
|
||||||
|
}
|
||||||
|
|
||||||
buildCommand (input: string) {
|
buildCommand (input: string) {
|
||||||
if (this.command) throw new Error('Command is already built')
|
if (this.command) throw new Error('Command is already built')
|
||||||
|
|
||||||
|
|
|
@ -36,25 +36,50 @@ export class FFmpegImage {
|
||||||
return this.commandWrapper.runCommand()
|
return this.commandWrapper.runCommand()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
async generateThumbnailFromVideo (options: {
|
async generateThumbnailFromVideo (options: {
|
||||||
fromPath: string
|
fromPath: string
|
||||||
output: string
|
output: string
|
||||||
framesToAnalyze: number
|
framesToAnalyze: number
|
||||||
ffprobe?: FfprobeData
|
ffprobe?: FfprobeData
|
||||||
}) {
|
}) {
|
||||||
const { fromPath, output, ffprobe, framesToAnalyze } = options
|
const { fromPath, ffprobe } = options
|
||||||
|
|
||||||
let duration = await getVideoStreamDuration(fromPath, ffprobe)
|
let duration = await getVideoStreamDuration(fromPath, ffprobe)
|
||||||
if (isNaN(duration)) duration = 0
|
if (isNaN(duration)) duration = 0
|
||||||
|
|
||||||
this.commandWrapper.buildCommand(fromPath)
|
this.buildGenerateThumbnailFromVideo(options)
|
||||||
.seekInput(duration / 2)
|
.seekInput(duration / 2)
|
||||||
.videoFilter('thumbnail=' + framesToAnalyze)
|
|
||||||
.outputOption('-frames:v 1')
|
try {
|
||||||
.output(output)
|
return await this.commandWrapper.runCommand()
|
||||||
|
} catch (err) {
|
||||||
|
this.commandWrapper.debugLog('Cannot generate thumbnail from video using seek input, fallback to no seek', { err })
|
||||||
|
|
||||||
|
this.commandWrapper.resetCommand()
|
||||||
|
|
||||||
|
this.buildGenerateThumbnailFromVideo(options)
|
||||||
|
|
||||||
return this.commandWrapper.runCommand()
|
return this.commandWrapper.runCommand()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private buildGenerateThumbnailFromVideo (options: {
|
||||||
|
fromPath: string
|
||||||
|
output: string
|
||||||
|
framesToAnalyze: number
|
||||||
|
}) {
|
||||||
|
const { fromPath, output, framesToAnalyze } = options
|
||||||
|
|
||||||
|
return this.commandWrapper.buildCommand(fromPath)
|
||||||
|
.videoFilter('thumbnail=' + framesToAnalyze)
|
||||||
|
.outputOption('-frames:v 1')
|
||||||
|
.outputOption('-abort_on empty_output')
|
||||||
|
.output(output)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
async generateStoryboardFromVideo (options: {
|
async generateStoryboardFromVideo (options: {
|
||||||
path: string
|
path: string
|
||||||
|
|
Loading…
Reference in New Issue