aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/helpers/ffmpeg-utils.ts18
-rw-r--r--server/lib/transcoding/video-transcoding-profiles.ts27
2 files changed, 26 insertions, 19 deletions
diff --git a/server/helpers/ffmpeg-utils.ts b/server/helpers/ffmpeg-utils.ts
index ab29d4691..78ee5fa7f 100644
--- a/server/helpers/ffmpeg-utils.ts
+++ b/server/helpers/ffmpeg-utils.ts
@@ -287,8 +287,8 @@ async function getLiveTranscodingCommand (options: {
287 addDefaultEncoderParams({ command, encoder: builderResult.encoder, fps: resolutionFPS, streamNum: i }) 287 addDefaultEncoderParams({ command, encoder: builderResult.encoder, fps: resolutionFPS, streamNum: i })
288 288
289 logger.debug( 289 logger.debug(
290 'Apply ffmpeg live video params from %s using %s profile.', builderResult.encoder, profile, builderResult, 290 'Apply ffmpeg live video params from %s using %s profile.', builderResult.encoder, profile,
291 { fps: resolutionFPS, resolution, ...lTags() } 291 { builderResult, fps: resolutionFPS, resolution, ...lTags() }
292 ) 292 )
293 293
294 command.outputOption(`${buildStreamSuffix('-c:v', i)} ${builderResult.encoder}`) 294 command.outputOption(`${buildStreamSuffix('-c:v', i)} ${builderResult.encoder}`)
@@ -314,8 +314,8 @@ async function getLiveTranscodingCommand (options: {
314 addDefaultEncoderParams({ command, encoder: builderResult.encoder, fps: resolutionFPS, streamNum: i }) 314 addDefaultEncoderParams({ command, encoder: builderResult.encoder, fps: resolutionFPS, streamNum: i })
315 315
316 logger.debug( 316 logger.debug(
317 'Apply ffmpeg live audio params from %s using %s profile.', builderResult.encoder, profile, builderResult, 317 'Apply ffmpeg live audio params from %s using %s profile.', builderResult.encoder, profile,
318 { fps: resolutionFPS, resolution, ...lTags() } 318 { builderResult, fps: resolutionFPS, resolution, ...lTags() }
319 ) 319 )
320 320
321 command.outputOption(`${buildStreamSuffix('-c:a', i)} ${builderResult.encoder}`) 321 command.outputOption(`${buildStreamSuffix('-c:a', i)} ${builderResult.encoder}`)
@@ -368,10 +368,6 @@ function addDefaultEncoderGlobalParams (options: {
368 command.outputOption('-max_muxing_queue_size 1024') 368 command.outputOption('-max_muxing_queue_size 1024')
369 // strip all metadata 369 // strip all metadata
370 .outputOption('-map_metadata -1') 370 .outputOption('-map_metadata -1')
371 // NOTE: b-strategy 1 - heuristic algorithm, 16 is optimal B-frames for it
372 .outputOption('-b_strategy 1')
373 // NOTE: Why 16: https://github.com/Chocobozzz/PeerTube/pull/774. b-strategy 2 -> B-frames<16
374 .outputOption('-bf 16')
375 // allows import of source material with incompatible pixel formats (e.g. MJPEG video) 371 // allows import of source material with incompatible pixel formats (e.g. MJPEG video)
376 .outputOption('-pix_fmt yuv420p') 372 .outputOption('-pix_fmt yuv420p')
377} 373}
@@ -627,8 +623,8 @@ async function presetVideo (options: {
627 623
628 logger.debug( 624 logger.debug(
629 'Apply ffmpeg params from %s for %s stream of input %s using %s profile.', 625 'Apply ffmpeg params from %s for %s stream of input %s using %s profile.',
630 builderResult.encoder, streamType, input, profile, builderResult, 626 builderResult.encoder, streamType, input, profile,
631 { resolution, fps, ...lTags() } 627 { builderResult, resolution, fps, ...lTags() }
632 ) 628 )
633 629
634 if (streamType === 'video') { 630 if (streamType === 'video') {
@@ -734,7 +730,7 @@ async function runCommand (options: {
734 command.on('start', cmdline => { shellCommand = cmdline }) 730 command.on('start', cmdline => { shellCommand = cmdline })
735 731
736 command.on('error', (err, stdout, stderr) => { 732 command.on('error', (err, stdout, stderr) => {
737 if (silent !== true) logger.error('Error in ffmpeg.', { stdout, stderr, ...lTags() }) 733 if (silent !== true) logger.error('Error in ffmpeg.', { stdout, stderr, shellCommand, ...lTags() })
738 734
739 rej(err) 735 rej(err)
740 }) 736 })
diff --git a/server/lib/transcoding/video-transcoding-profiles.ts b/server/lib/transcoding/video-transcoding-profiles.ts
index 34a364415..dcc8d4c5c 100644
--- a/server/lib/transcoding/video-transcoding-profiles.ts
+++ b/server/lib/transcoding/video-transcoding-profiles.ts
@@ -23,10 +23,9 @@ const defaultX264VODOptionsBuilder: EncoderOptionsBuilder = (options: EncoderOpt
23 23
24 return { 24 return {
25 outputOptions: [ 25 outputOptions: [
26 `-preset veryfast`, 26 ...getCommonOutputOptions(targetBitrate),
27 `-r ${fps}`, 27
28 `-maxrate ${targetBitrate}`, 28 `-r ${fps}`
29 `-bufsize ${targetBitrate * 2}`
30 ] 29 ]
31 } 30 }
32} 31}
@@ -38,11 +37,10 @@ const defaultX264LiveOptionsBuilder: EncoderOptionsBuilder = (options: EncoderOp
38 37
39 return { 38 return {
40 outputOptions: [ 39 outputOptions: [
41 `-preset veryfast`, 40 ...getCommonOutputOptions(targetBitrate),
41
42 `${buildStreamSuffix('-r:v', streamNum)} ${fps}`, 42 `${buildStreamSuffix('-r:v', streamNum)} ${fps}`,
43 `${buildStreamSuffix('-b:v', streamNum)} ${targetBitrate}`, 43 `${buildStreamSuffix('-b:v', streamNum)} ${targetBitrate}`
44 `-maxrate ${targetBitrate}`,
45 `-bufsize ${targetBitrate * 2}`
46 ] 44 ]
47 } 45 }
48} 46}
@@ -257,3 +255,16 @@ function capBitrate (inputBitrate: number, targetBitrate: number) {
257 255
258 return Math.min(targetBitrate, inputBitrateWithMargin) 256 return Math.min(targetBitrate, inputBitrateWithMargin)
259} 257}
258
259function getCommonOutputOptions (targetBitrate: number) {
260 return [
261 `-preset veryfast`,
262 `-maxrate ${targetBitrate}`,
263 `-bufsize ${targetBitrate * 2}`,
264
265 // NOTE: b-strategy 1 - heuristic algorithm, 16 is optimal B-frames for it
266 `-b_strategy 1`,
267 // NOTE: Why 16: https://github.com/Chocobozzz/PeerTube/pull/774. b-strategy 2 -> B-frames<16
268 `-bf 16`
269 ]
270}