diff --git a/lib/src/utils/config.rs b/lib/src/utils/config.rs index 365a2a66..65d35a90 100644 --- a/lib/src/utils/config.rs +++ b/lib/src/utils/config.rs @@ -299,7 +299,12 @@ impl PlayoutConfig { config.processing.width * config.processing.height / 16 ); - config.processing.cmd = Some(vec_strings![ + let buff_size = format!( + "{}k", + (config.processing.width * config.processing.height / 16) / 2 + ); + + let mut process_cmd = vec_strings![ "-pix_fmt", "yuv420p", "-r", @@ -315,20 +320,19 @@ impl PlayoutConfig { "-maxrate", &bitrate, "-bufsize", - &bitrate, - "-c:a", - "mp2", - "-b:a", - "384k", - "-ar", - "48000", - "-ac", - "2", - "-f", - "mpegts", - "-" + &buff_size + ]; + + process_cmd.append(&mut pre_audio_codec( + config.processing.add_loudnorm, + config.processing.loudnorm_ingest, + )); + process_cmd.append(&mut vec_strings![ + "-ar", "48000", "-ac", "2", "-f", "mpegts", "-" ]); + config.processing.cmd = Some(process_cmd); + config.ingest.input_cmd = split(config.ingest.input_param.as_str()); config.out.output_count = 1; @@ -380,3 +384,16 @@ impl Default for PlayoutConfig { Self::new(None) } } + +/// When add_loudnorm is False we use a different audio encoder, +/// s302m has higher quality, but is experimental +/// and works not well together with the loudnorm filter. +fn pre_audio_codec(add_loudnorm: bool, loudnorm_ingest: bool) -> Vec { + let mut codec = vec_strings!["-c:a", "s302m", "-strict", "-2", "-sample_fmt", "s16"]; + + if add_loudnorm || loudnorm_ingest { + codec = vec_strings!["-c:a", "mp2", "-b:a", "384k"]; + } + + codec +}