Skip to content

h264_cuvid crashed when meets with dynamic resolution stream. #2384

@abovzv

Description

@abovzv

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions