python rtsp to webrtc - python

I want to pass an h.264 or MJPEG RTSP stream from an IP camera directly to a webRTC session in a browser, without re-encoding. It has to be done in python, because the target is to have such RTSP/WebRTC gateway reside on the camera itself, which has a python interpreter. The stream is one way, to the browser only. I'm a python freshman, so any hints, ideas, or links to existing libraries are welcome.
I've seen the writeup at http://www.codeproject.com/Articles/800910/Broadcasting-of-a-Video-Stream-from-an-IP-camera-U, but this requires transcode to VP8 (and is not python).
Also reviewed the thread at Use an IP-camera with webRTC and looked at the Kurento media server (nodejs) and Janus gateway (C).
One of the commenters said "you could probably very easily use the native webrtc API and provide an RTSP stream through it." Do there exist any python bindings to the native WebRTC api? Am I deranged for even thinking such a gateway application is possible in python?

Firefox supports H.264 (via the OpenH264 plugin, which is automatically downloaded). Chrome will be adding H.264 "soon". Neither supports MJPEG, nor does the native webrtc.org code - though MJPEG is supported by all of them as a camera-capture source, and it wouldn't be particularly hard to add an MJPEG video codec to the native webrtc.org code. (Non-trivial, however, because of the number of things you'd need to change.)
Note that if this traverses the open internet (or even potentially a wifi link) your solution will be unable to easily adapt to bitrate changes without asking the IP camera to change it's rate.

Related

webrtc without a browser

Right now I am using this project here. It is a python script that runs a server using webrtc to send the clients/browsers webcam to the server and perform face recognition. What I want to do is do the same thing with a web cam or pi cam hooked up to the pi but without the use of the browser. Is there a way to do it with the current set up or is there a better method to accomplish this?
You can use the native library and connect it to the face recognition server. You can use either the google implementation of webrtc or a more recent implementation (by Ericsson) called openWebrtc. The developers of openWebRTC are very proud of running their implementation on various pieces of hardware like raspberry pi and iOS devices.
If you don't what to mess with a native library you can use a nodejs binding for webrtc (for example node-webrtc or easyrtc)
If you want a Python implementation of WebRTC, give aiortc a try. It features support for audio, video and data channels and builds upon Python's asyncio framework.
The server example illustrates both how to perform image processing on a video stream and how to send video back to the remote party. Aside from signaling there is no actual "server" or "client" role in WebRTC so you can also run aiortc on your raspberry pi and have it send video frames to whatever WebRTC endpoint you want.

streaming media over HTTP

I'm writing a web service to stream video (e.g., web cam). I want to know what options do I have.
For example, one naive way I can think of is to periodically fetch a jpeg from the source and display it.
But I also know some media types like mjpeg can be streamed over the HTTP. However I do not know exactly how that is achieved technically. Any example would be welcome.
UPDATE:
I found the below link, which implements a live video stream over HTTP using mjpeg and python WSGI.
Streaming MJPEG over HTTP with gstreamr and python – WSGI version (GIST)
Forget about gstreamer or ffmpeg.
create RAM DISK
install openCV , within infinite loop with "read()" write each frame into RAM DISK as jpg with Pillow
install https://snapcraft.io/mjpg-streamer point to ram disk and enable delete after read.

Capture/Restream streaming web cam video over network with VLC or Python

I have streaming video from a web cam that is accessible via a public ip I opened up on my machine. As in I can go to http//ip/webview and view the video with (I did have to install the activex hidvrocx.cab plugin). The video source itself is h.264 and, according to wireshark, is running on port 9000 over tcp.
What I would like to do is re-stream the raw video, but at this point I would settle for converting it to FLV so I can open is with VLC or something...
According to the technical support team of the webcam (Swann), "netviewer" (some third party software) can view the video feed so there is no encryption / special DRM.
I'm new to this whole thing streaming video world, so this is what I've tried / am considering:
- I've tried loading the stream using VLC at tcp://public_ip:9000, but according to swann support VLC can not view the source because it is raw h.264. Is it possible to use vlc to convert this raw h.264 format into something readable to media players. Possibly...?
vlc src --sout flv
Is it possible to use the python VideoCapture library? Is this strictly for capturing video directly for the device, or does it work over the network?
I'm completely lost right now, so even seeing the raw stream in a media player of any type would be an accomplishment.
TLDR; I have a streaming video source from a webcam over a public IP I would like to ultimately "redistribute" in it's original format (h.264) or flv. How do I accomplish this?
vlc <input_stream> --sout=#std{access=http,mux=ts,dst=<server_ip>:<port>/}
This command will re-stream your Input stream to http with ts muxer
Also you can try rtp/rtsp:
vlc <input_stream> --sout=#rtp{sdp=rtsp://<server_ip>:<port>/XXX.sdp}
will re-stream to rstp protocal

Python livestream to RTMP server (Flash Media Server clone?)

I would like to play around with coding an application that could capture a desktop or section of a screen (height and width variables for resolution) and stream those to an RTMP server (rtmp://server.com/live).
I saw something called rtmplite, but the description of this package is:
"This is a python implementation of the Flash RTMP server"
So I would ultimately like to achieve the following, but will implement it in pieces as I go along, without getting overwhelmed at the project scope:
Make connection to RTMP server (with authentication where needed) to channel on ustream.com, justin.tv/twitch.tv, own3d.tv, etc.
Ability to select height, width selection of desktop or entire desktop and stream live to that channel, as if I was using Flash Media Live Encoder.
Really I just want to make my own Python-based FMLE or Xsplit application so I can stream live on my own without using those applications.
Any libraries you can send me to read up on that explain this FMLE-clone type process or information would be helpful! Thanks
I did some RTMP streaming from python for the wiidiaplayer project: http://wiidiaplayer.org. This is by no means a full solution, but at least some RTMP functionality has been implemented in python there.
Unfortunately it has been a long time since I touched that code; if you have any questions feel free to ask them; I'm not sure how much of the answers I will be able to provide.

Verify RTSP service via URL

I am trying to verify that a video service is provided from an URL in python. I am asking does anyone know of any good libraries to use or a way to do this. I have not found much info for this on the web.
Thanks
Digging around on StackOverflow I came across a previous question asking for an RTSP library in Python or C/C++ .
Linked there is an RTSP library provided by Twisted, and another one called Live555. Have you tried either of these?
I am just reposting the links for convenience.
If you do not want to use a library, as suggested by synack, you can open a socket connection to the given URL and send an RTSP DESCRIEBE request. That is actually quite simple since RTSP is text-based HTTP-like. You would need to parse the response for a meaningful result, e.g look for the presence of media streams.
If you try to validate the URL itself as a valid RTSP URL, I think that it's only the protocol token that changes from http:// to rtsp:// or rtspu://, and implicitly, the default port is no longer 80, but 554.
See RTSP RFC, section 3.2 ("RTSP URL") for more details regarding URL format.
However, if wish to know if "behind" a given RTSP URL there's a running RTSP server, you should actually open a connection to this server, usually using TCP sockets. You can make the "conversation" simply via code, but I suggest you use some kind of a product/library that provides RTSP stack for Python; I don't know if such product actually exists for Python, but there are a few things for C/C++.
I don't believe Live555 provides a python library. However, they do provide source code that can be compiled to build openRTSP. This is a simple command-line utility that will perform the entire RTSP handshake to connect to the server and begin streaming to the client. It also can provide statistic measurements (such as jitter, number of packets lost, etc.) that can be used to measure the quality of the streaming connection.

Categories

Resources