1

Is it possible in python with the latest CV2 to use CV2 to directly bind mjpeg output from the camera to a stream without having to do source -> cv2.read() -> numpy array -> cv2.imencode(".jpg") -> mjpeg? I am looking to do source -> mjpeg in a pythonic way.

Latency is a major issue so any advice including options beyond CV2 would be appreciated.

aris-t
  • 151
  • 8
  • I don't know if CV2 can gives you directly JPG - I never found method for this - but there are methods to get stream faster in question [OpenCV real time streaming video capture is slow. How to drop frames or get synced with real time?](https://stackoverflow.com/questions/58293187/opencv-real-time-streaming-video-capture-is-slow-how-to-drop-frames-or-get-sync). If you would use webcam in Raspberry Pi then you could use module `picamera` to do this - ie. [web streaming](https://picamera.readthedocs.io/en/release-1.13/recipes2.html#web-streaming) – furas Dec 11 '20 at 01:02

1 Answers1

0

No. OpenCV is not a media library. Its video I/O is not intended or made for this.

I would advise to use PyAV, which is the only proper python wrapper around ffmpeg's libraries that I know of. PyAV comes with a few examples to give you a feel for how it works.

the basic problem then is how to use ffmpeg's libraries to enumerate available video devices, query their modes, select the mode you want, and move packets around.

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36