Skip to content

Commit

Permalink
UI: Support preferred video format/space/range in GoLiveApi
Browse files Browse the repository at this point in the history
Also sets Rec. 709/limited defaults for multitrack output.
  • Loading branch information
dsaedtler committed Oct 30, 2024
1 parent dc9370d commit 381132f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
33 changes: 32 additions & 1 deletion UI/models/multitrack-video.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,34 @@ NLOHMANN_JSON_SERIALIZE_ENUM(obs_scale_type, {
{OBS_SCALE_AREA, "OBS_SCALE_AREA"},
})

NLOHMANN_JSON_SERIALIZE_ENUM(video_colorspace, {
{VIDEO_CS_DEFAULT, "VIDEO_CS_DEFAULT"},
{VIDEO_CS_601, "VIDEO_CS_601"},
{VIDEO_CS_709, "VIDEO_CS_709"},
{VIDEO_CS_SRGB, "VIDEO_CS_SRGB"},
{VIDEO_CS_2100_PQ, "VIDEO_CS_2100_PQ"},
{VIDEO_CS_2100_HLG, "VIDEO_CS_2100_HLG"},
})

/* This only includes output formats selectable in advanced settings. */
NLOHMANN_JSON_SERIALIZE_ENUM(video_format, {
{VIDEO_FORMAT_NONE, "VIDEO_FORMAT_NONE"},
{VIDEO_FORMAT_I420, "VIDEO_FORMAT_I420"},
{VIDEO_FORMAT_NV12, "VIDEO_FORMAT_NV12"},
{VIDEO_FORMAT_BGRA, "VIDEO_FORMAT_BGRA"},
{VIDEO_FORMAT_I444, "VIDEO_FORMAT_I444"},
{VIDEO_FORMAT_I010, "VIDEO_FORMAT_I010"},
{VIDEO_FORMAT_P010, "VIDEO_FORMAT_P010"},
{VIDEO_FORMAT_P216, "VIDEO_FORMAT_P216"},
{VIDEO_FORMAT_P416, "VIDEO_FORMAT_P416"},
})

NLOHMANN_JSON_SERIALIZE_ENUM(video_range_type, {
{VIDEO_RANGE_DEFAULT, "VIDEO_RANGE_DEFAULT"},
{VIDEO_RANGE_PARTIAL, "VIDEO_RANGE_PARTIAL"},
{VIDEO_RANGE_FULL, "VIDEO_RANGE_FULL"},
})

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(media_frames_per_second, numerator, denominator)

namespace GoLiveApi {
Expand Down Expand Up @@ -206,10 +234,13 @@ struct VideoEncoderConfiguration {
uint32_t height;
optional<media_frames_per_second> framerate;
optional<obs_scale_type> gpu_scale_type;
optional<video_colorspace> colorspace;
optional<video_range_type> range;
optional<video_format> format;
json settings;

NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(VideoEncoderConfiguration, type, width, height, framerate,
gpu_scale_type, settings)
gpu_scale_type, colorspace, range, format, settings)
};

struct AudioEncoderConfiguration {
Expand Down
7 changes: 3 additions & 4 deletions UI/multitrack-video-output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,6 @@ static void adjust_video_encoder_scaling(const obs_video_info &ovi, obs_encoder_
auto requested_width = encoder_config.width;
auto requested_height = encoder_config.height;

if (ovi.output_width == requested_width || ovi.output_height == requested_height)
return;

if (ovi.base_width < requested_width || ovi.base_height < requested_height) {
blog(LOG_WARNING,
"Requested resolution exceeds canvas/available resolution for encoder %zu: %" PRIu32 "x%" PRIu32
Expand All @@ -187,7 +184,9 @@ static void adjust_video_encoder_scaling(const obs_video_info &ovi, obs_encoder_

obs_encoder_set_scaled_size(video_encoder, requested_width, requested_height);
obs_encoder_set_gpu_scale_type(video_encoder, encoder_config.gpu_scale_type.value_or(OBS_SCALE_BICUBIC));
obs_encoder_set_preferred_video_format(video_encoder, VIDEO_FORMAT_NV12);
obs_encoder_set_preferred_video_format(video_encoder, encoder_config.format.value_or(VIDEO_FORMAT_NV12));
obs_encoder_set_preferred_color_space(video_encoder, encoder_config.colorspace.value_or(VIDEO_CS_709));
obs_encoder_set_preferred_range(video_encoder, encoder_config.range.value_or(VIDEO_RANGE_PARTIAL));
}

static uint32_t closest_divisor(const obs_video_info &ovi, const media_frames_per_second &target_fps)
Expand Down

0 comments on commit 381132f

Please sign in to comment.