How to create x264 RTSP server with OpenCV Python with GStreamer backend - python

My goal is to create a RTSP server using OpenCV Python using the GStreamer backend.
I have RGB images stored as OpenCV Mat, and I would like to create a VideoWriter which can write to a RTSP sink. The output video must be x264 encoded.
I believe this can be easily achieved using a GStreamer pipeline and providing the pipeline arguments to the VideoWriter constructor and then later pushing frames to the VideoWriter, but the issue is I have no experience working with GStreamer and I find it very confusing.
The answers I have found on SO are incomplete, use specific hardware decoders (ex for NVIDIA Jetson), or are overly complex. I'd like to find a more generic solution which works on CPU.

I have created a project something related to your requirement sometime ago. This could be a kickstarter and customize it based on your need. I'm attaching my github repository link below.
OpenCV RTSP Server
Any issues related to the project can be raised in the github itself and doubts can be cleared here.

SimpleRTSPServer, Not in Python but very simple to run and use. Start the server in another terminal and write your outputs to there. The server easy to configure as well. You can capture read frames easily from another Python script or VLC.

Related

How to pass live video stream from webRTC/aiortc to python for face recognition

I'm working on deployment of a face recognition Flask application with nginx and gunicorn. It works fine on local host but I've encountered an issue accessing a remote user's media/camera since openCV cannot get the permission to do so. I've tried out different approaches including Javascript which is the most suitable but the problem with that is I have not found a way to pass the video stream to the face recognition functions. My most recent discovery aiortc looks promising as it is a wrapper around Javascript's getUserMedia but I'm having trouble installing and running it.
I ran pip3 install aiortc but when I try to run something like video = aiortc.MediaPlayer('/dev/video0', format='v4l2', options={'video_size':'640x480'}) I get the message AttributeError: module 'aiortc' has no attribute 'MediaPlayer'.'
I've come across WebRTC which I've tried but to no avail. How can I get a live video stream to pass to python so as to conduct face recognition? I would highly appreciate any help. I'm sorry if the issue is obvious.

How can I access my laptop's built-in infrared webcam using python?

I'm trying to access my laptop's built-in infrared webcam (intended for windows hello) in a python project. I can access the normal RGB camera quite easily using the VideoCapture class from OpenCV, however can't find a way to access the infrared camera. I tried passing different indices to the VideoCapture class, however only "0" works, which is the normal webcam.
There are ways to do this using the Windows API, however I can't find a way to access this in Python.
Some people have been able to access the windows hello camera on Ubuntu using fswebcam.
Is there anyway to access the infrared camera using python? Maybe some way of interfacing with the Windows API using pywin32? Any help getting started with this would be appreciated. Alternatively, is there anything similar to fswebcam for Windows that would let me do the same?
That example you provided, doesn't seem to use the win32 api, but rather the dotnet framework, specifically the Windows.Media.Capture.Frames.MediaFrameSourceGroup class.
It looks like you'll be able to access the dotnet framework using http://pythonnet.github.io/ . After that it should be a case of porting that C# code over to Python.
You need to access WinRT API, not Win32 API.
Use this library: https://github.com/Microsoft/xlang/tree/master/src/package/pywinrt/projection and you should be able to call invoke necessary parts in WinRT from the code you posted.

HDMI-USB Video Capture Card Stream Using Opencv or any other library in Python

I am trying to read the stream from HDMI-USB video-capture card using opencv. But OpenCV doesn't seem to support that functionality. I used opencv to read RTSP streams and webcams. Can anyone suggest a way here. Currently I am accessing the stream using OBS Studio software. Is there any other module in python that I can use. Thanks in advance.
There's a similar question here. But that approach doesn't work for me.
Edit:
video0 or video1 depends on your system and connected devices.
Turns out we can access this USB device using opencv itself.
In linux you can access these devices at /dev/video0.
import cv2
cap = cv2.VideoCapture('/dev/video0')
I'm yet to figure out how to do this in windows though

How to stream a video using python and opencv without twilio?

I know that video streaming is possible with python using flask framework. But as twilio is a paid platform, is there any other platforms which can be freely used for video streaming.
You can check out this blog written by miguel to develop a video steaming platform using flask.
https://blog.miguelgrinberg.com/post/video-streaming-with-flask
The theory is explained pretty well here and i personally recommend it.
If you want to some recognition or CV stuff you can also checkout tutorial by PyImageSearch.
https://www.pyimagesearch.com/2019/09/02/opencv-stream-video-to-web-browser-html-page/
I think this tutorial is more relevant for you but if you are new to python you may find this a bit overwhelming.

Streaming audio and video

I've been trying for a while but struggling. I have two projects:
Stream audio to server for distribution over the web
Stream audio and video from a webcam to a server for distribution over the web.
I have thus far tried ffmpeg and ffserver, PulseAudio, mjpegstreamer (I got this working but no audio) and IceCast all with little luck. While I'm sure this is likely my fault, I was wondering if there are any more option?
I've spent a while experimenting with Linux options and was also wondering if there were options with Python having recently played with OpenCV.
If anyone can suggest more options to look into Python or Linux based it would be much appreciated or point me at some good tutorials or explainations of what I've already used it would be much appreciated.
A good start for trying different options is to use vlc (http://www.videolan.org) Its file->transmit menu command opens a wizard with which you can play.
Another good one is gstreamer, (http://www.gstreamer.net), the gst-launch program in particular, which allows you to build pipelines from the command line.
As for me, RTSP casting is the easiest way.
GStreamer can do a lot of stuff, but you cannot start RTSP server just with gst-launch. One needs to compile an own RTSP server from gst-rtsp package. Compiling one of gst-rtsp examples will do.

Categories