Failed to get h265 file using opencv + gstreamer

i tried to just use gst-launch-1.0 which i can get the h265 file. the cmd is :

gst-launch-1.0 videotestsrc ! 'video/x-raw,format=(string)I420,width=(int)1280,height=(int)720' ! omxh265enc ! filesink location=test.h265 -e

but when i use opencv ,i can get the h265 file which is a 0byte file.the snippet:

VideoWriter writer;
writer.open("appsrc ! omxh265enc ! filesink location=test1.h265 ", 0, (double)24.0, cv::Size(1280, 720), true);
for(;;)
	{
		Mat frame(1280,720,CV_8UC3);
		cap>>frame; // get the frame OK
		writer.write(frame);

	}
	writer.release();

i get the exe .when i execute it .i get:

Inside NvxLiteH264DecoderLowLatencyInitNvxLiteH264DecoderLowLatencyInit set DPB and MjstreamingInside NvxLiteH265DecoderLowLatencyInitNvxLiteH265DecoderLowLatencyInit set DPB and MjstreamingGStreamer Plugin: Embedded video playback halted; module appsrc0 reported: Internal data flow error.

opencv version: 3.2
my questions:
1.is there something wrong i have done?
2.i wanna know how to change the argus of gst-launch-1.0 to fix the VideoWriter::open().what argus should i write in the open() function.

Hi,

Here is a relevant topic for your reference.

Thanks.

hi AastaLLL ,thanks for your answer
i have seen the post you mentioned before.the solution is to add a space symbol at the end of the pipeline.
but i have the space in my snippet.besides,i tried the argus

"appsrc ! autovideoconvert ! omxh265enc ! matroskamux ! filesink location=test.mkv "

it turns out to be the same error.
thanks.

Hi,

Try this:

#include <opencv2/highgui.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/videoio.hpp>
#include <iostream>

int main()
{
    cv::Mat img = cv::imread("cat.jpg");
    cv::VideoWriter writer;
    writer.open("appsrc ! videoconvert ! omxh265enc ! filesink location=test1.h265 ", 0, (double)24.0, img.size(), true);
    writer.write(img);
    writer.release();

    std::cout << "DONE" << std::endl;
    return 0;
}

Thanks.

Hi, AastaLLL,
I follow your tips ,and it works.Thank you very much!
My code is :

writer.open("appsrc ! videoconvert ! omxh265enc ! matroskamux ! filesink location=test.mkv ",0,(double)24.0,cv::Size(1280,720),true);

I use “videoconvert” rather than “autovideoconvert” to get the right output;