Sending OpenCV output to VLC stream

后端 未结 2 756
心在旅途
心在旅途 2020-12-15 08:06

This has been keeping me busy for a good part of the afternoon and I haven\'t been able to get it to work but I feel like I\'m really close.

I\'ve got openCV set up

相关标签:
2条回答
  • 2020-12-15 08:39

    The following works for me under Python 3

    import numpy as np
    import sys
    import cv2
    
    cap = cv2.VideoCapture(0)
    
    while(cap.isOpened()):
        ret, frame = cap.read()
        if ret==True:        
            sys.stdout.buffer.write(frame.tobytes())
        else:
            break
    
    cap.release()
    

    And the command line (my webcam has a different resolution, and I only display the result, but you did not have problems with that)

    python opencv.py | vlc --demux=rawvideo --rawvid-fps=25 --rawvid-width=640 --rawvid-height=480 --rawvid-chroma=RV24 - --sout "#display" 
    

    Of course this requires a conversion from BGR to RGB as the former is default in OpenCV.

    0 讨论(0)
  • 2020-12-15 08:45

    This worked for me, though I am sending to RTSP stream and not using imutils library:

    import numpy as np
    import sys
    import cv2
    
    input_rtsp = "rtsp://10.10.10.9:8080"
    cap = cv2.VideoCapture(input_rtsp)
    
    while(cap.isOpened()):
        ret, frame = cap.read()
        if ret==True:        
            sys.stdout.write(frame.tostring())
        else:
            break
    
    cap.release()
    

    Then in command line:

    python opencv.py | cvlc --demux=rawvideo --rawvid-fps=25 --rawvid-width=1280 --rawvid-height=720  --rawvid-chroma=RV24 - --sout "#transcode{vcodec=h264,vb=200,fps=25,width=1280,height=720}:rtp{dst=10.10.10.10,port=8081,sdp=rtsp://10.10.10.10:8081/test.sdp}"
    

    Note that you do not need to convert opencv BGR to RGB.

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