GStreamer-CRITICAL gst_poll_read_control: assertion 'set != NULL' failed

Here’s the gst string i use:

rtspsrc location=rtsp://admin:@192.168.168.168 latency=0 ! rtph264depay ! h264parse ! omxh264dec ! nvvidconv ! video/x-raw, width=(int)3072, height=(int)1728, format=(string)BGRx ! videoconvert ! appsink drop=1

Here’s the python3 code I use to create cv2.VideoCapture with gstreamer:

    def _create_jetson_nano_v_cap(self) -> cv2.VideoCapture:
        if not self.has_watermark:
            gst_str = f"rtspsrc location={self.uri} latency={self.latency} " \
                      f"! rtph264depay " \
                      f"! h264parse " \
                      f"! omxh264dec " \
                      f"! nvvidconv " \
                      f"! video/x-raw, width=(int){self.width}, height=(int){self.height}, format=(string)BGRx " \
                      f"! videoconvert " \
                      f"! appsink drop=1"
        else:
            top = 140
            left = 0
            right = self.width
            bottom = 2070

            gst_str = f"rtspsrc location={self.uri} latency={self.latency} " \
                      f"! rtph264depay " \
                      f"! h264parse " \
                      f"! omxh264dec " \
                      f"! nvvidconv top={top} left={left} right={right} bottom={bottom} " \
                      f"! video/x-raw, width=(int){self.width}, height=(int){self.height}, format=(string)BGRx " \
                      f"! videoconvert " \
                      f"! appsink drop=1"

        msg = f"ip camera gst_str :\n{gst_str}\n"
        self.logger.info(msg)
        v_cap = cv2.VideoCapture(gst_str, cv2.CAP_GSTREAMER)
        msg = f"video capture created"
        self.logger.info(msg)

        return v_cap

After the long run of the camera running, the error will occur.

The full version of IPCamera python class:

class IPCamera(ICHASEEdge):
    CLS_EMOJI = '📷'
    DEFAULT_W = 3840
    DEFAULT_H = 2160

    def __init__(self,
                 uri='rtsp://admin:@192.168.168.168',
                 width=3840, height=2160,
                 latency=0,
                 none_frame_thresh=15,
                 scale_fact=None,
                 has_watermark=False,
                 log_lv=AIBR.LOG.LV,
                 log_path: Union[pathlib.Path, str] = 'default'):
        super().__init__()
        self.uri = uri
        self.width = width
        self.height = height
        self.latency = latency
        self.none_frame_thresh = none_frame_thresh
        self.scale_fact = scale_fact
        self.has_watermark = has_watermark
        self.log_lv = log_lv
        self.log_path = log_path

        if self.scale_fact is not None:
            self.width = int(self.DEFAULT_W * self.scale_fact)
            self.height = int(self.DEFAULT_H * self.scale_fact)

        # setting logger
        self.logger = get_cls_instance_logger(self, log_lv=self.log_lv, log_path=self.log_path)

        self.frame = None
        self.frame_width = None
        self.frame_height = None
        self.v_cap = None
        self.is_opened = False
        self.is_broken = False
        self.thread_run_flag = False
        self.thread = None
        # self.thread_lock = threading.Lock()
        self.release_flag = False
        self._launch()

        self.none_frame_count = 0

        self.logger.info('initialized')

    def _create_jetson_nano_v_cap(self) -> cv2.VideoCapture:
        if not self.has_watermark:
            gst_str = f"rtspsrc location={self.uri} latency={self.latency} " \
                      f"! rtph264depay " \
                      f"! h264parse " \
                      f"! omxh264dec " \
                      f"! nvvidconv " \
                      f"! video/x-raw, width=(int){self.width}, height=(int){self.height}, format=(string)BGRx " \
                      f"! videoconvert " \
                      f"! appsink drop=1"
        else:
            top = 140
            left = 0
            right = self.width
            bottom = 2070

            gst_str = f"rtspsrc location={self.uri} latency={self.latency} " \
                      f"! rtph264depay " \
                      f"! h264parse " \
                      f"! omxh264dec " \
                      f"! nvvidconv top={top} left={left} right={right} bottom={bottom} " \
                      f"! video/x-raw, width=(int){self.width}, height=(int){self.height}, format=(string)BGRx " \
                      f"! videoconvert " \
                      f"! appsink drop=1"

        msg = f"ip camera gst_str :\n{gst_str}\n"
        self.logger.info(msg)
        v_cap = cv2.VideoCapture(gst_str, cv2.CAP_GSTREAMER)
        msg = f"video capture created"
        self.logger.info(msg)

        return v_cap

    def _open_camera(self) -> True:
        # with self.thread_lock:
        if self.v_cap is not None:
            raise RuntimeError('camera is already opened!')

        self.v_cap = self._create_jetson_nano_v_cap()
        if not self.v_cap.isOpened():
            msg = 'video capture is not opened'
            self.logger.error(msg)
            raise RuntimeError('cannot open camera if VideoCapture is not opened!')

        _, self.frame = self.v_cap.read()
        if self.frame is None:
            msg = 'VideoCapture.read() returns no image'
            self.logger.error(msg)
            self.is_opened = False
            return False

        self.is_opened = True
        self.frame_height, self.frame_width, _ = self.frame.shape
        assert self.frame_width is not None and self.frame_width is not None

        return True

    def _launch(self):
        assert self._open_camera()
        assert not self.thread_run_flag
        self.thread_run_flag = True
        self.thread = threading.Thread(target=self._update_frame)
        self.thread.start()

        msg = f'camera launched successfully'
        self.logger.debug(msg)

    def _update_frame(self):
        while self.thread_run_flag:
            _, self.frame = self.v_cap.read()
            # self.frame = None # !@#
            if self.frame is None:
                if not self.release_flag:
                    self.none_frame_count += 1
                    msg = f"fetched None frame count = {self.none_frame_count}"
                    # print(str(self.none_frame_count).zfill(6), end='\r') # !@#
                    self.logger.warning(msg)

                    if self.none_frame_count > self.none_frame_thresh:
                        self.is_broken = True
                        msg = f"fetched None frame count exceed thresh, prepare to stop update frame thread"
                        self.logger.warning(msg)
                        self.thread_run_flag = False
                        break
            else:
                self.none_frame_count = 0

        self.thread_run_flag = False
        msg = f"updating frame loop is break"
        self.logger.debug(msg)

    def _stop(self):
        if self.thread_run_flag:
            self.thread_run_flag = False

    def read(self):
        """Read a frame from the camera object.

        Returns None if the camera runs out of image or error.
        """
        if not self.is_opened:
            return None

        return self.frame

    def release(self):
        self.release_flag = True
        self._stop()
        try:
            self.v_cap.release()
        except:
            pass
        self.is_opened = False

        msg = f"camera released"
        self.logger.debug(msg)

    def __del__(self):
        if not self.release_flag:
            self.release()

    def isOpened(self):
        return self.is_opened

    @property
    def status(self) -> bool:
        if self.is_broken:
            return False

        msg = f"status check: none_frame_count = {self.none_frame_count}"

        return self.none_frame_count < self.none_frame_thresh and self.is_opened

    def get_curr_frame_eagerly(self, try_count=3):
        for i in range(try_count):
            frame = self.read()
            if frame is not None:
                return frame

        self.is_broken = True

