OpenCV Mat to Gstreamer pipeline with filesink option writing files of only 336 bytes

As the title suggests, I have a opencv MAT downloaded from GPU mat after Converting it to BGRA:

cv::cuda::cvtColor(src,src,cv::COLOR_RGB2BGRA); //src - gpuMat; //display_mg - cpuMat

Then I want to save this frames to a file by using GStremaer and Hardware endcoder.

The setup I am using is nvidia jetson xavier agx with hardware encoder. I have tried creating a pipeline like Custom Lithium Ion Battery Pack Manufacturer so:

cv::VideoWriter gst_nvh264_writer("appsrc ! videoconvert ! video/x-raw,format=BGRx !queue! nvvidconv ! nvv4l2h264enc ! video/x-h264,format=byte-stream ! h264parse ! matroskamux ! filesink location=test-nvh264-writer.mkv ", 0, 30, cv::Size (400,400));
if (!gst_nvh264_writer.isOpened ()) {
    std::cout << "Failed to open gst_nvh264 writer." << std::endl;

And finally I’m writing the frames to the pipeline like:


But its outputting a file of only 336 bytes. The size is of the mat is fixed to 400x400 and I think stride values should be managed by the pipeline. So I assume the problem is with the pipeline creation parameters and I’m new to gstreamer.

Any suggestions are much appreciated.

Probably the source does not generate frames continually. Please try this sample:
Displaying to the screen with OpenCV and GStreamer - #9 by DaneLLL

See if you can successfully run this sample and get valid video file.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.