diff options
Diffstat (limited to 'server/helpers')
-rw-r--r-- | server/helpers/custom-validators/videos.ts | 5 | ||||
-rw-r--r-- | server/helpers/ffmpeg-utils.ts | 25 |
2 files changed, 23 insertions, 7 deletions
diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index ae392f8c2..672f06dc0 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts | |||
@@ -118,6 +118,10 @@ function isVideoFileResolutionValid (value: string) { | |||
118 | return exists(value) && validator.isInt(value + '') | 118 | return exists(value) && validator.isInt(value + '') |
119 | } | 119 | } |
120 | 120 | ||
121 | function isVideoFPSResolutionValid (value: string) { | ||
122 | return value === null || validator.isInt(value + '') | ||
123 | } | ||
124 | |||
121 | function isVideoFileSizeValid (value: string) { | 125 | function isVideoFileSizeValid (value: string) { |
122 | return exists(value) && validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.FILE_SIZE) | 126 | return exists(value) && validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.FILE_SIZE) |
123 | } | 127 | } |
@@ -182,6 +186,7 @@ export { | |||
182 | isVideoFileInfoHashValid, | 186 | isVideoFileInfoHashValid, |
183 | isVideoNameValid, | 187 | isVideoNameValid, |
184 | isVideoTagsValid, | 188 | isVideoTagsValid, |
189 | isVideoFPSResolutionValid, | ||
185 | isScheduleVideoUpdatePrivacyValid, | 190 | isScheduleVideoUpdatePrivacyValid, |
186 | isVideoAbuseReasonValid, | 191 | isVideoAbuseReasonValid, |
187 | isVideoFile, | 192 | isVideoFile, |
diff --git a/server/helpers/ffmpeg-utils.ts b/server/helpers/ffmpeg-utils.ts index bfc942fa3..4086335d7 100644 --- a/server/helpers/ffmpeg-utils.ts +++ b/server/helpers/ffmpeg-utils.ts | |||
@@ -26,7 +26,7 @@ async function getVideoFileFPS (path: string) { | |||
26 | if (!frames || !seconds) continue | 26 | if (!frames || !seconds) continue |
27 | 27 | ||
28 | const result = parseInt(frames, 10) / parseInt(seconds, 10) | 28 | const result = parseInt(frames, 10) / parseInt(seconds, 10) |
29 | if (result > 0) return result | 29 | if (result > 0) return Math.round(result) |
30 | } | 30 | } |
31 | 31 | ||
32 | return 0 | 32 | return 0 |
@@ -83,8 +83,6 @@ type TranscodeOptions = { | |||
83 | 83 | ||
84 | function transcode (options: TranscodeOptions) { | 84 | function transcode (options: TranscodeOptions) { |
85 | return new Promise<void>(async (res, rej) => { | 85 | return new Promise<void>(async (res, rej) => { |
86 | const fps = await getVideoFileFPS(options.inputPath) | ||
87 | |||
88 | let command = ffmpeg(options.inputPath) | 86 | let command = ffmpeg(options.inputPath) |
89 | .output(options.outputPath) | 87 | .output(options.outputPath) |
90 | .videoCodec('libx264') | 88 | .videoCodec('libx264') |
@@ -92,14 +90,27 @@ function transcode (options: TranscodeOptions) { | |||
92 | .outputOption('-movflags faststart') | 90 | .outputOption('-movflags faststart') |
93 | // .outputOption('-crf 18') | 91 | // .outputOption('-crf 18') |
94 | 92 | ||
95 | // Our player has some FPS limits | 93 | let fps = await getVideoFileFPS(options.inputPath) |
96 | if (fps > VIDEO_TRANSCODING_FPS.MAX) command = command.withFPS(VIDEO_TRANSCODING_FPS.MAX) | ||
97 | else if (fps < VIDEO_TRANSCODING_FPS.MIN) command = command.withFPS(VIDEO_TRANSCODING_FPS.MIN) | ||
98 | |||
99 | if (options.resolution !== undefined) { | 94 | if (options.resolution !== undefined) { |
100 | // '?x720' or '720x?' for example | 95 | // '?x720' or '720x?' for example |
101 | const size = options.isPortraitMode === true ? `${options.resolution}x?` : `?x${options.resolution}` | 96 | const size = options.isPortraitMode === true ? `${options.resolution}x?` : `?x${options.resolution}` |
102 | command = command.size(size) | 97 | command = command.size(size) |
98 | |||
99 | // On small/medium resolutions, limit FPS | ||
100 | if ( | ||
101 | options.resolution < VIDEO_TRANSCODING_FPS.KEEP_ORIGIN_FPS_RESOLUTION_MIN && | ||
102 | fps > VIDEO_TRANSCODING_FPS.AVERAGE | ||
103 | ) { | ||
104 | fps = VIDEO_TRANSCODING_FPS.AVERAGE | ||
105 | } | ||
106 | } | ||
107 | |||
108 | if (fps) { | ||
109 | // Hard FPS limits | ||
110 | if (fps > VIDEO_TRANSCODING_FPS.MAX) fps = VIDEO_TRANSCODING_FPS.MAX | ||
111 | else if (fps < VIDEO_TRANSCODING_FPS.MIN) fps = VIDEO_TRANSCODING_FPS.MIN | ||
112 | |||
113 | command = command.withFPS(fps) | ||
103 | } | 114 | } |
104 | 115 | ||
105 | command | 116 | command |