bytedeco/javacv

h264_cuvid crashed when meets with dynamic resolution stream.

Open

#2 384 ouverte le 30 mars 2026

Voir sur GitHub
 (4 commentaires) (0 réactions) (0 assignés)Java (6 985 stars) (1 583 forks)batch import
enhancementhelp wanted

Description

Recently, while using JavaCV to ingest a video stream, I encountered a crash when the connected live stream's resolution dynamically increased. Interestingly, the stream remains stable if the resolution decreases.

The error message is: [h264_cuvid @ ...] AVHWFramesContext is already initialized with incompatible parameters

After inspecting the source code, I found the following check

    if (hwframe_ctx->pool && (
            hwframe_ctx->width < avctx->width ||
            hwframe_ctx->height < avctx->height ||
            hwframe_ctx->format != AV_PIX_FMT_CUDA ||
            hwframe_ctx->sw_format != avctx->sw_pix_fmt)) {
        av_log(avctx, AV_LOG_ERROR, "AVHWFramesContext is already initialized with incompatible parameters\n");
        // ... debug logs ...
        ctx->internal_error = AVERROR(EINVAL);
        return 0;

It appears this is related to the hardware context initialization.

My Question: Is it possible to manually preset a hardware context (AVHWFramesContext) with a sufficiently large resolution (e.g., a maximum expected size) to accommodate dynamic resolution upscaling without triggering this incompatibility error?

Any advice or workarounds would be greatly appreciated.

Guide contributeur