Write in Gstreamer pipeline from opencv in python

前端 未结 1 923
無奈伤痛
無奈伤痛 2020-12-15 01:54

I\'m trying to stream some images form opencv using gstreamer and I got ome issues with the pipeline. I\'m new to gstreamer and opencv in general. I compiled opencv 3.2 with

1条回答
  •  失恋的感觉
    2020-12-15 02:25

    I came across the solution and I hope this helps other people that come across the same issue. The pipeline was mistakenly arranged and videoconvert was needed. On the other hand the latency was quite relevant but setting speed.preset to ultrafast solved the issue even if there's not much of compression going on there, it was a good compromise. Here's my solution.

    import cv2
    
    cap = cv2.VideoCapture(0)
    
    framerate = 25.0
    
    out = cv2.VideoWriter('appsrc ! videoconvert ! '
                          'x264enc noise-reduction=10000 speed-preset=ultrafast tune=zerolatency ! '
                          'rtph264pay config-interval=1 pt=96 !'
                          'tcpserversink host=192.168.1.27 port=5000 sync=false',
                          0, framerate, (640, 480))
    
    while cap.isOpened():
        ret, frame = cap.read()
        if ret:
    
            out.write(frame)
    
            if cv2.waitKey(1) & 0xFF == ord('q'):
                break
        else:
            break
    
    # Release everything if job is finished
    cap.release()
    out.release()
    

    0 讨论(0)
提交回复
热议问题