How to release NvVideoEncoder resources perfectly?

Description

I am testing VideoEncoder from jetson_multimedia_api samples(sample: frontend).
I just want to test VideoEncoder.cpp, but if i encoding nothing, it appears “segmentation falt” when releasing NvVideoEncoder

Environment

I test tensorrt in Docker

Platform : Orin
Jetpack Version : 5.0.2-b231
TensorRT Version : 8.4.1
CUDA Version : 11.4
CUDNN Version : 8.4.1
Operating System + Version : ubuntu20.04
Python Version (if applicable) : 3.8.10
PyTorch Version (if applicable): 1.10
Baremetal or Container (if container which image + tag): dustynv/ros:noetic-ros-base-l4t-r35.1.0(GitHub - dusty-nv/jetson-containers: Machine Learning Containers for NVIDIA Jetson and JetPack-L4T))

Steps To Reproduce:

cd /usr/src/jetson_multimedia_api/samples/
mkdir l4t_encode_shutdown_debug
cd l4t_encode_shutdown_debug
cp /usr/src/jetson_multimedia_api/samples/frontend/VideoEncoder.h .
cp /usr/src/jetson_multimedia_api/samples/frontend/VideoEncoder.cpp .
// edit new main.cpp
// edit new Makefile
make
./l4t_encode_shutdown_debug

main.cpp

#include <iostream>
#include <string>

#include "VideoEncoder.h"

void bufferDoneCallback(int dmabuf_fd, void *arg){
 std::cout << "bufferDoneCallback" << std::endl;
}


bool g_bProfiling = false;
void l4t_encode(int argc, char** argv)
{
    std::string name = "enc";
    std::string outputFilename = "test.h264";
    int width = 640;
    int height = 480;
    uint32_t pixfmt = V4L2_PIX_FMT_H264;
    VideoEncoder m_VideoEncoder(name.c_str(), outputFilename.c_str(), width, height, pixfmt);
    m_VideoEncoder.setBufferDoneCallback(bufferDoneCallback, NULL);

    // Init encoder
    m_VideoEncoder.initialize();

    // encode
    // m_VideoEncoder.encodeFromFd(fd); 

    // release
    m_VideoEncoder.encodeFromFd(-1); 
    m_VideoEncoder.shutdown();
}


int main(int argc, char** argv)
{
    l4t_encode(argc, argv);   
    return 0;
}

Makefile

###############################################################################
#
# Copyright (c) 2016-2021, NVIDIA CORPORATION. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#  * Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#  * Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#  * Neither the name of NVIDIA CORPORATION nor the names of its
#    contributors may be used to endorse or promote products derived
#    from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
###############################################################################

include ../Rules.mk

APP := l4t_encode_shutdown_debug 

ARGUS_UTILS_DIR := $(TOP_DIR)/argus/samples/utils

ENABLE_TRT ?= 1

SRCS := main.cpp VideoEncoder.cpp \
	$(wildcard $(CLASS_DIR)/*.cpp) \
	$(ARGUS_UTILS_DIR)/Thread.cpp

OBJS := $(SRCS:.cpp=.o)

CPPFLAGS += \
	-I"$(ARGUS_UTILS_DIR)"


all: $(APP)

$(CLASS_DIR)/%.o: $(CLASS_DIR)/%.cpp
	$(AT)$(MAKE) -C $(CLASS_DIR)

$(ALGO_CUDA_DIR)/%.o: $(ALGO_CUDA_DIR)/%.cpp
	$(AT)$(MAKE) -C $(ALGO_CUDA_DIR)

$(ALGO_CUDA_DIR)/%.o: $(ALGO_CUDA_DIR)/%.cu
	$(AT)$(MAKE) -C $(ALGO_CUDA_DIR)

$(ALGO_TRT_DIR)/%.o: $(ALGO_TRT_DIR)/%.cpp
	$(AT)$(MAKE) -C $(ALGO_TRT_DIR)

%.o: %.cpp
	@echo "Compiling: $<"
	$(CPP) $(CPPFLAGS) -c $< -o $@

$(APP): $(OBJS)
	@echo "Linking: $@"
	$(CPP) -o $@ $(OBJS) $(CPPFLAGS) $(LDFLAGS)

clean:
	$(AT)rm -rf $(APP) $(OBJS)

Hi,
If you would like to test encoder only, we would suggest try the samples:

/usr/src/jetson_multimedia_api/samples/01_video_encode
/usr/src/jetson_multimedia_api/samples/unittest_samples/encoder_unit_sample
/usr/src/jetson_multimedia_api/samples/10_camera_recording