FFmpeg: формат аппаратных пикселей не поддерживается типом устройства.C#

Место общения программистов C#
Гость
FFmpeg: формат аппаратных пикселей не поддерживается типом устройства.

Сообщение Гость »

Windows, C#, FFmpeg.AutoGen
Я хочу использовать аппаратное ускорение для кодирования видео с помощью FFmpeg.
Это части моего кода:

Код: Выделить всё

AVBufferRef* hw_device_ctx = null;
int err = ffmpeg.av_hwdevice_ctx_create(&hw_device_ctx, AVHWDeviceType.AV_HWDEVICE_TYPE_DXVA2, null, null, 0);

AVBufferRef* hw_frames_ref;
AVHWFramesContext* frames_ctx = null;

hw_frames_ref = ffmpeg.av_hwframe_ctx_alloc(hw_device_ctx);

frames_ctx = (AVHWFramesContext*)(hw_frames_ref->data);

for (int i = 0; i < 256; i++)
{

frames_ctx->format    = (AVPixelFormat)i;
frames_ctx->sw_format = (AVPixelFormat)i;

frames_ctx->width = ctx->width;
frames_ctx->height = ctx->height;
frames_ctx->initial_pool_size = 20;

ffmpeg.av_hwframe_ctx_init(hw_frames_ref);

}
То есть перечисляются все значения AVPixelFormat.
Помимо AV_HWDEVICE_TYPE_DXVA2 я также использую AV_HWDEVICE_TYPE_CUDA и AV_HWDEVICE_TYPE_D3D11VA.
Я получаю один ответ для всех AVHWDeviceType и для всех AVPixelFormat:

Код: Выделить всё

The hardware pixel format %PixelFormat% is not supported by the device type %DeviceType%
Почему не поддерживается ни один формат пикселей?
Источники кода FFmpeg:

Код: Выделить всё

int av_hwframe_ctx_init(AVBufferRef *ref)
{
FFHWFramesContext *ctxi = (FFHWFramesContext*)ref->data;
AVHWFramesContext *ctx  = &ctxi->p;
const enum AVPixelFormat *pix_fmt;
int ret;

if (ctxi->source_frames) {
/* A derived frame context is already initialised. */
return 0;
}

/* validate the pixel format */
for (pix_fmt = ctxi->hw_type->pix_fmts; *pix_fmt != AV_PIX_FMT_NONE; pix_fmt++) {
if (*pix_fmt == ctx->format)
break;
}
if (*pix_fmt == AV_PIX_FMT_NONE) {
av_log(ctx, AV_LOG_ERROR,
"The hardware pixel format '%s' is not supported by the device type '%s'\n",
av_get_pix_fmt_name(ctx->format), ctxi->hw_type->name);
return AVERROR(ENOSYS);
}

}
...

Код: Выделить всё

const HWContextType ff_hwcontext_type_dxva2 = {
.type                 = AV_HWDEVICE_TYPE_DXVA2,
.name                 = "DXVA2",

.device_hwctx_size    = sizeof(AVDXVA2DeviceContext),
.frames_hwctx_size    = sizeof(DXVA2FramesContext),

.device_create        = dxva2_device_create,
.frames_init          = dxva2_frames_init,
.frames_uninit        = dxva2_frames_uninit,
.frames_get_buffer    = dxva2_get_buffer,
.transfer_get_formats = dxva2_transfer_get_formats,
.transfer_data_to     = dxva2_transfer_data_to,
.transfer_data_from   = dxva2_transfer_data_from,
.map_from             = dxva2_map_from,

.pix_fmts             = (const enum AVPixelFormat[]){ AV_PIX_FMT_DXVA2_VLD, AV_PIX_FMT_NONE },
};
Аналогично и для других типов устройств.
То есть должен поддерживаться хотя бы один формат пикселей!

Подробнее здесь: https://stackoverflow.com/questions/781 ... evice-type

Вернуться в «C#»