@@ -157,18 +157,36 @@ struct FFmpegHWDevice::Impl
157
157
}
158
158
}
159
159
160
- bool init_hw_device (const AVCodec *av_codec, const char *type)
160
+ bool init_hw_device (const AVCodec *av_codec, const char *type, bool encode )
161
161
{
162
162
#ifdef HAVE_FFMPEG_VULKAN
163
- bool use_vulkan = device->get_device_features ().supports_video_decode_queue ;
164
- if (use_vulkan)
163
+ bool use_vulkan = false ;
164
+
165
+ if (encode)
165
166
{
166
- if (av_codec->id == AV_CODEC_ID_H264)
167
- use_vulkan = device->get_device_features ().supports_video_decode_h264 ;
168
- else if (av_codec->id == AV_CODEC_ID_HEVC)
169
- use_vulkan = device->get_device_features ().supports_video_decode_h265 ;
170
- else
171
- use_vulkan = false ;
167
+ use_vulkan = device->get_device_features ().supports_video_encode_queue ;
168
+ if (use_vulkan)
169
+ {
170
+ if (av_codec->id == AV_CODEC_ID_H264)
171
+ use_vulkan = device->get_device_features ().supports_video_encode_h264 ;
172
+ else if (av_codec->id == AV_CODEC_ID_HEVC)
173
+ use_vulkan = device->get_device_features ().supports_video_encode_h265 ;
174
+ else
175
+ use_vulkan = false ;
176
+ }
177
+ }
178
+ else
179
+ {
180
+ use_vulkan = device->get_device_features ().supports_video_decode_queue ;
181
+ if (use_vulkan)
182
+ {
183
+ if (av_codec->id == AV_CODEC_ID_H264)
184
+ use_vulkan = device->get_device_features ().supports_video_decode_h264 ;
185
+ else if (av_codec->id == AV_CODEC_ID_HEVC)
186
+ use_vulkan = device->get_device_features ().supports_video_decode_h265 ;
187
+ else
188
+ use_vulkan = false ;
189
+ }
172
190
}
173
191
#endif
174
192
@@ -263,7 +281,7 @@ struct FFmpegHWDevice::Impl
263
281
}
264
282
265
283
bool init_codec_context (const AVCodec *av_codec, Vulkan::Device *device_,
266
- AVCodecContext *av_ctx, const char *type)
284
+ AVCodecContext *av_ctx, const char *type, bool encode )
267
285
{
268
286
if (device && (device != device_ || av_codec != cached_av_codec))
269
287
{
@@ -277,7 +295,7 @@ struct FFmpegHWDevice::Impl
277
295
device = device_;
278
296
cached_av_codec = av_codec;
279
297
280
- if (!init_hw_device (av_codec, type))
298
+ if (!init_hw_device (av_codec, type, encode ))
281
299
return false ;
282
300
283
301
if (av_ctx && (hw_config->methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX) != 0 )
@@ -337,11 +355,11 @@ FFmpegHWDevice::~FFmpegHWDevice()
337
355
}
338
356
339
357
bool FFmpegHWDevice::init_codec_context (const AVCodec *codec, Vulkan::Device *device,
340
- AVCodecContext *ctx, const char *type)
358
+ AVCodecContext *ctx, const char *type, bool encode )
341
359
{
342
360
if (!impl)
343
361
impl.reset (new Impl);
344
- return impl->init_codec_context (codec, device, ctx, type);
362
+ return impl->init_codec_context (codec, device, ctx, type, encode );
345
363
}
346
364
347
365
bool FFmpegHWDevice::init_frame_context (AVCodecContext *ctx,
0 commit comments