[Libav-user] Ffmpeg crash with avformat_close_input()

Denis Ivanov denisx.ivanov at gmail.com
Tue Mar 2 16:10:03 EET 2021


I have multiple input devices (Cameras), every one of them is encoded to
their own file. Everything is working fine. I have only one input
AVFormatContext. This is how cameras are opened

for (int i = 0; i < CameraList.Count; i++)
            {
                var camera = CameraList[i];
                    AVDictionary* optionalOpts;
                    if (!string.IsNullOrEmpty(camera.InputResolution))
                        ffmpeg.av_dict_set(&optionalOpts, "video_size",
camera.InputResolution, 0);

                    ffmpeg.av_dict_copy(&optionalOpts, options, 0);

                    AVInputFormat* inputFormat = null;

                    if (!string.IsNullOrEmpty(camera.Format))
                    {
                        inputFormat =
ffmpeg.av_find_input_format(camera.Format);
                        if (inputFormat == null)
                            // exception
                    }

                    if (ffmpeg.avformat_open_input(&pInputFmtCtx,
camera.Url, inputFormat, &optionalOpts) != 0)
                    {
                        if (ffmpeg.avformat_open_input(&pInputFmtCtx,
camera.Url, inputFormat, &options) != 0)
                            // exception
                    }
            }

The problem is that the application crashes when having more than one
input, specifically here:

fixed (AVFormatContext** p = &InputFormatContext)
                    ffmpeg.avformat_close_input(p);

If I have single input (one video and one audio stream) everything is fine.
There is no errors thrown, just crash and that's it.What am I doing wrong?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20210302/b1ff1394/attachment.html>


More information about the Libav-user mailing list