aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/ffmpeg-utils.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-11-26 14:45:48 +0100
committerChocobozzz <me@florianbigard.com>2020-11-26 14:45:48 +0100
commitce4a50b99b6aa9f0a6c4ff1023b36bd47ebe8f71 (patch)
tree1e409f33f9967b4d6be81a504cc247076194bf53 /server/helpers/ffmpeg-utils.ts
parentfb4b3f91dc1292c8ecd8a1523b49ff5bfb6035f4 (diff)
downloadPeerTube-ce4a50b99b6aa9f0a6c4ff1023b36bd47ebe8f71.tar.gz
PeerTube-ce4a50b99b6aa9f0a6c4ff1023b36bd47ebe8f71.tar.zst
PeerTube-ce4a50b99b6aa9f0a6c4ff1023b36bd47ebe8f71.zip
Fix "Too many packets buffered for output stream"
And move encoder global options in a global wrapper
Diffstat (limited to 'server/helpers/ffmpeg-utils.ts')
-rw-r--r--server/helpers/ffmpeg-utils.ts35
1 files changed, 23 insertions, 12 deletions
diff --git a/server/helpers/ffmpeg-utils.ts b/server/helpers/ffmpeg-utils.ts
index 3cc062b8c..7c997877c 100644
--- a/server/helpers/ffmpeg-utils.ts
+++ b/server/helpers/ffmpeg-utils.ts
@@ -221,6 +221,8 @@ async function getLiveTranscodingCommand (options: {
221 221
222 command.outputOption('-preset superfast') 222 command.outputOption('-preset superfast')
223 223
224 addDefaultEncoderGlobalParams({ command })
225
224 for (let i = 0; i < resolutions.length; i++) { 226 for (let i = 0; i < resolutions.length; i++) {
225 const resolution = resolutions[i] 227 const resolution = resolutions[i]
226 const resolutionFPS = computeFPS(fps, resolution) 228 const resolutionFPS = computeFPS(fps, resolution)
@@ -345,6 +347,23 @@ export {
345// Default options 347// Default options
346// --------------------------------------------------------------------------- 348// ---------------------------------------------------------------------------
347 349
350function addDefaultEncoderGlobalParams (options: {
351 command: ffmpeg.FfmpegCommand
352}) {
353 const { command } = options
354
355 // avoid issues when transcoding some files: https://trac.ffmpeg.org/ticket/6375
356 command.outputOption('-max_muxing_queue_size 1024')
357 // strip all metadata
358 .outputOption('-map_metadata -1')
359 // NOTE: b-strategy 1 - heuristic algorithm, 16 is optimal B-frames for it
360 .outputOption('-b_strategy 1')
361 // NOTE: Why 16: https://github.com/Chocobozzz/PeerTube/pull/774. b-strategy 2 -> B-frames<16
362 .outputOption('-bf 16')
363 // allows import of source material with incompatible pixel formats (e.g. MJPEG video)
364 .outputOption('-pix_fmt yuv420p')
365}
366
348function addDefaultEncoderParams (options: { 367function addDefaultEncoderParams (options: {
349 command: ffmpeg.FfmpegCommand 368 command: ffmpeg.FfmpegCommand
350 encoder: 'libx264' | string 369 encoder: 'libx264' | string
@@ -355,23 +374,13 @@ function addDefaultEncoderParams (options: {
355 374
356 if (encoder === 'libx264') { 375 if (encoder === 'libx264') {
357 // 3.1 is the minimal resource allocation for our highest supported resolution 376 // 3.1 is the minimal resource allocation for our highest supported resolution
358 command.outputOption('-level 3.1') 377 command.outputOption(buildStreamSuffix('-level:v', streamNum) + ' 3.1')
359 // NOTE: b-strategy 1 - heuristic algorithm, 16 is optimal B-frames for it
360 .outputOption('-b_strategy 1')
361 // NOTE: Why 16: https://github.com/Chocobozzz/PeerTube/pull/774. b-strategy 2 -> B-frames<16
362 .outputOption('-bf 16')
363 // allows import of source material with incompatible pixel formats (e.g. MJPEG video)
364 .outputOption(buildStreamSuffix('-pix_fmt', streamNum) + ' yuv420p')
365 // strip all metadata
366 .outputOption('-map_metadata -1')
367 // avoid issues when transcoding some files: https://trac.ffmpeg.org/ticket/6375
368 .outputOption(buildStreamSuffix('-max_muxing_queue_size', streamNum) + ' 1024')
369 378
370 if (fps) { 379 if (fps) {
371 // Keyframe interval of 2 seconds for faster seeking and resolution switching. 380 // Keyframe interval of 2 seconds for faster seeking and resolution switching.
372 // https://streaminglearningcenter.com/blogs/whats-the-right-keyframe-interval.html 381 // https://streaminglearningcenter.com/blogs/whats-the-right-keyframe-interval.html
373 // https://superuser.com/a/908325 382 // https://superuser.com/a/908325
374 command.outputOption('-g ' + (fps * 2)) 383 command.outputOption(buildStreamSuffix('-g:v', streamNum) + ' ' + (fps * 2))
375 } 384 }
376 } 385 }
377} 386}
@@ -537,6 +546,8 @@ async function presetVideo (
537 .format('mp4') 546 .format('mp4')
538 .outputOption('-movflags faststart') 547 .outputOption('-movflags faststart')
539 548
549 addDefaultEncoderGlobalParams({ command })
550
540 // Audio encoder 551 // Audio encoder
541 const parsedAudio = await getAudioStream(input) 552 const parsedAudio = await getAudioStream(input)
542 553