Keep ratio for thumbnails
This commit is contained in:
parent
ea99d15fe8
commit
266707202c
|
@ -1,6 +1,8 @@
|
||||||
import * as ffmpeg from 'fluent-ffmpeg'
|
import * as ffmpeg from 'fluent-ffmpeg'
|
||||||
import { VideoResolution } from '../../shared/models/videos'
|
import { VideoResolution } from '../../shared/models/videos'
|
||||||
import { CONFIG, MAX_VIDEO_TRANSCODING_FPS } from '../initializers'
|
import { CONFIG, MAX_VIDEO_TRANSCODING_FPS } from '../initializers'
|
||||||
|
import { processImage } from './image-utils'
|
||||||
|
import { join } from 'path'
|
||||||
|
|
||||||
async function getVideoFileHeight (path: string) {
|
async function getVideoFileHeight (path: string) {
|
||||||
const videoStream = await getVideoFileStream(path)
|
const videoStream = await getVideoFileStream(path)
|
||||||
|
@ -34,23 +36,25 @@ function getDurationFromVideoFile (path: string) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateImageFromVideoFile (fromPath: string, folder: string, imageName: string, size: string) {
|
async function generateImageFromVideoFile (fromPath: string, folder: string, imageName: string, size: { width: number, height: number }) {
|
||||||
|
const pendingImageName = 'pending-' + imageName
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
filename: imageName,
|
filename: pendingImageName,
|
||||||
count: 1,
|
count: 1,
|
||||||
folder
|
folder
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size !== undefined) {
|
await new Promise<string>((res, rej) => {
|
||||||
options['size'] = size
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Promise<string>((res, rej) => {
|
|
||||||
ffmpeg(fromPath)
|
ffmpeg(fromPath)
|
||||||
.on('error', rej)
|
.on('error', rej)
|
||||||
.on('end', () => res(imageName))
|
.on('end', () => res(imageName))
|
||||||
.thumbnail(options)
|
.thumbnail(options)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const pendingImagePath = join(folder, pendingImageName)
|
||||||
|
const destination = join(folder, imageName)
|
||||||
|
await processImage({ path: pendingImagePath }, destination, size)
|
||||||
}
|
}
|
||||||
|
|
||||||
type TranscodeOptions = {
|
type TranscodeOptions = {
|
||||||
|
|
|
@ -793,24 +793,20 @@ export class VideoModel extends Model<VideoModel> {
|
||||||
}
|
}
|
||||||
|
|
||||||
createPreview (videoFile: VideoFileModel) {
|
createPreview (videoFile: VideoFileModel) {
|
||||||
const imageSize = PREVIEWS_SIZE.width + 'x' + PREVIEWS_SIZE.height
|
|
||||||
|
|
||||||
return generateImageFromVideoFile(
|
return generateImageFromVideoFile(
|
||||||
this.getVideoFilePath(videoFile),
|
this.getVideoFilePath(videoFile),
|
||||||
CONFIG.STORAGE.PREVIEWS_DIR,
|
CONFIG.STORAGE.PREVIEWS_DIR,
|
||||||
this.getPreviewName(),
|
this.getPreviewName(),
|
||||||
imageSize
|
PREVIEWS_SIZE
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
createThumbnail (videoFile: VideoFileModel) {
|
createThumbnail (videoFile: VideoFileModel) {
|
||||||
const imageSize = THUMBNAILS_SIZE.width + 'x' + THUMBNAILS_SIZE.height
|
|
||||||
|
|
||||||
return generateImageFromVideoFile(
|
return generateImageFromVideoFile(
|
||||||
this.getVideoFilePath(videoFile),
|
this.getVideoFilePath(videoFile),
|
||||||
CONFIG.STORAGE.THUMBNAILS_DIR,
|
CONFIG.STORAGE.THUMBNAILS_DIR,
|
||||||
this.getThumbnailName(),
|
this.getThumbnailName(),
|
||||||
imageSize
|
THUMBNAILS_SIZE
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue