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.ts25
1 files changed, 18 insertions, 7 deletions
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
84function transcode (options: TranscodeOptions) { 84function 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