Handle videos with FPS < 1

This commit is contained in:
Chocobozzz 2024-05-29 08:56:53 +02:00
parent 67c1f1985f
commit 4ea659d569
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
4 changed files with 22 additions and 10 deletions

View File

@ -120,7 +120,7 @@ export class FFmpegImage {
const filter = [
// Fix "t" variable with some videos
`setpts=N/round(FRAME_RATE)/TB`,
`setpts='N/FRAME_RATE/TB'`,
// First frame or the time difference between the last and the current frame is enough for our sprite interval
`select='isnan(prev_selected_t)+gte(t-prev_selected_t,${options.sprites.duration})'`,
`scale=${sprites.size.width}:${sprites.size.height}`,

View File

@ -1,9 +1,18 @@
export type VideoTranscodingFPS = {
MIN: number
// Refuse videos with FPS below this limit
HARD_MIN: number
// Cap FPS to this min value
SOFT_MIN: number
STANDARD: number[]
HD_STANDARD: number[]
AUDIO_MERGE: number
AVERAGE: number
MAX: number
// Cap FPS to this max value
SOFT_MAX: number
KEEP_ORIGIN_FPS_RESOLUTION_MIN: number
}

View File

@ -18,13 +18,15 @@ export function computeOutputFPS (options: {
fps = getClosestFramerateStandard({ fps, type: 'STANDARD' })
}
// Hard FPS limits
if (fps > VIDEO_TRANSCODING_FPS.MAX) fps = getClosestFramerateStandard({ fps, type: 'HD_STANDARD' })
if (fps < VIDEO_TRANSCODING_FPS.MIN) {
throw new Error(`Cannot compute FPS because ${fps} is lower than our minimum value ${VIDEO_TRANSCODING_FPS.MIN}`)
if (fps < VIDEO_TRANSCODING_FPS.HARD_MIN) {
throw new Error(`Cannot compute FPS because ${fps} is lower than our minimum value ${VIDEO_TRANSCODING_FPS.HARD_MIN}`)
}
// Cap min FPS
if (fps < VIDEO_TRANSCODING_FPS.SOFT_MIN) fps = VIDEO_TRANSCODING_FPS.SOFT_MIN
// Cap max FPS
if (fps > VIDEO_TRANSCODING_FPS.SOFT_MAX) fps = getClosestFramerateStandard({ fps, type: 'HD_STANDARD' })
return fps
}

View File

@ -513,12 +513,13 @@ const MAX_LOCAL_VIEWER_WATCH_SECTIONS = 100
let CONTACT_FORM_LIFETIME = 60000 * 60 // 1 hour
const VIDEO_TRANSCODING_FPS: VideoTranscodingFPS = {
MIN: 1,
HARD_MIN: 0.1,
SOFT_MIN: 1,
STANDARD: [ 24, 25, 30 ],
HD_STANDARD: [ 50, 60 ],
AUDIO_MERGE: 25,
AVERAGE: 30,
MAX: 60,
SOFT_MAX: 60,
KEEP_ORIGIN_FPS_RESOLUTION_MIN: 720 // We keep the original FPS on high resolutions (720 minimum)
}