encoders/ffmpeg: Add support for re-configuration of encoders

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2021-12-03 07:13:08 +01:00
parent 977716d679
commit 19689d1a11
3 changed files with 90 additions and 60 deletions

View file

@ -191,10 +191,22 @@ void ffmpeg_instance::migrate(obs_data_t* settings, uint64_t version)
bool ffmpeg_instance::update(obs_data_t* settings) bool ffmpeg_instance::update(obs_data_t* settings)
{ {
bool support_reconfig = false;
bool support_reconfig_threads = false;
bool support_reconfig_gpu = false;
bool support_reconfig_keyframes = false;
if (_handler) {
support_reconfig = _handler->supports_reconfigure(_factory, support_reconfig_threads, support_reconfig_gpu,
support_reconfig_keyframes);
}
if (!_context->internal) {
// FFmpeg Options // FFmpeg Options
_context->debug = 0; _context->debug = 0;
_context->strict_std_compliance = FF_COMPLIANCE_NORMAL; _context->strict_std_compliance = FF_COMPLIANCE_NORMAL;
}
if (!_context->internal || (support_reconfig && support_reconfig_threads)) {
/// Threading /// Threading
if (!_hwinst) { if (!_hwinst) {
_context->thread_type = 0; _context->thread_type = 0;
@ -214,17 +226,22 @@ bool ffmpeg_instance::update(obs_data_t* settings)
} else { } else {
_context->thread_count = 1; _context->thread_count = 1;
} }
// Frame Delay (Lag In Frames) // Frame Delay (Lag In Frames)
_context->delay = _context->thread_count; _context->delay = _context->thread_count;
} else { } else {
_context->delay = 0; _context->delay = 0;
} }
}
if (!_context->internal || (support_reconfig && support_reconfig_gpu)) {
// Apply GPU Selection // Apply GPU Selection
if (!_hwinst && ::streamfx::ffmpeg::tools::can_hardware_encode(_codec)) { if (!_hwinst && ::streamfx::ffmpeg::tools::can_hardware_encode(_codec)) {
av_opt_set_int(_context, "gpu", (int)obs_data_get_int(settings, ST_KEY_FFMPEG_GPU), AV_OPT_SEARCH_CHILDREN); av_opt_set_int(_context, "gpu", (int)obs_data_get_int(settings, ST_KEY_FFMPEG_GPU), AV_OPT_SEARCH_CHILDREN);
} }
}
if (!_context->internal || (support_reconfig && support_reconfig_keyframes)) {
// Keyframes // Keyframes
if (_handler && _handler->has_keyframe_support(_factory)) { if (_handler && _handler->has_keyframe_support(_factory)) {
// Key-Frame Options // Key-Frame Options
@ -244,7 +261,9 @@ bool ffmpeg_instance::update(obs_data_t* settings)
} }
_context->keyint_min = _context->gop_size; _context->keyint_min = _context->gop_size;
} }
}
if (!_context->internal || support_reconfig) {
// Handler Options // Handler Options
if (_handler) if (_handler)
_handler->update(settings, _codec, _context); _handler->update(settings, _codec, _context);
@ -259,10 +278,11 @@ bool ffmpeg_instance::update(obs_data_t* settings)
// Handler Overrides // Handler Overrides
if (_handler) if (_handler)
_handler->override_update(this, settings); _handler->override_update(this, settings);
}
// Handler Logging // Handler Logging
if (_handler) { if (!_context->internal || support_reconfig) {
DLOG_INFO("[%s] Initializing...", _codec->name); DLOG_INFO("[%s] Configuration:", _codec->name);
DLOG_INFO("[%s] FFmpeg:", _codec->name); DLOG_INFO("[%s] FFmpeg:", _codec->name);
DLOG_INFO("[%s] Custom Settings: %s", _codec->name, DLOG_INFO("[%s] Custom Settings: %s", _codec->name,
obs_data_get_string(settings, ST_KEY_FFMPEG_CUSTOMSETTINGS)); obs_data_get_string(settings, ST_KEY_FFMPEG_CUSTOMSETTINGS));
@ -302,8 +322,11 @@ bool ffmpeg_instance::update(obs_data_t* settings)
} else { } else {
DLOG_INFO("[%s] Distance: %i frames", _codec->name, _context->gop_size); DLOG_INFO("[%s] Distance: %i frames", _codec->name, _context->gop_size);
} }
if (_handler) {
_handler->log_options(settings, _codec, _context); _handler->log_options(settings, _codec, _context);
} }
}
return true; return true;
} }

View file

@ -43,3 +43,8 @@ bool handler::handler::has_pixel_format_support(ffmpeg_factory* instance)
{ {
return (instance->get_avcodec()->pix_fmts != nullptr); return (instance->get_avcodec()->pix_fmts != nullptr);
} }
bool handler::handler::supports_reconfigure(ffmpeg_factory* instance, bool& threads, bool& gpu, bool& keyframes)
{
return false;
}

View file

@ -61,6 +61,8 @@ namespace streamfx::encoder::ffmpeg {
virtual bool has_pixel_format_support(ffmpeg_factory* instance); virtual bool has_pixel_format_support(ffmpeg_factory* instance);
virtual bool supports_reconfigure(ffmpeg_factory* instance, bool& threads, bool& gpu, bool& keyframes);
public /*settings*/: public /*settings*/:
virtual void get_properties(obs_properties_t* props, const AVCodec* codec, AVCodecContext* context, virtual void get_properties(obs_properties_t* props, const AVCodec* codec, AVCodecContext* context,
bool hw_encode){}; bool hw_encode){};