hi i develop following opencv code to capture frame from mipi camera the show it and save the video but i encounter some errors that can not save video file
std::string gstreamer_pipeline (int capture_width, int capture_height, int display_width, int display_height, int framerate, int flip_method) {
return "nvarguscamerasrc ! video/x-raw(memory:NVMM), width=(int)" + std::to_string(capture_width) + ", height=(int)" +
std::to_string(capture_height) + ", framerate=(fraction)" + std::to_string(framerate) +
"/1 ! nvvidconv flip-method=" + std::to_string(flip_method) + " ! video/x-raw, width=(int)" + std::to_string(display_width) + ", height=(int)" +
std::to_string(display_height) + ", format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink";
};
int main(){
int capture_width = 1024 ;
int capture_height = 720 ;
int framerate = 30 ;
int flip_method = 0 ;
cv::VideoWriter writer;
writer.open("nvarguscamerasrc ! 'video/x-raw(memory:NVMM), width=1024, height=720,format=NV12,
framerate=30/1' ! omxh265enc ! qtmux ! filesink location=test.mp4 -e", cv::CAP_GSTREAMER
,30,cv::Size(1024,720));
std::string pipeline;
pipeline = gstreamer_pipeline(capture_width,
capture_height,
capture_width,
capture_height,
framerate,
flip_method);
cv::VideoCapture capture(pipeline, cv::CAP_GSTREAMER);
if(!capture.isOpened()) {
std::cout<<"Failed to open camera."<<std::endl;
return (-1);
}
while (1) {
if (!capture.read(rgbFrame)) {
std::cout << "Cannot grab a frame." << std::endl;
break;
}
cv::rectangle(rgbFrame, myRect, cv::Scalar(0, 255, 0), 1, 1);
writer<<rgbFrame;
cv::imshow("Video",rgbFrame);
int key=cv::waitKey(1);
if(key=='q')
break;
}//while
writer.release();
capture.release();
above source code show video but in saving video file encounter these errors and nothing saved!!!
GStreamer-CRITICAL **: 15:04:50.586: gst_element_make_from_uri: assertion 'gst_uri_is_valid (uri)' failed
[ WARN:0@2.833] global cap_gstreamer.cpp:2436 open OpenCV | GStreamer warning: error opening writer pipeline: syntax error
GST_ARGUS: Creating output stream
CONSUMER: Waiting until producer is connected...
GST_ARGUS: Available Sensor modes :
GST_ARGUS: 4032 x 3040 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.000000, max 22.250000; Exposure Range min 13000, max 683709000;
GST_ARGUS: 3840 x 2160 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.000000, max 22.250000; Exposure Range min 13000, max 683709000;
GST_ARGUS: 1920 x 1080 FR = 59.999999 fps Duration = 16666667 ; Analog Gain range min 1.000000, max 22.250000; Exposure Range min 13000, max 683709000;
GST_ARGUS: Running with following settings:
Camera index = 0
Camera mode = 2
Output Stream W = 1920 H = 1080
seconds to Run = 0
Frame Rate = 59.999999
GST_ARGUS: Setup Complete, Starting captures for 0 seconds
GST_ARGUS: Starting repeat capture requests.
CONSUMER: Producer has connected; continuing.
[ WARN:0@3.581] global cap_gstreamer.cpp:1777 open OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1
Using pipeline:
nvarguscamerasrc ! video/x-raw(memory:NVMM), width=(int)1024, height=(int)720, framerate=(fraction)30/1 ! nvvidconv flip-method=0 ! video/x-raw, width=(int)1024, height=(int)720, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink
FPS: 30
Video width: 1024
Video height: 720
i check gstreamer expression on ubuntu command line
gst-launch-1.0 nvarguscamerasrc ! 'video/x-raw(memory:NVMM), width=1024, height=720,format=NV12, framerate=30/1' ! omxh265enc ! qtmux ! filesink location=test.mp4 -e
it is ok and save video file(test.mp4) but why in my opencv code video file not generate?!!!