我想使用dxva2进行硬件加速。在我的代码中软件解码工作正常,但硬件加速avcodec_send_packet返回负值(-1094995529)。帮帮我解决这个问题?
dxva2硬件的初始化:
enum AVHWDeviceType type = av_hwdevice_find_type_by_name("dxva2");
if (type == AV_HWDEVICE_TYPE_NONE) {
fprintf(fp, "Hardware Device type is not supported.\n");
return -1;
}
for (int i = 0;; i++) {
const AVCodecHWConfig *config = avcodec_get_hw_config(sChannelInfo[chNum].codec, i);
if (!config) {
fprintf(fp, "Failed to get Hardware Configuartion\n");
return -1;
}
if (config->methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX &&
config->device_type == type) {
hw_pix_fmt = config->pix_fmt;
fprintf(fp, "config->pix_fmt %d\n", (int)hw_pix_fmt);
break;
}
}
sChannelInfo[chNum].pCodecContext->pix_fmt = AV_PIX_FMT_DXVA2_VLD;
sChannelInfo[chNum].pCodecContext->get_format = get_hw_format;
av_opt_set_int(sChannelInfo[chNum].pCodecContext, "refcounted_frames", 1, 0);
if (hw_decoder_init(sChannelInfo[chNum].pCodecContext, type) < 0)
{
fprintf(fp, "hardware decoder initilisation Failed\n");
return -1;
}
解码:
int ret = avcodec_send_packet(sChannelInfo[chNum].pCodecContext, &pkt);
if (ret < 0) {
char buffer[64];
av_make_error_string(buffer, 64, ret);
fprintf(fp, "Error during decoding %d %s\n",ret,buffer);
return ret;
}
为什么avcodec_send_packet API返回-1094995529值? dxva2初始化中是否缺少任何内容?