mirror of
https://github.com/pion/mediadevices.git
synced 2026-04-22 15:57:27 +08:00
Expose LogLevel param for x264 codec (#685)
* Suppress noisy x264 [info] log messages and expose LogLevel param x264's default log level (X264_LOG_INFO) causes it to write encoder stats, CPU capabilities, and profile info to stderr. When used with viam-server, these appear as warn-level logs and create noise. Default to LogWarning to suppress info messages while preserving actual warnings and errors. Expose a LogLevel field on Params so consumers can control the verbosity themselves. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Default to info to avoid breaking change; Fix comment --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -33,6 +33,7 @@ Encoder *enc_new(x264_param_t param, char *preset, int *rc) {
|
||||
free(preset);
|
||||
|
||||
/* Configure non-default params */
|
||||
e->param.i_log_level = param.i_log_level;
|
||||
e->param.i_csp = param.i_csp;
|
||||
e->param.i_width = param.i_width;
|
||||
e->param.i_height = param.i_height;
|
||||
|
||||
@@ -12,8 +12,29 @@ type Params struct {
|
||||
|
||||
// Faster preset has lower CPU usage but lower quality
|
||||
Preset Preset
|
||||
|
||||
// LogLevel controls the verbosity of x264's internal logging.
|
||||
// Messages at this level and above severities will be emitted.
|
||||
// Defaults to LogInfo to match x264's default behavior.
|
||||
LogLevel LogLevel
|
||||
}
|
||||
|
||||
// LogLevel controls which x264 log messages are emitted.
|
||||
type LogLevel int
|
||||
|
||||
const (
|
||||
// LogNone suppresses all log output from x264.
|
||||
LogNone LogLevel = iota
|
||||
// LogError shows only error messages.
|
||||
LogError
|
||||
// LogWarning shows warnings and errors.
|
||||
LogWarning
|
||||
// LogInfo shows info, warnings, and errors (x264 default).
|
||||
LogInfo
|
||||
// LogDebug shows all messages including debug output.
|
||||
LogDebug
|
||||
)
|
||||
|
||||
// Preset represents a set of default configurations from libx264
|
||||
type Preset int
|
||||
|
||||
@@ -36,6 +57,7 @@ func NewParams() (Params, error) {
|
||||
BaseParams: codec.BaseParams{
|
||||
KeyFrameInterval: 60,
|
||||
},
|
||||
LogLevel: LogInfo,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -72,11 +72,29 @@ func newEncoder(r video.Reader, p prop.Media, params Params) (codec.ReadCloser,
|
||||
// Reference: https://code.videolan.org/videolan/x264/-/blob/7923c5818b50a3d8816eed222a7c43b418a73b36/encoder/ratecontrol.c#L657
|
||||
params.BitRate /= 1000
|
||||
|
||||
// Map Go LogLevel to x264 log level constants.
|
||||
// x264 uses: X264_LOG_NONE(-1), X264_LOG_ERROR(0), X264_LOG_WARNING(1),
|
||||
// X264_LOG_INFO(2), X264_LOG_DEBUG(3).
|
||||
x264LogLevel := C.int(C.X264_LOG_INFO)
|
||||
switch params.LogLevel {
|
||||
case LogNone:
|
||||
x264LogLevel = C.X264_LOG_NONE
|
||||
case LogError:
|
||||
x264LogLevel = C.X264_LOG_ERROR
|
||||
case LogWarning:
|
||||
x264LogLevel = C.X264_LOG_WARNING
|
||||
case LogInfo:
|
||||
x264LogLevel = C.X264_LOG_INFO
|
||||
case LogDebug:
|
||||
x264LogLevel = C.X264_LOG_DEBUG
|
||||
}
|
||||
|
||||
param := C.x264_param_t{
|
||||
i_csp: C.X264_CSP_I420,
|
||||
i_width: C.int(p.Width),
|
||||
i_height: C.int(p.Height),
|
||||
i_keyint_max: C.int(params.KeyFrameInterval),
|
||||
i_log_level: x264LogLevel,
|
||||
}
|
||||
param.rc.i_bitrate = C.int(params.BitRate)
|
||||
param.rc.i_vbv_max_bitrate = param.rc.i_bitrate
|
||||
|
||||
Reference in New Issue
Block a user