I want to get the stream frame from one usb camera, and use the gstreamer framework to display the stream into the hdmi in real time and also save the stream into files.
So I write the code bellow, and it run well in the phase before stream.release() is called(I call the function to generate one size-limited file, and set the max frame count to 1200 for testing), but after , the process is blocked by the stream.write function when the cnt is 1203, and the hdmi screen become nothing displayed.
Cloud anybody help me to troubleshotting it?
import cv2
g_test = 1
print(cv2.__version__)
cap = cv2.VideoCapture('/dev/video8', cv2.CAP_V4L)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 360)
cap.set(cv2.CAP_PROP_FPS, 20)
cnt = 0
gst_video_writer = " t. ! queue ! videoconvert ! video/x-raw,format=BGRx ! nvvidconv ! nvv4l2h264enc profile=4 bitrate=16384000 ! h264parse ! matroskamux ! filesink location=./test_"+str(cnt)+".avi"
gst_out_hdmi = " t. ! timeoverlay ! textoverlay name=txt0 shaded-background=false valignment=top halignment=right text="+str("Road") +" ! videoconvert ! nvvidconv ! nvdrmvideosink max-bitrate=16384000 set_mode=1 sync=false"
gst_str= "appsrc ! tee name=t "+gst_video_writer+gst_out_hdmi
print(gst_str)
stream = cv2.VideoWriter(gst_str, cv2.CAP_GSTREAMER, 0, 20, (640,360))
stream.set(cv2.VIDEOWRITER_PROP_QUALITY,100)
max_cnt_per_one_video = 20*60
while True:
ret, frame_read = cap.read()
cnt = cnt +1
print('get frame',frame_read.shape,cnt)
stream.write(frame_read)
print('writen frame',frame_read.shape,cnt)
if (cnt % (max_cnt_per_one_video) ==0):
stream.release()
gst_str= "appsrc ! tee name=t "+gst_video_writer+gst_out_hdmi
print("get new str",gst_str)
stream = cv2.VideoWriter(gst_str, cv2.CAP_GSTREAMER, 0, 20, (640,360))
The output as bellow:
get frame (360, 640, 3) 1196
writen frame (360, 640, 3) 1196
get frame (360, 640, 3) 1197
writen frame (360, 640, 3) 1197
get frame (360, 640, 3) 1198
writen frame (360, 640, 3) 1198
get frame (360, 640, 3) 1199
writen frame (360, 640, 3) 1199
get frame (360, 640, 3) 1200
writen frame (360, 640, 3) 1200
get new str appsrc ! tee name=t t. ! queue ! videoconvert ! video/x-raw,format=BGRx ! nvvidconv ! nvv4l2h264enc profile=4 bitrate=16384000 ! h264parse ! matroskamux ! filesink location=./test_0.avi t. ! timeoverlay ! textoverlay name=txt0 shaded-background=false valignment=top halignment=right text=Road ! videoconvert ! nvvidconv ! nvdrmvideosink max-bitrate=16384000 set_mode=1 sync=false
Opening in BLOCKING MODE
get frame (360, 640, 3) 1201
writen frame (360, 640, 3) 1201
NvMMLiteOpen : Block : BlockType = 4
===== NVMEDIA: NVENC =====
get frame (360, 640, 3) 1202
NvMMLiteBlockCreate : Block : BlockType = 4
(python3:154730): GStreamer-**CRITICAL** **: 15:47:41.208: gst_mini_object_copy: assertion 'mini_object != NULL' failed
(python3:154730): GStreamer-**CRITICAL** **: 15:47:41.208: gst_caps_get_structure: assertion 'GST_IS_CAPS (caps)' failed
(python3:154730): GStreamer-**CRITICAL** **: 15:47:41.208: gst_structure_copy: assertion 'structure != NULL' failed
(python3:154730): GStreamer-**CRITICAL** **: 15:47:41.208: gst_caps_append_structure_full: assertion 'GST_IS_CAPS (caps)' failed
(python3:154730): GStreamer-**CRITICAL** **: 15:47:41.208: gst_caps_get_structure: assertion 'GST_IS_CAPS (caps)' failed
(python3:154730): GStreamer-**CRITICAL** **: 15:47:41.208: gst_structure_copy: assertion 'structure != NULL' failed
(python3:154730): GStreamer-**CRITICAL** **: 15:47:41.208: gst_caps_append_structure_full: assertion 'GST_IS_CAPS (caps)' failed
(python3:154730): GStreamer-**CRITICAL** **: 15:47:41.208: gst_mini_object_copy: assertion 'mini_object != NULL' failed
(python3:154730): GStreamer-**CRITICAL** **: 15:47:41.208: gst_caps_get_structure: assertion 'GST_IS_CAPS (caps)' failed
(python3:154730): GStreamer-**CRITICAL** **: 15:47:41.208: gst_structure_copy: assertion 'structure != NULL' failed
(python3:154730): GStreamer-**CRITICAL** **: 15:47:41.208: gst_caps_append_structure_full: assertion 'GST_IS_CAPS (caps)' failed
(python3:154730): GStreamer-**CRITICAL** **: 15:47:41.208: gst_caps_get_structure: assertion 'GST_IS_CAPS (caps)' failed
(python3:154730): GStreamer-**CRITICAL** **: 15:47:41.208: gst_structure_copy: assertion 'structure != NULL' failed
(python3:154730): GStreamer-**CRITICAL** **: 15:47:41.208: gst_caps_append_structure_full: assertion 'GST_IS_CAPS (caps)' failed
color_range if supported, to be set to default by DRM
color_range if supported, to be set to default by DRM
writen frame (360, 640, 3) 1202
color_range if supported, to be set to default by DRM
get frame (360, 640, 3) 1203
H264: Profile = 100, Level = 0
NVMEDIA: Need to set EMC bandwidth : 84000
NVMEDIA_ENC: bBlitMode is set to TRUE
color_range if supported, to be set to default by DRM
color_range if supported, to be set to default by DRM
color_range if supported, to be set to default by DRM
color_range if supported, to be set to default by DRM