mediamtx icon indicating copy to clipboard operation
mediamtx copied to clipboard

Exception: can't open video writer, Publish to Server from OpenCV

Open naseemap47 opened this issue 1 year ago • 0 comments

Which version are you using?

opencv-python==4.6.0.66

Which operating system are you using?

  • [x] Linux amd64 standard
  • [ ] Linux amd64 Docker
  • [ ] Linux arm64 standard
  • [ ] Linux arm64 Docker
  • [ ] Linux arm7 standard
  • [ ] Linux arm7 Docker
  • [ ] Linux arm6 standard
  • [ ] Linux arm6 Docker
  • [ ] Windows amd64 standard
  • [ ] Windows amd64 Docker (WSL backend)
  • [ ] macOS amd64 standard
  • [ ] macOS amd64 Docker
  • [ ] Other (please describe)

Describe the issue

Exception: can't open video writer, Publish to Server from OpenCV

Describe how to replicate the issue

  1. start the server
  2. publish to server with OpenCV
  3. read with
import cv2
import numpy as np
from time import sleep

fps = 20
width = 800
height = 600

out = cv2.VideoWriter('appsrc ! videoconvert' + \
    ' ! x264enc speed-preset=ultrafast bitrate=600 key-int-max=40' + \
    ' ! rtspclientsink location=rtsp://localhost:8554/mystream',
    cv2.CAP_GSTREAMER, 0, fps, (width, height), True)
if not out.isOpened():
    raise Exception("can't open video writer")

while True:
    frame = np.zeros((height, width, 3), np.uint8)

    # create a red rectangle
    for y in range(0, int(frame.shape[0] / 2)):
        for x in range(0, int(frame.shape[1] / 2)):
            frame[y][x] = (0, 0, 255)

    out.write(frame)
    print("frame written to the server")

    sleep(1 / fps)

OutPut:

Exception: can't open video writer

Did you attach the server logs?

yes

$ ./rtsp-simple-server 
2022/10/31 11:28:15 INF rtsp-simple-server v0.20.1
2022/10/31 11:28:15 INF [RTSP] listener opened on :8554 (TCP), :8000 (UDP/RTP), :8001 (UDP/RTCP)
2022/10/31 11:28:15 INF [RTMP] listener opened on :1935
2022/10/31 11:28:15 INF [HLS] listener opened on :8888

Did you attach a network dump?

no

naseemap47 avatar Oct 31 '22 06:10 naseemap47