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

Viewed 39

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
src.download(display_img); //display_mg - cpuMat

Then I want to save this frames to a file by using gstreamer and hardware encoder.

The setup I am using is nvidia jetson xavier agx with hardware encoder. I have tried creating a pipeline like 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:

gst_nvh264_writer.write(display_img);

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.

0 Answers
Related