Hi,
We have deprecated omx plugins. Please use nvv4l2decoder.

Here is a python sample for your reference:
Doesn't work nvv4l2decoder for decoding RTSP in gstreamer + opencv - #3 by DaneLLL

Also I want to ask, what’s the difference between input the whole gst string into cv2 and use the gi package? are they doing the same thing?

Here’s the updated method for created VideoCapture and VideoWriter:

# video capture
def _create_jetson_nano_v_cap(self) -> cv2.VideoCapture:

    gst_str = f"rtspsrc location={self.uri} latency={self.latency} " \
              f"! rtph264depay " \
              f"! h264parse " \
              f"! nvv4l2decoder " \
              f"! nvvidconv " \
              f"! video/x-raw, width=(int){self. Width}, height=(int){self.height}, format=(string)BGRx " \
              f"! videoconvert " \
              f"! appsink drop=1"


    msg = f"ip camera gst_str :\n{gst_str}\n"
    self.logger.info(msg)
    v_cap = cv2.VideoCapture(gst_str, cv2.CAP_GSTREAMER)
    msg = f"video capture created"
    self.logger.info(msg)

    return v_cap

# video writer
        self.gs_str = f"appsrc " \
                      f"! video/x-raw, format=BGR " \
                      f"! queue " \
                      f"! videoconvert " \
                      f"! video/x-raw,format=BGRx " \
                      f"! nvvidconv " \
                      f"! nvv4l2h264enc " \
                      f"! h264parse " \
                      f"! matroskamux " \
                      f"! filesink location={self.video_path}"

        msg = f"gstreamer str:\ngst-launch-1.0 {self.gs_str}\n"
        self.logger.info(msg)

        self.v_writer = cv2.VideoWriter(self.gs_str, cv2.CAP_GSTREAMER, 0, fps, (self. Width, self. Height))

After about 2 hours video recording, still meet similiar error, but it seems occurred on VideoWriter, how can i improve it:

2023-08-15 21:53:11 INFO 🎞️  GSVideoWriter-AA5236 📝 gstreamer str:
gst-launch-1.0 appsrc ! video/x-raw, format=BGR ! queue ! videoconvert ! video/x-raw, format=BGRx ! nvvidconv ! nvv4l2h264enc ! h264parse ! matroskamux ! filesink location=/home/ichase/ICHASE/repel-record/B000-1_2023-08-15-21-53-11_repel-record/B000-1_2023-08-15-21-53-11_repel-record.mkv

