Livestreaming to a web

S.L.P. image questions, stereoscopic video livestream and recording, stereoscopic photo capture etc.
Post Reply
AlexVega
Posts: 6
Joined: Mon Feb 08, 2021 7:50 pm

Livestreaming to a web

Post by AlexVega »

Hi everyone!!

I'm trying to do a livestreaming to a web with the StereoPi using the Rasbian OS and python. I'm not sure if for the SLP image has been done it with python or any other way.

I was going to try to do it with OpenCV but as I saw in the forum is not a good way to make a livestreaming video. There's a way to do it with Python or is better using another way?

Also, I'm not using the SLP because I'm not sure if I can adapt it to the project I'm trying to do. What I want to do is:

1) Display the livestream via web
2) Control the StereoPi from the web, sending messages to the StereoPi (forward, backwards i.e.)
3) The messages receive by the StereoPi also will be send to another controller (motor) via Bluetooth by the StereoPi

If it is possible modify the SLP image to also allow it to do something like that or even better to implement python programs on it, that will be amazing cause it will take a lot of work out of the project.

Thank you for your help and time!!

PS. If anything is not clear please tell me because my english is a bit rusty since I didn't use it in a while :)

zoldaten
Posts: 44
Joined: Fri Apr 26, 2019 7:07 am

Re: Livestreaming to a web

Post by zoldaten »

Привет.

SLP image - это просто Raspbian Stretch без GUI, причем не обновленный и sudo apt-get update|upgrade добавит массу хлопот. Я обновился, но в некоторых моментах до сих пор разгребаю ошибку "bad gateway" при поддержке разработчика.
Разработчик писал про обновленную версию SLP image в обозримом будущем.

Кроме того, на SLP уже стоит python 3.5.x и 2.7.
В цикле при запуске крутятся скрипты php, которые выдают livestream на 80 порт на любой вкус и цвет. Виды livesteamов можно менять прямо через web-интерфейс.
Скрипты можно поубивать либо переделать под себя. Сервер тоже можно снести, он в var/www/html. Но тогда Raspbian не будет ничем отличаться от обычного Raspbian )

Контролировать с web raspberry можно как и любую другую raspberry, gpio те же.

По поводу Bluetooth пошукай форум, тут было про bluetooth и кто-то даже что-то прикручивал. Но коллективный вывод по bluetooth - плохая идея, все за wifi или провода.

AlexVega
Posts: 6
Joined: Mon Feb 08, 2021 7:50 pm

Re: Livestreaming to a web

Post by AlexVega »

Hi zoldaten!!

Sorry for the inconvenience but I didn't quite get it since the translate app has flaws translating technical stuff to english or spanish!!

As I understood, you said that it is possible to work with python on the SLP, i suppose is using the ssh control, am i right?

I'm a little lost with the headless use of RPi, I will search for extra info (if you have some I'll appreciate it so much)

Thank you for your help an answer!!!

zoldaten
Posts: 44
Joined: Fri Apr 26, 2019 7:07 am

Re: Livestreaming to a web

Post by zoldaten »

Sorry ) I thought you are from Russia )

So,here is the translation.

SLP image - it`s just Raspbian Stretch without GUI, and you cannot simply update it with "sudo apt-get update|upgrade".
I did that but it`ve taken a lot of time and effort to fix errors in some cases.
"Realizator" annonced a new version of SLP in near future.

SLP has python 3.5.x и 2.7 pre-installed.
At start php scrpits are running providing web-interface and livestream to 80 port. Types of livesteams can be changed in web-interface.
Php scrpits can be killed or changed as you wish. Server also could be removed (he`s in var/www/html). But after that Raspbian will look as standard Raspbian )

You can control gpio raspberry as usual but as i found recently stereopi has inverted placement of gpio.

As to Bluetooth use there`s a discussion in forum of it. To sum up - bluetooth bad idea, wifi is better. But tastes differ.

stereomaton
Posts: 210
Joined: Tue May 21, 2019 12:33 pm
Location: France

Re: Livestreaming to a web

Post by stereomaton »

If I understand your project well, you want to have:
1) a live stream
2) be able to send messages and report status to an autonomous application you design, via a web interface

