Don't fail on upload if we cannot generate thumbnail

This commit is contained in:
Chocobozzz 2018-02-27 13:46:56 +01:00
parent 266707202c
commit 6fdc553adb
No known key found for this signature in database
GPG key ID: 583A612D890159BE
3 changed files with 27 additions and 12 deletions

View file

@ -1,8 +1,10 @@
import * as ffmpeg from 'fluent-ffmpeg'
import { join } from 'path'
import { VideoResolution } from '../../shared/models/videos'
import { CONFIG, MAX_VIDEO_TRANSCODING_FPS } from '../initializers'
import { unlinkPromise } from './core-utils'
import { processImage } from './image-utils'
import { join } from 'path'
import { logger } from './logger'
async function getVideoFileHeight (path: string) {
const videoStream = await getVideoFileStream(path)
@ -45,16 +47,27 @@ async function generateImageFromVideoFile (fromPath: string, folder: string, ima
folder
}
await new Promise<string>((res, rej) => {
ffmpeg(fromPath)
.on('error', rej)
.on('end', () => res(imageName))
.thumbnail(options)
})
const pendingImagePath = join(folder, pendingImageName)
const destination = join(folder, imageName)
await processImage({ path: pendingImagePath }, destination, size)
try {
await new Promise<string>((res, rej) => {
ffmpeg(fromPath)
.on('error', rej)
.on('end', () => res(imageName))
.thumbnail(options)
})
const destination = join(folder, imageName)
await processImage({ path: pendingImagePath }, destination, size)
} catch (err) {
logger.error('Cannot generate image from video %s.', fromPath, err)
try {
await unlinkPromise(pendingImagePath)
} catch (err) {
logger.debug('Cannot remove pending image path after generation error.', err)
}
}
}
type TranscodeOptions = {