Opening in BLOCKING MODE 
2023-08-15 21:53:11 INFO 🎞️  GSVideoWriter-AA5236 📝 video writer created
2023-08-15 21:53:11 DEBUG 🎞️  GSVideoWriter-AA5236 📝 initialized
2023-08-15 21:53:11 CRITICAL 🔫📖 RepelRecord-91BF15 📝 start video recording

(python3:10067): GStreamer-CRITICAL **: 21:53:11.660: gst_poll_write_control: assertion 'set != NULL' failed

(python3:10067): GStreamer-CRITICAL **: 21:53:11.660: gst_poll_write_control: assertion 'set != NULL' failed
NvMMLiteOpen : Block : BlockType = 4 
===== NVMEDIA: NVENC =====
NvMMLiteBlockCreate : Block : BlockType = 4 

(python3:10067): GStreamer-CRITICAL **: 21:53:11.662: gst_poll_write_control: assertion 'set != NULL' failed

(python3:10067): GStreamer-CRITICAL **: 21:53:11.663: gst_poll_write_control: assertion 'set != NULL' failed

(python3:10067): GStreamer-CRITICAL **: 21:53:11.666: gst_poll_read_control: assertion 'set != NULL' failed

(python3:10067): GStreamer-CRITICAL **: 21:53:11.667: gst_poll_write_control: assertion 'set != NULL' failed

(python3:10067): GStreamer-CRITICAL **: 21:53:11.667: gst_poll_write_control: assertion 'set != NULL' failed
RV Recorder: 00:00 - Repel Record FPS = 52.035
(python3:10067): GStreamer-CRITICAL **: 21:53:11.679: gst_poll_read_control: assertion 'set != NULL' failed
NvRmChannelSubmit: NvError_IoctlFailed with error code 22
NvRmPrivFlush: NvRmChannelSubmit failed (err = 196623, SyncPointIdx = 15, SyncPointValue = 0)
fence_set_name ioctl failed with 22
NvDdkVicExecute Failed
nvbuffer_transform Failed
gst_nvvconv_transform: NvBufferTransform Failed 

(python3:10067): GStreamer-CRITICAL **: 21:53:11.762: gst_poll_write_control: assertion 'set != NULL' failed

Try the following sample (assumming that your python install has opencv with Gstreamer support).
I just made a localhost RTSP server in a first terminal with test-launch using:

./test-launch "videotestsrc is-live=true ! video/x-raw, width=640, height=480, framerate=30/1 ! nvvidconv ! video/x-raw(memory:NVMM), width=1280, height=720, format=NV12 ! nvv4l2h264enc insert-vui=true insert-sps-pps=1 idrinterval=15 ! h264parse ! rtph264pay name=pay0 "

So the test.py code:

import cv2

import re
print('GStreamer support: %s' % re.search(r'GStreamer\:\s+(.*)', cv2.getBuildInformation()).group(1))

capture_pipeline = f"uridecodebin uri=rtsp://127.0.0.1:8554/test source::latency=500 " \
                   f"! nvvidconv " \
                   f"! video/x-raw, format=BGRx " \
                   f"! videoconvert " \
                   f"! video/x-raw, format=BGR " \
                   f"! queue " \
                   f"! appsink drop=1"
cap = cv2.VideoCapture(capture_pipeline, cv2.CAP_GSTREAMER)
if not cap.isOpened() :
	print('Failed to open capture')
	exit(-1)
# Get some properties of the video stream
w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
h = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
fps = float(cap.get(cv2.CAP_PROP_FPS))
print('capture opened, framing %dx%d@%f fps' % (w,h,fps))


writer_pipeline = f"appsrc " \
                  f"! video/x-raw, format=BGR " \
                  f"! queue " \
                  f"! videoconvert " \
                  f"! video/x-raw,format=BGRx " \
                  f"! nvvidconv " \
                  f"! nvv4l2h264enc " \
                  f"! h264parse " \
                  f"! matroskamux " \
                  f"! filesink location=test.mkv"
writer = cv2.VideoWriter(writer_pipeline, cv2.CAP_GSTREAMER, 0, float(fps), (w, h))
if not writer.isOpened() :
	print('Failed to open writer')
	exit(-2)

print('Capture and Writer successfully opened, starting recording rtsp -> mkv file')
while True:
        ret,frame = cap.read()
        if not ret:
                print('Failed to read from camera')
                break
                
        writer.write(frame)
        
writer.release()
cap.release()

Then, in a second terminal, run it for 10 seconds:

python test.py

# There may be some harmless warnings about video duration and video position (a live stream has no duration and its current position cannot be computed)

# After 10 s stop the app with Ctrl-C

# Play back the recorded video
gst-play-1.0 test.mkv

Can you share the test-launch shell? and my original code can also work in short period of run. But when comes to keep inferencing frames and recording in about hours, the error is occurred.

Hi,
Please check Jetson Nano FAQ

Q: Is there any example of running RTSP streaming?

And download/build test-launch

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