Streaming and recording video with Python - python

I thinking about architecture of service with video streaming.
2 people call to each other in browsers with webcams (like group talks in google plus, but only 2 people). Their conversation dumping to server. Server know when conversation was started, when it was finished and which clients communicate.
At the backend I plan to use Python/Django. I don't have any ideas about what to use for streaming/frontend(html5, flash). I want to controle streaming process (dumping, start|stop conversation) using python.
What you can recommend to me?

I think you need to look at the following two -
http://videocapture.sourceforge.net/ #For video recording purpose
and
http://twistedmatrix.com/trac/ #For transmission over the network
Following example using Twisted might be of some help -
http://www.rtmpy.org/index.html

Related

How to stream multiple ESP32-CAM's to a Python Server and serve stream to clients over the cloud

I am developing a live monitoring application using multiple resources. The server is a Python Flask Application (Running on GCP using a docker container in cloud run). For the database for storing users, we chose Firestore, and authentication is done using JWT. The client application was created with React Native and receives information from the server using basic HTTP methods in a JSON format.
As for now, the whole system works, but it is still missing the live cameras. I never played around with live video streaming or anything like that.
For hardware, we chose ESP32-CAM modules as they are cheap and easy to maintain.
The problem is that I have no idea how to stream the camera content to the server and serve that to the client. Remember that the cameras would be at various locations with no external IP access, so the server couldn't just make capture requests for the camera; the camera themselves will have to send the information to the server.
I took a look at some ESP32-CAM libraries and various communications methods, but none fit what I am trying to do or that have enough documentation for a basic understanding. Some were RTSP, FFmpeg, Sockets, HLS, WebRCT. It must be compatible with the ESP32 (C++ or/and Arduino libraries) and Python packages. (With ports allowed to be accessed by GCP if needed)
Lastly, I would like suggestions on how and what to use to transmit the data to the final client.
Below is a quick schematic for the current infrastructure.
Schematic

How do I build a video chat application using python

Just finished my studies on python 3, build some app and I want to on to my main project. Please how can I build a video chat application using python
That is quite an ambition challenge! I would start by writing a GUI interface so that users can start/end/pause the video call and mute their camera or microphone. Tkinter, wxPython, and PyQt are a few decent ones. After that, I would do some research on networking and figure out how to send the video to and from each recipient. I would look into RTP (Real-Time Transport Protocol) for that. You could even establish a UDP connection between the two. The number of approaches are endless! I encourage you to do some more in-depth research before you begin.
**Note that this process would be different if you were to make a video chat website.
Best of luck!

Creating an Action Server & Client in ROS

I'm trying to setup a ROS Action server & client to handle sending images (encoded as 64-bit strings) between Python and ROS (with the goal of making the image something other scripts can pull from ROS). Being very new to all of this (Python, Ubuntu, Bash, ROS, etc...), I'm having a very difficult time determining HOW exactly to do this. I think part of the reason is that the ROS wiki tutorials/documentation are linear to a fault, and the process just comes across as convoluted and extraordinarily complicated. Does anyone out there know of any non-ROS-wiki related/dependent tutorials to help me figure this out? Or can you create a concise step-by-step guide to establishing this system? I've been unable to find much of anything relating to this topic specifically - which makes me think it's either a very uncommon use, or it's super easy and I'm just not at that level yet.
My attempt at a solution is essentially just getting the information flow down. I want Python to be able to read in an image, convert it to bytes (using b64encode), and send it over to ROS to publish as an action. (Thus, a stream of images can be sent with no pause, as would be done with a service, if I understand correctly.) Anything subscribed to the node (or server, however that works, I'll figure it out when I get there) can then see the images and pull them from the action server.
Now, I'm being told an action is the best way to do this. Personally, I don't see why a service wouldn't suffice (and I've at least gotten one of those to work).
Thanks again for any help you all can provide!
Edit: The end application here is for video streaming. A server will grab live video, convert it to images, change those to byte strings, and stream them to the client, which will then publish them to a ROS Action Server.
I think you're overcomplicating it. I wouldn't implement it as an actionlib server, although that is one approach. I've created a few similar systems, and this is how I structured them:
Write your node that streams video by publishing images on a topic. You can implement this as an actionlib server, but that's not required. In my case, I used the pre-existing raspicam_node to read a Raspberry Pi's camera. If you want to implement this in Python, read the tutorial on creating a publisher.
Create a node that subscribes to your image topic, and then reads the image from the topic message. Again, the tutorial shows how to create a subscriber. The main difference is that you'd use either CompressedImage or Image from sensor_msgs.msg as your message type.
For the subscriber-side, here's an example Python ROS node I wrote that implements a MJPEG streamer. It subscribes to a topic, reads the image data, and re-publishes it via a streaming HTTP response. Even though it's "slow Python", I get less than 1 second of latency.

