Ruslan-B/FFmpeg.AutoGen

AccessViolation in avformat_find_stream_info

zgabi opened this issue · 1 comments

zgabi commented

Note: for support questions, please use stackoverflow or special repository on [github.com](in special repository github.com). This repository's issues are reserved for feature requests and bug reports.

  • **I'm submitting a ... **

    • bug report
    • feature request
    • support request or question => Please do not submit support request or questions here, see note at the top of this template.
  • Do you want to request a feature or report a bug?
    bug

  • What is the current behavior?
    AccessViolationException in avformat_find_stream_info

  • *If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem:

av_log_set_level(AV_LOG_DEBUG);

AVFormatContext* cf = null;

try
{
    cf = avformat_alloc_context();
    if (cf == null)
    {
        throw new Exception("Could not allocate the format context");
    }

    int probeSize = 32768 * 2;
    cf->probesize = probeSize;

    AVDictionary* options = null;
    string probeSizeStr = probeSize.ToString();
    av_dict_set(&options, "analyzeduration", probeSizeStr, 0);
    av_dict_set(&options, "probesize", probeSizeStr, 0);
    av_dict_set(&options, "rtsp_transport", "tcp", 0);

    string url =
        "rtsp://horizontetest:horizontetest@122.5.39.146:7828/cam/realmonitor?channel=1&subtype=1&unicast=true&proto=Onvif";
    int ret = avformat_open_input(&cf, url, null, &options);
    if (ret != 0)
    {
        throw new Exception("Could not open the input");
    }

    ret = avformat_find_stream_info(cf, &options);
    Console.WriteLine(probeSizeStr);
    if (ret < 0)
    {
        throw new Exception("Could not find stream info");
    }

    if (cf->streams == null)
    {
        throw new Exception("Could not find stream");
    }
}
finally
{
    if (cf != null)
    {
        avformat_close_input(&cf);
    }
}
  • What is the expected behavior?
    No Access Violation.

  • What is the motivation / use case for changing the behavior?

  • Please tell us about your environment:
    Windows 10 Latest / Windows server 2022
    .NET 6 version which comes with the latest Visual Studio 2022 (17.3.3).
    FFmpeg 5.1.1, FFmpeg.AutoGen 5.1.1, but also tried with 4.x versions.

  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc)
    I'm not sure wether this is an FFmpeg.AutoGen or ffmpeg issue. I'm checking all the return values of the previous calls, and the code is very simple (only 3 calls: avformat_alloc_context, avformat_find_stream_info and avformat_find_stream_info), so I think this is not an issue in my code, but I also created a stackoverflow questsion: https://stackoverflow.com/questions/73700549/accessviolationexception-in-ffmpeg-called-from-net-with-ffmpeg-autogen

This code works with a lot of another Hikvision cameras, but anyway if there is a problem with the stream from the camera, ffmpeg should not crash.

zgabi commented

I've reproduced the problem in a native C++ code, so not an FFmpeg.AutoGen issue.
Strange, since it occues only with some RTSP streams, but with those streams always reprducible.
Anyway if you have any idea how to fix it, please let me know. Thank you.