mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-04 10:19:35 +02:00
Optimize video thumbnail generation
Process images in worker threads Reduce ffmpeg calls
This commit is contained in:
parent
ea6c2b064f
commit
272a902b2a
19 changed files with 226 additions and 156 deletions
|
@ -1,9 +1,10 @@
|
|||
import { join } from 'path'
|
||||
import Piscina from 'piscina'
|
||||
import { JOB_CONCURRENCY, WORKER_THREADS } from '@server/initializers/constants.js'
|
||||
import httpBroadcast from './workers/http-broadcast.js'
|
||||
import downloadImage from './workers/image-downloader.js'
|
||||
import processImage from './workers/image-processor.js'
|
||||
import type httpBroadcast from './workers/http-broadcast.js'
|
||||
import type downloadImage from './workers/image-downloader.js'
|
||||
import type processImage from './workers/image-processor.js'
|
||||
import type getImageSize from './workers/get-image-size.js'
|
||||
|
||||
let downloadImageWorker: Piscina
|
||||
|
||||
|
@ -37,6 +38,22 @@ function processImageFromWorker (options: Parameters<typeof processImage>[0]): P
|
|||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
let getImageSizeWorker: Piscina
|
||||
|
||||
function getImageSizeFromWorker (options: Parameters<typeof getImageSize>[0]): Promise<ReturnType<typeof getImageSize>> {
|
||||
if (!getImageSizeWorker) {
|
||||
getImageSizeWorker = new Piscina({
|
||||
filename: new URL(join('workers', 'get-image-size.js'), import.meta.url).href,
|
||||
concurrentTasksPerWorker: WORKER_THREADS.GET_IMAGE_SIZE.CONCURRENCY,
|
||||
maxThreads: WORKER_THREADS.GET_IMAGE_SIZE.MAX_THREADS
|
||||
})
|
||||
}
|
||||
|
||||
return getImageSizeWorker.run(options)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
let parallelHTTPBroadcastWorker: Piscina
|
||||
|
||||
function parallelHTTPBroadcastFromWorker (options: Parameters<typeof httpBroadcast>[0]): Promise<ReturnType<typeof httpBroadcast>> {
|
||||
|
@ -73,5 +90,6 @@ export {
|
|||
downloadImageFromWorker,
|
||||
processImageFromWorker,
|
||||
parallelHTTPBroadcastFromWorker,
|
||||
getImageSizeFromWorker,
|
||||
sequentialHTTPBroadcastFromWorker
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue