[Jetson Xavier] using cv::VideoWriter with nvv4l2h264enc (DPS4.0)and memory leak

Hi,
cuda-10.0,DeepStream4.0 on Jetson Xavier
I using this sample to test cv::VideoWriter with nvv4l2h264enc.And Memory leak problem happens.

void writeMP4File()
{
	string videoPath = "./test.mp4";
	int frameRate = 6;
	Mat bmp = imread ("./test_1.png");
	cv::Size frame_size(bmps[0].cols,bmps[0].rows);
	std::string  gst_writer = "appsrc ! video/x-raw, format=(string)BGR ! \
                              videoconvert ! video/x-raw, format=(string)I420 ! \
                              nvvideoconvert ! video/x-raw(memory:NVMM) ! \
                              nvv4l2h264enc ! h264parse ! matroskamux ! filesink location=" + videoPath;
	cv::VideoWriter channelVideoWriter = cv::VideoWriter(gst_writer, cv::VideoWriter::fourcc('a','v','c','1'), frameRate, frame_size, true);
	int frame = 0;
	while(frame < 40)
	{
		channelVideoWriter.write(bmp);
		frame++;
	}	
	channelVideoWriter.release();
}

If I use VideoWriter without nvv4l2h264enc from deepstream-4.0SDK,Memory leak problem never happens.

string videoPath = "./test.mp4";
      cv::VideoWriter channelVideoWriter = cv::VideoWriter(videoPath, cv::VideoWriter::fourcc('a','v','c','1'), frameRate, frame_size, true);

And If I use these VideoWriter,Memory leak obviously.Runing function of writeMP4File 100 times with 2GB memory leak.

std::string  gst_writer = "appsrc ! video/x-raw, format=(string)BGR ! \
                              videoconvert ! video/x-raw, format=(string)I420 ! \
                              nvvideoconvert ! video/x-raw(memory:NVMM) ! \
                              nvv4l2h264enc ! h264parse ! matroskamux ! filesink location=" + videoPath;
	cv::VideoWriter channelVideoWriter = cv::VideoWriter(gst_writer, cv::VideoWriter::fourcc('a','v','c','1'), frameRate, frame_size, true);

Could you test this and help me?

Hi,
Please replace nvvideoconvert with nvvidconv, and try again.

Hi,I had used nvvidconv.And it is not work.And I am using DeepStream SDK 4.0 here is log:

===== NVMEDIA: NVENC =====
NvMMLiteBlockCreate : Block : BlockType = 4
Failed to configure NvDdkVic Source Surface
nvbuffer_transform Failed
gst_nvvconv_transform: NvBufferTransform Failed

Hi,
Can you please set width, height and try again? Below pipeline runs well.

$ gst-launch-1.0 videotestsrc num-buffers=300 ! video/x-raw,format=BGR,<b>width=1280,height=720</b> ! videoconvert ! video/x-raw,format=I420 ! nvvidconv ! 'video/x-raw(memory:NVMM)' ! nvv4l2h264enc ! h264parse ! matroskamux ! filesink location=a.mkv

Hi,
what is your test platform?xaiver on Jetpack 4.2.1 using DeepStream4.0SDK?
I can not successed to run this pipeline:

gst-launch-1.0 videotestsrc num-buffers=300 ! video/x-raw,format=BGR,width=1280,height=720 ! videoconvert ! video/x-raw,format=I420 ! nvvidconv ! 'video/x-raw(memory:NVMM)' ! nvv4l2h264enc ! h264parse ! matroskamux ! filesink location=a.mkv

And here is log :

gst-launch-1.0 videotestsrc num-buffers=300 ! video/x-raw,format=BGR,width=1280,height=720 ! videoconvert ! video/x-raw,format=I420 ! nvvidconv ! 'video/x-raw(memory:NVMM)' ! nvv4l2h264enc ! h264parse ! matroskamux ! filesink location=a.mkv

(gst-plugin-scanner:9918): GLib-GObject-WARNING **: 13:41:12.434: cannot register existing type 'GstInterpolationMethod'

(gst-plugin-scanner:9918): GLib-GObject-CRITICAL **: 13:41:12.434: g_param_spec_enum: assertion 'G_TYPE_IS_ENUM (enum_type)' failed

(gst-plugin-scanner:9918): GLib-GObject-CRITICAL **: 13:41:12.434: validate_pspec_to_install: assertion 'G_IS_PARAM_SPEC (pspec)' failed
Setting pipeline to PAUSED ...
Opening in BLOCKING MODE
Pipeline is PREROLLING ...
Redistribute latency...
NvMMLiteOpen : Block : BlockType = 4
===== NVMEDIA: NVENC =====
NvMMLiteBlockCreate : Block : BlockType = 4
Failed to configure NvDdkVic Source Surface
nvbuffer_transform Failed
gst_nvvconv_transform: NvBufferTransform Failed
ERROR: from element /GstPipeline:pipeline0/GstVideoTestSrc:videotestsrc0: Internal data stream error.
Additional debug info:
gstbasesrc.c(3055): gst_base_src_loop (): /GstPipeline:pipeline0/GstVideoTestSrc:videotestsrc0:
streaming stopped, reason error (-5)
ERROR: pipeline doesn't want to preroll.
Setting pipeline to NULL ...
Freeing pipeline ...

Hi,

Yes. Could you clean the cache and try again:
https://docs.nvidia.com/metropolis/deepstream/4.0/dev-guide/index.html#page/DeepStream_Development_Guide%2Fdeepstream_quick_start.html%23wwpID0E05E0HA

If the application encounters errors and cannot create Gst elements, remove the GStreamer cache, then try again. To remove the GStreamer cache, enter this command:
$ rm ${HOME}/.cache/gstreamer-1.0/registry.x86_64.bin

Hi,Thanks for your reply.
rm ${HOME}/.cache/gstreamer-1.0/registry.aarch64.bin.
But it is same with before.

Hi,
You may try to re-flash or re-extract DS4.0. Please notice some steps have to be executed in super user.

Hi,
After re-flash system and reinstall DS4.0 with SDKManger,it is ok.
Thanks for help.