Jetson nano python program freezes on the line cv2.VideoWriter.write(frame)

Hello!
I use the latest Jetson Nano sd-card image for now, February 24 (downloaded it here: Jetson Download Center | NVIDIA Developer), camera IMX219-160, python 3.6.9, OpenCV library 4.1.1 (it was already installed in image). In my python program I use the next code to get images from camera and to write them to videofile:

def get_gstreamer_output_pipeline(video_file_name, path_to_video_folder):
    return ('appsrc ! '
            'video/x-raw, format=BGR ! '
            'queue ! '
            'videoconvert ! '
            'video/x-raw,format=RGBA ! '
            'nvvidconv ! '
            'omxh264enc ! '
            'h264parse ! '
            'qtmux ! '
            'filesink location=%s%s ' % (path_to_video_folder, video_file_name))

gstreamer_pipeline = (
    'nvarguscamerasrc ! '
    'video/x-raw(memory:NVMM), width=(int)1080, height=(int)720, format=(string)NV12, framerate=(fraction)30/1 ! '
    'nvvidconv ! '
    'video/x-raw, format=(string)BGRx ! '
    'videoconvert ! '
'video/x-raw, format=(string)BGR ! '
'appsink')
video_capturer = cv2.VideoCapture(gstreamer_pipeliPreformatted textne, cv2.CAP_GSTREAMER)



counter = 0
video_name_1 = str(counter)
video_name_2 = str(counter + 1)
gst_out = get_gstreamer_output_pipeline(video_name_1, path_to_video_folder)
output_1 = cv2.VideoWriter(gst_out, cv2.CAP_GSTREAMER, 0, 30.0, (int(1080), int(720)))
gst_out = get_gstreamer_output_pipeline(video_name_2, path_to_video_folder)
output_2 = cv2.VideoWriter(gst_out, cv2.CAP_GSTREAMER, 0, 30.0, (int(1080), int(720)))

current_date = datetime.datetime.now()
while (video_capturer.isOpened()):
    if (datetime.datetime.now() - current_date).total_seconds() > 60:
        output_1.release()
        output_2.release()

        current_date = datetime.datetime.now()

        counter += 2
        video_name_1 = str(counter)
        video_name_1 = str(counter + 1)

        gst_out = get_gstreamer_output_pipeline(video_name, path_to_video_folder)
        output_1 = cv2.VideoWriter(gst_out, cv2.CAP_GSTREAMER, 0, 30.0, (int(1080), int(720)))
        gst_out = get_gstreamer_output_pipeline(video_name_m, path_to_video_folder)
        output_2 = cv2.VideoWriter(gst_out, cv2.CAP_GSTREAMER, 0, 30.0, (int(1080), int(720)))

    _, frame = video_capturer.read()
    if (not _):
        break

    # ...Some frame processing...
    
    output_1.write(frame)
    output_2.write(image)

It seems that in some cases after a few hours of this program work, the program freezes when writing frame to a videofile. It just stops on the line output_1.write(frame) or output_2.write(image) and doesn’t move on. From the moment of the freeze, syslog is spammed with messages:

Feb 22 19:52:14 jetson-desktop nvargus-daemon[5375]: (Argus) Error OverFlow: Too many pending events, ignoring new events (in src/api/EventProviderImpl.cpp, function addEvent(), line 156)                      
Feb 22 19:52:35 jetson-desktop nvargus-daemon[5375]: message repeated 1255 times: [ (Argus) Error OverFlow: Too many pending events, ignoring new events (in src/api/EventProviderImpl.cpp, function addEvent(), line 156)]
Feb 22 19:52:35 jetson-desktop nvargus-daemon[5375]: (Argus) Error OverFlow: Too many pending events, ignoring new events (in src/api/EventProviderImpl.cpp, function addEvent(), line 156)
Feb 22 19:52:35 jetson-desktop nvargus-daemon[5375]: (Argus) Error OverFlow: Too many pending events, ignoring new events (in src/api/EventProviderImpl.cpp, function addEvent(), line 156) ...

Can you please help me to solve this problem? Thank you.

Hi,
Could you check if it stops due to insufficient freespace on storage? For writing to video files for hours, it may consume significant storage space.

I checked, at the time of the freeze, there is enough space on the sd card.

Hi,
Looks like you use omxh264enc plugin in the pipeline. We have deprecated omx plugins. Please try v4l2 plugins.

You can refer to this python sample:
Displaying to the screen with OpenCV and GStreamer - #9 by DaneLLL

Thank you. I will try it and report the results later.

Thank you. It seems that with the next pipeline video writing is much more stable and program does not freeze after several hours.

def get_gstreamer_output_pipeline(video_file_name, path_to_video_folder):
    return ('appsrc ! '
            'video/x-raw, format=BGR ! '
            'queue ! '
            'videoconvert ! '
            'video/x-raw,format=RGBA ! '
            'nvvidconv ! '
            'nvv4l2h264enc ! '
            'h264parse ! '
            'qtmux ! '
            'filesink location=%s%s ' % (path_to_video_folder, video_file_name))