private void InitializeConverters(bool shouldResize)
        {
            var videoStreamIndex = Array.FindIndex(_StreamsContextArr, x => x.DecoderContext->codec_type == AVMediaType.AVMEDIA_TYPE_VIDEO);

            if (videoStreamIndex < 0)
            {
                throw new Exception("No video stream found");
            }

            if (shouldResize)
            {
                var decoderContext = _StreamsContextArr[videoStreamIndex].DecoderContext;

                _videoConverter = new VideoFrameConverter(new Size(decoderContext->width, decoderContext->height),
                                                          decoderContext->pix_fmt,
                                                          _size,
                                                          TARGET_PIX_FORMAT);
            }

            var audioStreamIndex = Array.FindIndex(_StreamsContextArr, x => x.DecoderContext->codec_type == AVMediaType.AVMEDIA_TYPE_AUDIO);

            if (audioStreamIndex > -1)
            {
                _audioConverter = new AudioFrameConverter(_StreamsContextArr[audioStreamIndex].EncoderContext,
                                                          _StreamsContextArr[audioStreamIndex].DecoderContext);
            }
        }
        public void Dispose()
        {
            if (_videoConverter != null)
            {
                _videoConverter.Dispose();
                _videoConverter = null;
            }

            if (_audioConverter != null)
            {
                _audioConverter.Dispose();
                _audioConverter = null;
            }

            _outputName         = null;
            _inputName          = null;
            _validStreamIndexes = null;

            for (int i = 0; i < _StreamsContextArr.Length; i++)
            {
                fixed(AVCodecContext **ptr = &_StreamsContextArr[i].DecoderContext)
                {
                    ffmpeg.avcodec_free_context(ptr);
                }

                if (_pOutputFmCtx != null && _StreamsContextArr.Length > i && _pOutputFmCtx->streams[i] != null && _StreamsContextArr[i].EncoderContext != null)
                {
                    fixed(AVCodecContext **ptr = &_StreamsContextArr[i].EncoderContext)
                    {
                        ffmpeg.avcodec_free_context(ptr);
                    }
                }
            }

            fixed(AVFormatContext **ptr = &_pInputFmtCtx)
            {
                ffmpeg.avformat_close_input(ptr);
            }

            if (_pOutputFmCtx != null && (_pOutputFmCtx->oformat->flags & ffmpeg.AVFMT_NOFILE) == 0)
            {
                ffmpeg.avio_closep(&_pOutputFmCtx->pb);
            }

            ffmpeg.avformat_free_context(_pOutputFmCtx);
            _pOutputFmCtx = null;

            ffmpeg.avformat_free_context(_pInputFmtCtx);
            _pInputFmtCtx = null;

            if (_pReusablePacket != null)
            {
                FreePacket(realloc: false);
            }

            if (_pReusableFrame != null)
            {
                FreeFrame(realloc: false);
            }

            _StreamsContextArr = null;
        }