1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
|
diff --git a/plugins/obs-ffmpeg/obs-ffmpeg-vaapi.c b/plugins/obs-ffmpeg/obs-ffmpeg-vaapi.c
index 445c5a792..a7a96d819 100644
--- a/plugins/obs-ffmpeg/obs-ffmpeg-vaapi.c
+++ b/plugins/obs-ffmpeg/obs-ffmpeg-vaapi.c
@@ -69,10 +69,35 @@ struct vaapi_encoder {
bool initialized;
};
-static const char *vaapi_getname(void *unused)
+/* Identify codecs, and some default values */
+struct type_data {
+ const int id;
+ const int profile;
+ const int level;
+ const char *name;
+ const char *rate_control;
+};
+
+static struct type_data h264_type = {
+ .id = AV_CODEC_ID_H264,
+ .profile = FF_PROFILE_H264_CONSTRAINED_BASELINE,
+ .level = 40,
+ .rate_control = "CBR",
+ .name = "FFMPEG VAAPI",
+};
+
+static struct type_data hevc_type = {
+ .id = AV_CODEC_ID_HEVC,
+ .profile = FF_PROFILE_HEVC_MAIN,
+ .level = 0,
+ .name = "FFMPEG VAAPI (hevc)",
+ .rate_control = "CQP",
+};
+
+static const char *vaapi_getname(void *type_data)
{
- UNUSED_PARAMETER(unused);
- return "FFMPEG VAAPI";
+ struct type_data *data = type_data;
+ return data->name;
}
static inline bool valid_format(enum video_format format)
@@ -170,15 +195,15 @@ typedef struct {
bool maxrate;
} rc_mode_t;
+/* Set "allowed" options per Rate Control */
+static const rc_mode_t RC_MODES[] = {
+ {.name = "CBR", .qp = false, .bitrate = true, .maxrate = false},
+ {.name = "CQP", .qp = true, .bitrate = false, .maxrate = false},
+ {.name = "VBR", .qp = false, .bitrate = true, .maxrate = true},
+ NULL};
+
static const rc_mode_t *get_rc_mode(const char *name)
{
- /* Set "allowed" options per Rate Control */
- static const rc_mode_t RC_MODES[] = {
- {.name = "CBR", .qp = false, .bitrate = true, .maxrate = false},
- {.name = "CQP", .qp = true, .bitrate = false, .maxrate = false},
- {.name = "VBR", .qp = false, .bitrate = true, .maxrate = true},
- NULL};
-
const rc_mode_t *rc_mode = RC_MODES;
while (!!rc_mode && strcmp(rc_mode->name, name) != 0)
@@ -278,6 +303,7 @@ static bool vaapi_update(void *data, obs_data_t *settings)
info("settings:\n"
"\tdevice: %s\n"
+ "\tcodec: %s\n"
"\trate_control: %s\n"
"\tprofile: %d\n"
"\tlevel: %d\n"
@@ -288,9 +314,9 @@ static bool vaapi_update(void *data, obs_data_t *settings)
"\twidth: %d\n"
"\theight: %d\n"
"\tb-frames: %d\n",
- device, rate_control, profile, level, qp, bitrate, maxrate,
- enc->context->gop_size, enc->context->width, enc->context->height,
- enc->context->max_b_frames);
+ device, enc->vaapi->name, rate_control, profile, level, qp,
+ bitrate, maxrate, enc->context->gop_size, enc->context->width,
+ enc->context->height, enc->context->max_b_frames);
return vaapi_init_codec(enc, device);
}
@@ -344,9 +370,12 @@ static void *vaapi_create(obs_data_t *settings, obs_encoder_t *encoder)
if (vaapi_codec == AV_CODEC_ID_H264) {
enc->vaapi = avcodec_find_encoder_by_name("h264_vaapi");
+ enc->first_packet = true;
+ }
+ if (vaapi_codec == AV_CODEC_ID_HEVC) {
+ enc->vaapi = avcodec_find_encoder_by_name("hevc_vaapi");
+ enc->first_packet = false;
}
-
- enc->first_packet = true;
blog(LOG_INFO, "---------------------------------");
@@ -482,7 +511,10 @@ static bool vaapi_encode(void *data, struct encoder_frame *frame,
packet->data = enc->buffer.array;
packet->size = enc->buffer.num;
packet->type = OBS_ENCODER_VIDEO;
- packet->keyframe = obs_avc_keyframe(packet->data, packet->size);
+ packet->keyframe =
+ enc->vaapi->id == AV_CODEC_ID_H264
+ ? obs_avc_keyframe(packet->data, packet->size)
+ : av_pkt.flags & AV_PKT_FLAG_KEY;
*received_packet = true;
} else {
*received_packet = false;
@@ -503,19 +535,20 @@ static void set_visible(obs_properties_t *ppts, const char *name, bool visible)
obs_property_set_visible(p, visible);
}
-static void vaapi_defaults(obs_data_t *settings)
+static void vaapi_defaults(obs_data_t *settings, void *type_data)
{
+ struct type_data *codec = type_data;
+
obs_data_set_default_string(settings, "vaapi_device",
"/dev/dri/renderD128");
- obs_data_set_default_int(settings, "vaapi_codec", AV_CODEC_ID_H264);
- obs_data_set_default_int(settings, "profile",
- FF_PROFILE_H264_CONSTRAINED_BASELINE);
- obs_data_set_default_int(settings, "level", 40);
+ obs_data_set_default_int(settings, "vaapi_codec", codec->id);
+ obs_data_set_default_int(settings, "profile", codec->profile);
+ obs_data_set_default_int(settings, "level", codec->level);
obs_data_set_default_int(settings, "bitrate", 2500);
obs_data_set_default_int(settings, "keyint_sec", 0);
obs_data_set_default_int(settings, "bf", 0);
- obs_data_set_default_int(settings, "rendermode", 0);
- obs_data_set_default_string(settings, "rate_control", "CBR");
+ obs_data_set_default_string(settings, "rate_control",
+ codec->rate_control);
obs_data_set_default_int(settings, "qp", 20);
obs_data_set_default_int(settings, "maxrate", 0);
}
@@ -538,9 +571,13 @@ static bool rate_control_modified(obs_properties_t *ppts, obs_property_t *p,
return true;
}
-static obs_properties_t *vaapi_properties(void *unused)
+static obs_properties_t *vaapi_properties(void *unused, void *type_data)
{
UNUSED_PARAMETER(unused);
+ struct type_data *codec = type_data;
+ struct dstr name;
+
+ dstr_init(&name);
obs_properties_t *props = obs_properties_create();
obs_property_t *list;
@@ -561,43 +598,46 @@ static obs_properties_t *vaapi_properties(void *unused)
}
}
- list = obs_properties_add_list(props, "vaapi_codec",
- obs_module_text("VAAPI.Codec"),
- OBS_COMBO_TYPE_LIST,
- OBS_COMBO_FORMAT_INT);
-
- obs_property_list_add_int(list, "H.264 (default)", AV_CODEC_ID_H264);
-
- list = obs_properties_add_list(props, "profile",
- obs_module_text("Profile"),
- OBS_COMBO_TYPE_LIST,
- OBS_COMBO_FORMAT_INT);
- obs_property_list_add_int(list, "Constrained Baseline (default)",
- FF_PROFILE_H264_CONSTRAINED_BASELINE);
- obs_property_list_add_int(list, "Main", FF_PROFILE_H264_MAIN);
- obs_property_list_add_int(list, "High", FF_PROFILE_H264_HIGH);
-
- list = obs_properties_add_list(props, "level", obs_module_text("Level"),
- OBS_COMBO_TYPE_LIST,
- OBS_COMBO_FORMAT_INT);
- obs_property_list_add_int(list, "Auto", FF_LEVEL_UNKNOWN);
- obs_property_list_add_int(list, "3.0", 30);
- obs_property_list_add_int(list, "3.1", 31);
- obs_property_list_add_int(list, "4.0 (default) (Compatibility mode)",
- 40);
- obs_property_list_add_int(list, "4.1", 41);
- obs_property_list_add_int(list, "4.2", 42);
- obs_property_list_add_int(list, "5.0", 50);
- obs_property_list_add_int(list, "5.1", 51);
- obs_property_list_add_int(list, "5.2", 52);
-
- list = obs_properties_add_list(props, "rate_control",
- obs_module_text("RateControl"),
- OBS_COMBO_TYPE_LIST,
- OBS_COMBO_FORMAT_STRING);
- obs_property_list_add_string(list, "CBR (default)", "CBR");
- obs_property_list_add_string(list, "CQP", "CQP");
- obs_property_list_add_string(list, "VBR", "VBR");
+ if (codec->id == AV_CODEC_ID_H264) {
+ list = obs_properties_add_list(props, "profile",
+ obs_module_text("Profile"),
+ OBS_COMBO_TYPE_LIST,
+ OBS_COMBO_FORMAT_INT);
+ obs_property_list_add_int(list, "Constrained Baseline (default)",
+ FF_PROFILE_H264_CONSTRAINED_BASELINE);
+ obs_property_list_add_int(list, "Main", FF_PROFILE_H264_MAIN);
+ obs_property_list_add_int(list, "High", FF_PROFILE_H264_HIGH);
+
+ list = obs_properties_add_list(props, "level",
+ obs_module_text("Level"),
+ OBS_COMBO_TYPE_LIST,
+ OBS_COMBO_FORMAT_INT);
+ obs_property_list_add_int(list, "Auto", FF_LEVEL_UNKNOWN);
+ obs_property_list_add_int(list, "3.0", 30);
+ obs_property_list_add_int(list, "3.1", 31);
+ obs_property_list_add_int(list, "4.0 (default) (Compatibility mode)",
+ 40);
+ obs_property_list_add_int(list, "4.1", 41);
+ obs_property_list_add_int(list, "4.2", 42);
+ obs_property_list_add_int(list, "5.0", 50);
+ obs_property_list_add_int(list, "5.1", 51);
+ obs_property_list_add_int(list, "5.2", 52);
+ }
+
+ list = obs_properties_add_list(props, "rate_control",
+ obs_module_text("RateControl"),
+ OBS_COMBO_TYPE_LIST,
+ OBS_COMBO_FORMAT_STRING);
+
+ for (const rc_mode_t *rc_mode = RC_MODES; rc_mode; rc_mode++) {
+ /* Identify the default choice */
+ char *def = strcmp(rc_mode->name, codec->rate_control) == 0
+ ? " (default)"
+ : "";
+
+ dstr_printf(&name, "%s%s", rc_mode->name, def);
+ obs_property_list_add_string(list, name.array, rc_mode->name);
+ }
obs_property_set_modified_callback(list, rate_control_modified);
@@ -616,6 +656,7 @@ static obs_properties_t *vaapi_properties(void *unused)
obs_module_text("KeyframeIntervalSec"), 0, 20,
1);
+ dstr_free(&name);
return props;
}
@@ -645,11 +686,26 @@ struct obs_encoder_info vaapi_encoder_info = {
.create = vaapi_create,
.destroy = vaapi_destroy,
.encode = vaapi_encode,
- .get_defaults = vaapi_defaults,
- .get_properties = vaapi_properties,
+ .get_defaults2 = vaapi_defaults,
+ .get_properties2 = vaapi_properties,
.get_extra_data = vaapi_extra_data,
.get_sei_data = vaapi_sei_data,
.get_video_info = vaapi_video_info,
+ .type_data = &h264_type,
+};
+
+struct obs_encoder_info vaapi_hevc_encoder_info = {
+ .id = "ffmpeg_vaapi_hevc",
+ .type = OBS_ENCODER_VIDEO,
+ .codec = "hevc",
+ .get_name = vaapi_getname,
+ .create = vaapi_create,
+ .destroy = vaapi_destroy,
+ .encode = vaapi_encode,
+ .get_defaults2 = vaapi_defaults,
+ .get_properties2 = vaapi_properties,
+ .get_video_info = vaapi_video_info,
+ .type_data = &hevc_type,
};
#endif
diff --git a/plugins/obs-ffmpeg/obs-ffmpeg.c b/plugins/obs-ffmpeg/obs-ffmpeg.c
index b7a17095d..9d8397e68 100644
--- a/plugins/obs-ffmpeg/obs-ffmpeg.c
+++ b/plugins/obs-ffmpeg/obs-ffmpeg.c
@@ -35,6 +35,7 @@ extern struct obs_encoder_info nvenc_encoder_info;
#ifdef LIBAVUTIL_VAAPI_AVAILABLE
extern struct obs_encoder_info vaapi_encoder_info;
+extern struct obs_encoder_info vaapi_hevc_encoder_info;
#endif
#ifndef __APPLE__
@@ -210,9 +211,9 @@ finish:
#endif
#ifdef LIBAVUTIL_VAAPI_AVAILABLE
-static bool vaapi_supported(void)
+static bool vaapi_supported(const char *codec_name)
{
- AVCodec *vaenc = avcodec_find_encoder_by_name("h264_vaapi");
+ AVCodec *vaenc = avcodec_find_encoder_by_name(codec_name);
return !!vaenc;
}
#endif
@@ -253,10 +254,14 @@ bool obs_module_load(void)
obs_register_encoder(&nvenc_encoder_info);
}
#if !defined(_WIN32) && defined(LIBAVUTIL_VAAPI_AVAILABLE)
- if (vaapi_supported()) {
+ if (vaapi_supported("h264_vaapi")) {
blog(LOG_INFO, "FFMPEG VAAPI supported");
obs_register_encoder(&vaapi_encoder_info);
}
+ if (vaapi_supported("hevc_vaapi")) {
+ blog(LOG_INFO, "FFMPEG HEVC VAAPI supported");
+ obs_register_encoder(&vaapi_hevc_encoder_info);
+ }
#endif
#endif
|