2

After much reading and trial-and-error... I have successfully got my RPi Model 4B (w/4GB RAM) working with Gstreamer pipes using hardware decoding and encoding in OpenCV 4.4.0 with 1920x1080 video frames coming in via RTSP IP camera. Thats the good news!

Here is my working VideoCapture Gstreamer pipe for getting the video frames from IP Camera:

std::string gst_pipe_in = "rtspsrc location=rtsp://admin:passwd@192.168.1.30:554/cam/realmonitor?channel=1&subtype=0 ! rtph264depay ! h264parse ! v4l2h264dec ! autovideoconvert ! appsink"; cv::VideoCapture capture(gst_pipe_in,cv::CAP_GSTREAMER);

The VideoWriter Gstreamer pipe for writing the processed video to a file:

std::string motion_writer_pipe = "appsrc ! autovideoconvert ! v4l2h264enc ! h264parse ! mp4mux ! filesink location = " + savedMotionVideoFullPath; cv::VideoWriter motion_writer = cv::VideoWriter(motion_writer_pipe,cv::CAP_GSTREAMER,frames_per_second,frame_size,true);

My question is: How can I adjust the QUALITY of the video being written via this VideoWriter Gsteamer pipe?

I wanted to use the Gstreamer element 'omxh264dec' and 'omxh264enc' but I have never been able to get a pipe to work using them... and I've read online that the omxh264 hardware-accelerated plugins are BROKEN in the RPi4. And there doesn't seem to be any CAPABILITIES in the 'v4l2h264enc' element to allow setting for encoding quality or video file size or anything.

Any help on how I can use hardware-accelerated video h264 video encoding at 1920x1080 and control the resulting quality or file size?

Currently with this setup, using the Gstreamer pipes as shown above... I'm getting 16.7 fps reading the frames in and then simply writing the frames out to a MP4 file. When adding my Motion Detection openCV processing code, I'm now getting about 14-15 fps.

The reason I went to Gstreamer was that with only using the RPi CPU... same setup... I could only get 8.6 fps... so with the hardware-acceleration provided by the Gstreamer pipes... I have doubled my fps. Thank goodness!

Now I just want to improve the video quality of the written .mp4 h264 file. I would love to use h265... but that seems to be impossible at the moment using the RPi4B.

Thanks for listening. Any help or ideas would be most appreciated! Dave

DaveK
  • 39
  • 1
  • 3

0 Answers0