getting error while running streamer command from opencv videowrite api

asked 2020-04-27 08:56:48 -0500

sahil_saxena gravatar image

updated 2020-04-27 08:57:51 -0500

Hi, While running below command i am getting below error, could not able to figure out what could be the problem. It will be a great help if someone help me to find the rootcause

import cv2
cap = cv2.VideoCapture('/dev/video0')
framerate = 30.0
gst_str = 'appsrc ! videoconvert ! image/jpeg, width=1280, height=720, framerate=30/1 ! jpegdec ! x264enc ! mpegtsmux ! hlssink location=/var/www/segment-%05d.ts playlist-location=/var/www/index.m3u8 max-files=20 target-duration=15'
out = cv2.VideoWriter(gst_str, 0, 30.0, (640, 480))

while cap.isOpened():
    ret, frame = cap.read()
    if ret:
        out.write(frame)
    else:
        break

# Release everything if job is finished
cap.release()
out.release()

output log:

0:00:00.053608539    17 0x55d1603b6150 WARN                  ladspa gstladspa.c:507:plugin_init:<plugin91> no LADSPA plugins found, check LADSPA_PATH
0:00:00.070290877    17 0x55d1603b6150 WARN                 default gstsf.c:98:gst_sf_create_audio_template_caps: format 0x120000: 'AVR (Audio Visual Research)' is not mapped
0:00:00.070302475    17 0x55d1603b6150 WARN                 default gstsf.c:98:gst_sf_create_audio_template_caps: format 0x180000: 'CAF (Apple Core Audio File)' is not mapped
0:00:00.070318097    17 0x55d1603b6150 WARN                 default gstsf.c:98:gst_sf_create_audio_template_caps: format 0x100000: 'HTK (HMM Tool Kit)' is not mapped
0:00:00.070324196    17 0x55d1603b6150 WARN                 default gstsf.c:98:gst_sf_create_audio_template_caps: format 0xc0000: 'MAT4 (GNU Octave 2.0 / Matlab 4.2)' is not mapped
0:00:00.070342167    17 0x55d1603b6150 WARN                 default gstsf.c:98:gst_sf_create_audio_template_caps: format 0xd0000: 'MAT5 (GNU Octave 2.1 / Matlab 5.0)' is not mapped
0:00:00.070346981    17 0x55d1603b6150 WARN                 default gstsf.c:98:gst_sf_create_audio_template_caps: format 0x210000: 'MPC (Akai MPC 2k)' is not mapped
0:00:00.070352990    17 0x55d1603b6150 WARN                 default gstsf.c:98:gst_sf_create_audio_template_caps: format 0xe0000: 'PVF (Portable Voice Format)' is not mapped
0:00:00.070374024    17 0x55d1603b6150 WARN                 default gstsf.c:98:gst_sf_create_audio_template_caps: format 0x160000: 'SD2 (Sound Designer II)' is not mapped
0:00:00.070381877    17 0x55d1603b6150 WARN                 default gstsf.c:98:gst_sf_create_audio_template_caps: format 0x190000: 'WVE (Psion Series 3)' is not mapped
0:00:00.302048869     9 0x55569c840530 WARN                 basesrc gstbasesrc.c:3583:gst_base_src_start_complete:<source> pad not activated yet
0:00:00.304445375     9 0x55569c840530 WARN                 basesrc gstbasesrc.c:3583:gst_base_src_start_complete:<source> pad not activated yet
0:00:00.304622909     9 0x55569c970d40 WARN                 filesrc gstfilesrc.c:403:gst_file_src_fill:<source> error: system error: Invalid argument
0:00:00.304658363     9 0x55569c970d40 WARN                 basesrc gstbasesrc.c:3055:gst_base_src_loop:<source> error: Internal data stream error.
0:00:00.304665379     9 0x55569c970d40 WARN                 basesrc gstbasesrc.c:3055:gst_base_src_loop:<source> error: streaming stopped, reason error (-5)
0:00:00.304705271     9 0x55569c970d40 WARN                typefind gsttypefindelement.c:991:gst_type_find_element_chain_do_typefinding:<typefind> error: Stream doesn't contain enough data.
[ WARN:0] global /opencv-4.2.0/modules/videoio/src/cap_gstreamer.cpp (1759) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module source reported: Could not read from resource.
0:00:00.304738732     9 0x55569c970d40 WARN                typefind gsttypefindelement.c:991:gst_type_find_element_chain_do_typefinding:<typefind> error: Can't typefind stream
[ WARN:0] global /opencv-4.2.0/modules/videoio/src/cap_gstreamer.cpp (888) open OpenCV | GStreamer warning: unable ...
(more)
edit retag flag offensive close merge delete

Comments

Try this:

device_index = None
for file in os.listdir("/sys/class/video4linux"):
    real_file = os.path.realpath("/sys/class/video4linux/" + file)
    print real_file
    print "/" + str(bus[-1]) + "-" + str(device[-1]) + "/"
    if "/" + str(bus[-1]) + "-" + str(device[-1]) + "/" in real_file:
        device_index = real_file[-1]
        print "Hurray, device index is " + str(device_index)


camera = cv2.VideoCapture(int(device_index))
supra56 gravatar imagesupra56 ( 2020-04-27 21:16:35 -0500 )edit