aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/ffmpeg-utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/ffmpeg-utils.ts')
-rw-r--r--server/helpers/ffmpeg-utils.ts15
1 files changed, 11 insertions, 4 deletions
diff --git a/server/helpers/ffmpeg-utils.ts b/server/helpers/ffmpeg-utils.ts
index 00c32e99a..63dc5b6a3 100644
--- a/server/helpers/ffmpeg-utils.ts
+++ b/server/helpers/ffmpeg-utils.ts
@@ -263,6 +263,10 @@ async function canDoQuickTranscode (path: string): Promise<boolean> {
263 return true 263 return true
264} 264}
265 265
266function getClosestFramerateStandard (fps: number, hd = false): number {
267 return VIDEO_TRANSCODING_FPS[hd ? 'HD_STANDARD' : 'STANDARD'].slice(0).sort((a, b) => fps % a - fps % b)[0]
268}
269
266// --------------------------------------------------------------------------- 270// ---------------------------------------------------------------------------
267 271
268export { 272export {
@@ -286,13 +290,16 @@ export {
286 290
287async function buildx264Command (command: ffmpeg.FfmpegCommand, options: TranscodeOptions) { 291async function buildx264Command (command: ffmpeg.FfmpegCommand, options: TranscodeOptions) {
288 let fps = await getVideoFileFPS(options.inputPath) 292 let fps = await getVideoFileFPS(options.inputPath)
289 // On small/medium resolutions, limit FPS
290 if ( 293 if (
294 // On small/medium resolutions, limit FPS
291 options.resolution !== undefined && 295 options.resolution !== undefined &&
292 options.resolution < VIDEO_TRANSCODING_FPS.KEEP_ORIGIN_FPS_RESOLUTION_MIN && 296 options.resolution < VIDEO_TRANSCODING_FPS.KEEP_ORIGIN_FPS_RESOLUTION_MIN &&
293 fps > VIDEO_TRANSCODING_FPS.AVERAGE 297 fps > VIDEO_TRANSCODING_FPS.AVERAGE ||
298 // If the video is doesn't match hd standard
299 !VIDEO_TRANSCODING_FPS.HD_STANDARD.some(value => fps % value === 0)
294 ) { 300 ) {
295 fps = VIDEO_TRANSCODING_FPS.AVERAGE 301 // Get closest standard framerate by modulo: downsampling has to be done to a divisor of the nominal fps value
302 fps = getClosestFramerateStandard(fps)
296 } 303 }
297 304
298 command = await presetH264(command, options.inputPath, options.resolution, fps) 305 command = await presetH264(command, options.inputPath, options.resolution, fps)
@@ -305,7 +312,7 @@ async function buildx264Command (command: ffmpeg.FfmpegCommand, options: Transco
305 312
306 if (fps) { 313 if (fps) {
307 // Hard FPS limits 314 // Hard FPS limits
308 if (fps > VIDEO_TRANSCODING_FPS.MAX) fps = VIDEO_TRANSCODING_FPS.MAX 315 if (fps > VIDEO_TRANSCODING_FPS.MAX) fps = getClosestFramerateStandard(fps, true)
309 else if (fps < VIDEO_TRANSCODING_FPS.MIN) fps = VIDEO_TRANSCODING_FPS.MIN 316 else if (fps < VIDEO_TRANSCODING_FPS.MIN) fps = VIDEO_TRANSCODING_FPS.MIN
310 317
311 command = command.withFPS(fps) 318 command = command.withFPS(fps)