Creating a real-time chat with Python and websocket

I'm writing a python real-time chat feature embedded in a web app. I'm a little bit confused on the real time implementation. I need to push real time message to different users.
I plan to use websocket but I'm not quite sure how to save those sockets into an array so that once a user send a message to server, the server can find the related socket and push the message.
So any idea about this? Or what's the common way to implement real time chat feature?
Thanks in advance.
You need to use a websocket aware web server, like Tornado to handle websocket traffic. To multiplex chat messages between different chats and users, there are solutions like Redis and ZeroMQ that you can use for message multiplexing.
However, it sounds like you have zero experience and starting point, so starting with an working example is better approach. Please study existing real-time chat implementations for Python:
https://github.com/heroku-examples/python-websockets-chat
https://github.com/nellessen/Tornado-Redis-Chat
https://github.com/tornadoweb/tornado/blob/master/demos/websocket/chatdemo.py
http://ferretfarmer.net/2013/09/05/tutorial-real-time-chat-with-django-twisted-and-websockets-part-1/

Webcam streaming in Django project

I am currently working on a Django project and would like to add the ability for uses to enter a video conference with each other using their webcams. I understand html5 has capabilities for this, but I would like to stay away from it for now, as quite a few browsers don't yet support it. Anyone have any suggestion as to how I could do this? Thanks.
It's hard to say use this one thing when really it will be a collection of things that meet your individual needs. Here are some links to some resources that should get you started.
OpenCV - Has Python wrappers for webcam
Tornado - Python web framework and asynchronous networking
library
Twisted - Event driven networking engine written in Python
On the client side, you might want to look at getUserMedia.js for handling capturing the video from the camera - it implements a Flash fallback for browsers that don't support the getUserMedia() API.
On the server side, I think Drewness's answer covers it.
The short answer is that you have to use flash or narrow down which browsers you want to support.
The act of getting the stream from your webcam and into the browser is somewhat supported by HTML5 and fully supported by flash in modern browsers.
The tricky part is streaming that to other people in a call. There are two approaches - have everyone pipe their feed to a central server which then beams the collected feeds down to everyone in the room, or have peers directly connect to one another.
For any kind of real time chat app, you want to be using the latter (the latency of a central server architecture makes it unusable).
On the web your options are WebRTC, RTMFP, HLS, or plugins. WebRTC is fantastic, but is still a working standard. Most significantly IE does not support it, so if you expect this to be a public facing web app a sizable percentage of your users will be out of luck. HLS is an apple technology that also has patchy support (and isn't particularly efficient).
For RTMFP, have a look at cirrus/stratus. They have a sample app that illustrates the technology (BTW this is what ChatRoulette uses). Of course this requires flash, but IMO it's your best bet for covering as many platforms as possible without having your users install something first.
The choice of web framework (Django in your case) doesn't matter very much since you don't want your users sending their streams up to the server anyway. The server's job is simply to help with discovery and connection, and for this you should look into a push/comet server like APE.

Categories

Resources