Simpler thumbnail generation
This commit is contained in:
parent
318aa9c422
commit
b7f946892b
2 changed files with 12 additions and 16 deletions
|
@ -51,7 +51,7 @@ async function generateImageFromVideoFile (options: {
|
||||||
const pendingImagePath = join(folder, pendingImageName)
|
const pendingImagePath = join(folder, pendingImageName)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await generateThumbnailFromVideo({ fromPath, folder, imageName })
|
await generateThumbnailFromVideo({ fromPath, output: pendingImagePath })
|
||||||
|
|
||||||
const destination = join(folder, imageName)
|
const destination = join(folder, imageName)
|
||||||
await processImage({ path: pendingImagePath, destination, newSize: size })
|
await processImage({ path: pendingImagePath, destination, newSize: size })
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { FFmpegCommandWrapper, FFmpegCommandWrapperOptions } from './ffmpeg-command-wrapper'
|
import { FFmpegCommandWrapper, FFmpegCommandWrapperOptions } from './ffmpeg-command-wrapper'
|
||||||
|
import { getVideoStreamDuration } from './ffprobe'
|
||||||
|
|
||||||
export class FFmpegImage {
|
export class FFmpegImage {
|
||||||
private readonly commandWrapper: FFmpegCommandWrapper
|
private readonly commandWrapper: FFmpegCommandWrapper
|
||||||
|
@ -36,25 +37,20 @@ export class FFmpegImage {
|
||||||
|
|
||||||
async generateThumbnailFromVideo (options: {
|
async generateThumbnailFromVideo (options: {
|
||||||
fromPath: string
|
fromPath: string
|
||||||
folder: string
|
output: string
|
||||||
imageName: string
|
|
||||||
}) {
|
}) {
|
||||||
const { fromPath, folder, imageName } = options
|
const { fromPath, output } = options
|
||||||
|
|
||||||
const pendingImageName = 'pending-' + imageName
|
let duration = await getVideoStreamDuration(fromPath)
|
||||||
|
if (isNaN(duration)) duration = 0
|
||||||
|
|
||||||
const thumbnailOptions = {
|
|
||||||
filename: pendingImageName,
|
|
||||||
count: 1,
|
|
||||||
folder
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Promise<string>((res, rej) => {
|
|
||||||
this.commandWrapper.buildCommand(fromPath)
|
this.commandWrapper.buildCommand(fromPath)
|
||||||
.on('error', rej)
|
.seekInput(duration / 2)
|
||||||
.on('end', () => res(imageName))
|
.videoFilter('thumbnail=500')
|
||||||
.thumbnail(thumbnailOptions)
|
.outputOption('-frames:v 1')
|
||||||
})
|
.output(output)
|
||||||
|
|
||||||
|
return this.commandWrapper.runCommand()
|
||||||
}
|
}
|
||||||
|
|
||||||
async generateStoryboardFromVideo (options: {
|
async generateStoryboardFromVideo (options: {
|
||||||
|
|
Loading…
Add table
Reference in a new issue