Skip to content

Commit 1a2f8c2

Browse files
Huts, RomanRytoEX
Huts, Roman
authored andcommitted
obs-ffmpeg: Add AMD AV1 B-frame support
1 parent 7f94906 commit 1a2f8c2

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

plugins/obs-ffmpeg/texture-amf.cpp

+25-2
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,7 @@ static obs_properties_t *amf_properties_internal(amf_codec_type codec)
11571157
#undef add_profile
11581158
}
11591159

1160-
if (amf_codec_type::AVC == codec) {
1160+
if (amf_codec_type::AVC == codec || amf_codec_type::AV1 == codec) {
11611161
obs_properties_add_int(props, "bf", obs_module_text("BFrames"), 0, 5, 1);
11621162
}
11631163

@@ -1970,6 +1970,15 @@ static bool amf_av1_init(void *data, obs_data_t *settings)
19701970
const char *preset = obs_data_get_string(settings, "preset");
19711971
const char *profile = obs_data_get_string(settings, "profile");
19721972
const char *rc_str = obs_data_get_string(settings, "rate_control");
1973+
int64_t bf = obs_data_get_int(settings, "bf");
1974+
1975+
if (enc->bframes_supported) {
1976+
set_av1_property(enc, MAX_CONSECUTIVE_BPICTURES, bf);
1977+
set_av1_property(enc, B_PIC_PATTERN, bf);
1978+
} else if (bf != 0) {
1979+
warn("B-Frames set to %lld but b-frames are not supported by this device", bf);
1980+
bf = 0;
1981+
}
19731982

19741983
int rc = get_av1_rate_control(rc_str);
19751984
set_av1_property(enc, RATE_CONTROL_METHOD, rc);
@@ -2003,10 +2012,11 @@ static bool amf_av1_init(void *data, obs_data_t *settings)
20032012
"\tkeyint: %d\n"
20042013
"\tpreset: %s\n"
20052014
"\tprofile: %s\n"
2015+
"\tb-frames: %d\n"
20062016
"\twidth: %d\n"
20072017
"\theight: %d\n"
20082018
"\tparams: %s",
2009-
rc_str, bitrate, qp, gop_size, preset, profile, enc->cx, enc->cy, ffmpeg_opts);
2019+
rc_str, bitrate, qp, gop_size, preset, profile, bf, enc->cx, enc->cy, ffmpeg_opts);
20102020

20112021
return true;
20122022
}
@@ -2021,6 +2031,7 @@ static void amf_av1_create_internal(amf_base *enc, obs_data_t *settings)
20212031
AMFCapsPtr caps;
20222032
AMF_RESULT res = enc->amf_encoder->GetCaps(&caps);
20232033
if (res == AMF_OK) {
2034+
caps->GetProperty(AMF_VIDEO_ENCODER_AV1_CAP_BFRAMES, &enc->bframes_supported);
20242035
caps->GetProperty(AMF_VIDEO_ENCODER_AV1_CAP_MAX_THROUGHPUT, &enc->max_throughput);
20252036
caps->GetProperty(AMF_VIDEO_ENCODER_AV1_CAP_REQUESTED_THROUGHPUT, &enc->requested_throughput);
20262037
/* For some reason there's no specific CAP for AV1, but should always be supported */
@@ -2053,6 +2064,17 @@ static void amf_av1_create_internal(amf_base *enc, obs_data_t *settings)
20532064
res = enc->amf_encoder->GetProperty(AMF_VIDEO_ENCODER_AV1_EXTRA_DATA, &p);
20542065
if (res == AMF_OK && p.type == AMF_VARIANT_INTERFACE)
20552066
enc->header = AMFBufferPtr(p.pInterface);
2067+
2068+
if (enc->bframes_supported) {
2069+
amf_int64 b_frames = 0;
2070+
amf_int64 b_max = 0;
2071+
2072+
if (get_av1_property(enc, B_PIC_PATTERN, &b_frames) &&
2073+
get_av1_property(enc, MAX_CONSECUTIVE_BPICTURES, &b_max))
2074+
enc->dts_offset = b_frames + 1;
2075+
else
2076+
enc->dts_offset = 0;
2077+
}
20562078
}
20572079

20582080
static void *amf_av1_create_texencode(obs_data_t *settings, obs_encoder_t *encoder)
@@ -2127,6 +2149,7 @@ static void amf_av1_defaults(obs_data_t *settings)
21272149
obs_data_set_default_string(settings, "rate_control", "CBR");
21282150
obs_data_set_default_string(settings, "preset", "quality");
21292151
obs_data_set_default_string(settings, "profile", "high");
2152+
obs_data_set_default_int(settings, "bf", 2);
21302153
}
21312154

21322155
static void register_av1()

0 commit comments

Comments
 (0)