mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-11-27 22:03:01 +00:00
encoders/ffmpeg: Add support for re-configuration of encoders
This commit is contained in:
parent
977716d679
commit
19689d1a11
3 changed files with 90 additions and 60 deletions
|
@ -191,10 +191,22 @@ void ffmpeg_instance::migrate(obs_data_t* settings, uint64_t version)
|
|||
|
||||
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
|
||||
_context->debug = 0;
|
||||
_context->strict_std_compliance = FF_COMPLIANCE_NORMAL;
|
||||
}
|
||||
|
||||
if (!_context->internal || (support_reconfig && support_reconfig_threads)) {
|
||||
/// Threading
|
||||
if (!_hwinst) {
|
||||
_context->thread_type = 0;
|
||||
|
@ -214,17 +226,22 @@ bool ffmpeg_instance::update(obs_data_t* settings)
|
|||
} else {
|
||||
_context->thread_count = 1;
|
||||
}
|
||||
|
||||
// Frame Delay (Lag In Frames)
|
||||
_context->delay = _context->thread_count;
|
||||
} else {
|
||||
_context->delay = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!_context->internal || (support_reconfig && support_reconfig_gpu)) {
|
||||
// Apply GPU Selection
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
if (!_context->internal || (support_reconfig && support_reconfig_keyframes)) {
|
||||
// Keyframes
|
||||
if (_handler && _handler->has_keyframe_support(_factory)) {
|
||||
// Key-Frame Options
|
||||
|
@ -244,7 +261,9 @@ bool ffmpeg_instance::update(obs_data_t* settings)
|
|||
}
|
||||
_context->keyint_min = _context->gop_size;
|
||||
}
|
||||
}
|
||||
|
||||
if (!_context->internal || support_reconfig) {
|
||||
// Handler Options
|
||||
if (_handler)
|
||||
_handler->update(settings, _codec, _context);
|
||||
|
@ -259,10 +278,11 @@ bool ffmpeg_instance::update(obs_data_t* settings)
|
|||
// Handler Overrides
|
||||
if (_handler)
|
||||
_handler->override_update(this, settings);
|
||||
}
|
||||
|
||||
// Handler Logging
|
||||
if (_handler) {
|
||||
DLOG_INFO("[%s] Initializing...", _codec->name);
|
||||
if (!_context->internal || support_reconfig) {
|
||||
DLOG_INFO("[%s] Configuration:", _codec->name);
|
||||
DLOG_INFO("[%s] FFmpeg:", _codec->name);
|
||||
DLOG_INFO("[%s] Custom Settings: %s", _codec->name,
|
||||
obs_data_get_string(settings, ST_KEY_FFMPEG_CUSTOMSETTINGS));
|
||||
|
@ -302,8 +322,11 @@ bool ffmpeg_instance::update(obs_data_t* settings)
|
|||
} else {
|
||||
DLOG_INFO("[%s] Distance: %i frames", _codec->name, _context->gop_size);
|
||||
}
|
||||
|
||||
if (_handler) {
|
||||
_handler->log_options(settings, _codec, _context);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -43,3 +43,8 @@ bool handler::handler::has_pixel_format_support(ffmpeg_factory* instance)
|
|||
{
|
||||
return (instance->get_avcodec()->pix_fmts != nullptr);
|
||||
}
|
||||
|
||||
bool handler::handler::supports_reconfigure(ffmpeg_factory* instance, bool& threads, bool& gpu, bool& keyframes)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -61,6 +61,8 @@ namespace streamfx::encoder::ffmpeg {
|
|||
|
||||
virtual bool has_pixel_format_support(ffmpeg_factory* instance);
|
||||
|
||||
virtual bool supports_reconfigure(ffmpeg_factory* instance, bool& threads, bool& gpu, bool& keyframes);
|
||||
|
||||
public /*settings*/:
|
||||
virtual void get_properties(obs_properties_t* props, const AVCodec* codec, AVCodecContext* context,
|
||||
bool hw_encode){};
|
||||
|
|
Loading…
Reference in a new issue