There are many ways to achieve this. I would say that the easiest would probably be to start with SLP to take advantage of the streaming part that is already built, and start a different web interface on another port in your application (which gives an address like http://stereopi.local:8000/ for port 8000). Since you use python, which is installed in SLP, you can make your interface with flask, bottle, aiohttp, ... (many frameworks exist)
Alternatively, you could modify the PHP web interface of SLP to add buttons for example, and call your script from PHP (or send it a message via socket or fifo if it is supposed to run continuously).

If you do not want to use SLP, you could look at gstreamer to stream your video. With OpenCV, you could use a cv2.VideoWriter to start a gstreamer pipeline starting with an appsrc element. [Note: I never done it myself, but noted this info to do it later]
Stereophotographer and hacker
Despite my quite active participation in the forum, I am not in the StereoPi team
StereoPi (v1) Standard Edition + CM3Lite module + a few cameras

AlexVega
Posts: 6
Joined: Mon Feb 08, 2021 7:50 pm

Re: Livestreaming to a web

Post by AlexVega »

Hi Stereomaton!!

First of all thank you for the reply!! That's it, you got it right, but for complicate it a lil bit more, I am trying to do it without using SLP (I love the environment but I'm kinda new in this world and for me is a lot easier use Raspbian, at least for now, I found it lot simpler).

I've followed your advice and looked up for gstreamer, the thing is, I didn't find anything that worked for me yet. Do you have some resources or something else I can look up? Maybe is because I'm trying to do it with Python, not sure if it's possible or if I have to use C/C++

Again, really thankful for your reply has me looking in another direction that I didn't know about!!!

User avatar
Realizator
Site Admin
Posts: 686
Joined: Tue Apr 16, 2019 9:23 am
Contact:

Re: Livestreaming to a web

Post by Realizator »

AlexVega, I'd recommend you to download /opt/StereoPi and /var/www folders from the SLP and look at the code. All you need is in these folders.
Look at the file names in the /opt/StereoPi/scripts folders:
loop-mpegts-skybox.sh
loop-mpegts.sh
loop-record.sh
loop-rtmp.sh
loop-rtsp.sh
loop-ws.sh
record-watcher.sh
usb-video.sh
video-source.sh
wlan-switch.php
wlan.lib.php

I think they are clear :-)

And in the /var/www/html you can find all admin panel items (like make_photo.php) and JS scripts. So you can use them as a tutorial.

One global tip for you. We have a key script video-source.sh It has two logic ways (look inside the code please):
1. RTSP - in this case, we are getting raspivid video and, with GStreamer and our RTMP binary, stream it to the server
2. All other cases - we are using our "splitter" binary to split video streams to several directions (like UDP stream, video recording, browser stream etc.). You can exclude splitter if you need to stream to the single point only (like the browser). Also, the splitter is doing re-striming to the local ports (like 3002 for RTMP, 3004 for mpegts etc.) And all related scripts in /scripts are listening for appropriate port to get the video as an input.

All that stuff was done for the flexible configuration of a few video streams simultaneously. As I mentioned, if you need just a single stream, you can greatly simplify this and put just a single line of code to do this.
Eugene a.k.a. Realizator

stereomaton
Posts: 210
Joined: Tue May 21, 2019 12:33 pm
Location: France

Re: Livestreaming to a web

Post by stereomaton »

I do not have special links in mind for gstreamer and have not played with it yet. It can be controlled via python with deep access, but it is not simple. Using the VideoWriter is simpler because you only have to write the downstream pipeline in the string form, but not easy for beginners.

However, I just realized that most people use a graphical interface and that it is probably what you meant by Raspbian is simpler. (I did not understand before, as SLP is based on Raspbian itself, and I rarely use an embedded GUI so I did not see the difference)

With that in mind, I would advise the same thing as realizator: copy the programs from SLP to have the streaming part on your Raspbian together with the desktop interface, and use the first part of my previous answer in this new hybrid environment.
Stereophotographer and hacker
Despite my quite active participation in the forum, I am not in the StereoPi team
StereoPi (v1) Standard Edition + CM3Lite module + a few cameras

Post Reply