I am using FFMpeg.AutoGen (v6.0.0.2) with hwencode support for Nvidia cards, and in few devices (for example on NVIDIA GeForce MX350) when I am doing fffmpeg.avcodec_open2 I got the following ffmpeg message in logs:
[h264_nvenc @ 000001f473fcc480] OpenEncodeSessionEx failed: unsupported device (2): (no details)
And then it crashes with the following crash:
Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at FFmpeg.AutoGen.DynamicallyLoadedBindings+<>c.<Initialize>b__2_494(FFmpeg.AutoGen.AVCodecContext*, FFmpeg.AutoGen.AVCodec*, FFmpeg.AutoGen.AVDictionary**)
at FFmpeg.AutoGen.ffmpeg.avcodec_open2(FFmpeg.AutoGen.AVCodecContext*, FFmpeg.AutoGen.AVCodec*, FFmpeg.AutoGen.AVDictionary**)
at GraphicsCheck.FfmpegChecker.StartEncoder(Omni.Platforms.Windows.Services.AV.CodecInfo, Int32, Int32, Int32)
at GraphicsCheck.FfmpegChecker.CheckConfig(CodecConfig)
at Program.<Main>$(System.String[])
I created a sample app to demo this issue. And following the path of the calls..
- That happens at nvenc_open_session and is called here
- That would cause going to fail2 routine, which is this one:
fail2:
CHECK_CU(dl_fn->cuda_dl->cuCtxDestroy(ctx->cu_context_internal));
ctx->cu_context_internal = NULL;
- ctx->cu_context_internal comes from (in same method) then I suppose it was created properly (as otherwise wouldn't continue).
ret = CHECK_CU(dl_fn->cuda_dl->cuCtxCreate(&ctx->cu_context_internal, 0, cu_device));
if (ret < 0)
goto fail;
- ctx in that method is the priv_data of AVCodecContext as we can see here:
static av_cold int nvenc_check_device(AVCodecContext *avctx, int idx)
{
NvencContext *ctx = avctx->priv_data;
- Also the act of printing the error message, on nvenc_print_error, is interacting with context.
static int nvenc_print_error(AVCodecContext *avctx, NVENCSTATUS err,
const char *error_string)
{
const char *desc;
const char *details = "(no details)";
int ret = nvenc_map_error(err, &desc);
#ifdef NVENC_HAVE_GETLASTERRORSTRING
NvencContext *ctx = avctx->priv_data;
NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &ctx->nvenc_dload_funcs.nvenc_funcs;
if (p_nvenc && ctx->nvencoder)
details = p_nvenc->nvEncGetLastErrorString(ctx->nvencoder);
#endif
av_log(avctx, AV_LOG_ERROR, "%s: %s (%d): %s\n", error_string, desc, err, details);
return ret;
}
av_log is executed as we can see the error message on logs then the other lines shouldn't be a problem.
Seeing the other calls, when nvenc_check_device fails the error is going up to nvenc_check_device -> nvenc_setup_device but we aren't seeing more logs then the issue may be on nvenc_check_device on fail2 routine or on nvenc_print_error
Any thoughts ?