Fix "Too many packets buffered for output stream"

And move encoder global options in a global wrapper
This commit is contained in:
Chocobozzz 2020-11-26 14:45:48 +01:00
parent fb4b3f91dc
commit ce4a50b99b
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
1 changed files with 23 additions and 12 deletions

View File

@ -221,6 +221,8 @@ async function getLiveTranscodingCommand (options: {
command.outputOption('-preset superfast') command.outputOption('-preset superfast')
addDefaultEncoderGlobalParams({ command })
for (let i = 0; i < resolutions.length; i++) { for (let i = 0; i < resolutions.length; i++) {
const resolution = resolutions[i] const resolution = resolutions[i]
const resolutionFPS = computeFPS(fps, resolution) const resolutionFPS = computeFPS(fps, resolution)
@ -345,6 +347,23 @@ export {
// Default options // Default options
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
function addDefaultEncoderGlobalParams (options: {
command: ffmpeg.FfmpegCommand
}) {
const { command } = options
// avoid issues when transcoding some files: https://trac.ffmpeg.org/ticket/6375
command.outputOption('-max_muxing_queue_size 1024')
// strip all metadata
.outputOption('-map_metadata -1')
// NOTE: b-strategy 1 - heuristic algorithm, 16 is optimal B-frames for it
.outputOption('-b_strategy 1')
// NOTE: Why 16: https://github.com/Chocobozzz/PeerTube/pull/774. b-strategy 2 -> B-frames<16
.outputOption('-bf 16')
// allows import of source material with incompatible pixel formats (e.g. MJPEG video)
.outputOption('-pix_fmt yuv420p')
}
function addDefaultEncoderParams (options: { function addDefaultEncoderParams (options: {
command: ffmpeg.FfmpegCommand command: ffmpeg.FfmpegCommand
encoder: 'libx264' | string encoder: 'libx264' | string
@ -355,23 +374,13 @@ function addDefaultEncoderParams (options: {
if (encoder === 'libx264') { if (encoder === 'libx264') {
// 3.1 is the minimal resource allocation for our highest supported resolution // 3.1 is the minimal resource allocation for our highest supported resolution
command.outputOption('-level 3.1') command.outputOption(buildStreamSuffix('-level:v', streamNum) + ' 3.1')
// NOTE: b-strategy 1 - heuristic algorithm, 16 is optimal B-frames for it
.outputOption('-b_strategy 1')
// NOTE: Why 16: https://github.com/Chocobozzz/PeerTube/pull/774. b-strategy 2 -> B-frames<16
.outputOption('-bf 16')
// allows import of source material with incompatible pixel formats (e.g. MJPEG video)
.outputOption(buildStreamSuffix('-pix_fmt', streamNum) + ' yuv420p')
// strip all metadata
.outputOption('-map_metadata -1')
// avoid issues when transcoding some files: https://trac.ffmpeg.org/ticket/6375
.outputOption(buildStreamSuffix('-max_muxing_queue_size', streamNum) + ' 1024')
if (fps) { if (fps) {
// Keyframe interval of 2 seconds for faster seeking and resolution switching. // Keyframe interval of 2 seconds for faster seeking and resolution switching.
// https://streaminglearningcenter.com/blogs/whats-the-right-keyframe-interval.html // https://streaminglearningcenter.com/blogs/whats-the-right-keyframe-interval.html
// https://superuser.com/a/908325 // https://superuser.com/a/908325
command.outputOption('-g ' + (fps * 2)) command.outputOption(buildStreamSuffix('-g:v', streamNum) + ' ' + (fps * 2))
} }
} }
} }
@ -537,6 +546,8 @@ async function presetVideo (
.format('mp4') .format('mp4')
.outputOption('-movflags faststart') .outputOption('-movflags faststart')
addDefaultEncoderGlobalParams({ command })
// Audio encoder // Audio encoder
const parsedAudio = await getAudioStream(input) const parsedAudio = await getAudioStream(input)