From 73ac96ac7cc46dbe6be086af51fcdc96bc3b390e Mon Sep 17 00:00:00 2001 From: pkv Date: Thu, 16 Apr 2020 21:21:07 +0200 Subject: [PATCH] obs-ffmpeg: Allow video headers repetition in IDR and bitstream for jim-nvenc This commit adds a repeat_headers setting which will allow sps/pps repetition and AUDs(access unit delimiters) . Repetition is ensured by h264config->repeatSPSPPS & h264config->disableSPSPPS; the two parameters are set by nvenc to true on default. When video headers repetition is required, we set the second in jim-nvenc to false so that SPS/PPS are written into bitstream. The first parameter could be omitted but is exposed since repetition of video headers might not be required. When headers repetition is enabled, we also enable AUD to facilitate decoding. Typically the video headers repetition will be useful for mpegts and DVB broadcast decoders. --- plugins/obs-ffmpeg/jim-nvenc.c | 8 ++++++++ plugins/obs-ffmpeg/obs-ffmpeg-nvenc.c | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/plugins/obs-ffmpeg/jim-nvenc.c b/plugins/obs-ffmpeg/jim-nvenc.c index 097db6432..b112a2f2c 100644 --- a/plugins/obs-ffmpeg/jim-nvenc.c +++ b/plugins/obs-ffmpeg/jim-nvenc.c @@ -426,6 +426,14 @@ static bool init_encoder(struct nvenc_data *enc, obs_data_t *settings) config->gopLength = gop_size; config->frameIntervalP = 1 + bf; h264_config->idrPeriod = gop_size; + + bool repeat_headers = obs_data_get_bool(settings, "repeat_headers"); + if (repeat_headers) { + h264_config->repeatSPSPPS = 1; + h264_config->disableSPSPPS = 0; + h264_config->outputAUD = 1; + } + vui_params->videoSignalTypePresentFlag = 1; vui_params->videoFullRangeFlag = (voi->range == VIDEO_RANGE_FULL); vui_params->colourDescriptionPresentFlag = 1; diff --git a/plugins/obs-ffmpeg/obs-ffmpeg-nvenc.c b/plugins/obs-ffmpeg/obs-ffmpeg-nvenc.c index 74480a797..b667665ab 100644 --- a/plugins/obs-ffmpeg/obs-ffmpeg-nvenc.c +++ b/plugins/obs-ffmpeg/obs-ffmpeg-nvenc.c @@ -477,6 +477,7 @@ void nvenc_defaults(obs_data_t *settings) obs_data_set_default_bool(settings, "psycho_aq", true); obs_data_set_default_int(settings, "gpu", 0); obs_data_set_default_int(settings, "bf", 2); + obs_data_set_default_bool(settings, "repeat_headers", false); } static bool rate_control_modified(obs_properties_t *ppts, obs_property_t *p, @@ -576,6 +577,9 @@ obs_properties_t *nvenc_properties_internal(bool ffmpeg) obs_module_text("NVENC.PsychoVisualTuning")); obs_property_set_long_description( p, obs_module_text("NVENC.PsychoVisualTuning.ToolTip")); + p = obs_properties_add_bool(props, "repeat_headers", + "repeat_headers"); + obs_property_set_visible(p, false); } obs_properties_add_int(props, "gpu", obs_module_text("GPU"), 0, 8, 1);