Use VLC or OMXPlayer to play video streams on your TV with the RaspberryPI, and control it with your phone.
Important: OMXplayer is deprecated starting from Debian 11; VLC is now recommended. The old commands are still available as comments, just in case, but they are not tested anymore.
If you're looking for a way of watching TV via your RaspberryPi, you must already know about Kodi or other media centers. They provide pretty much any feature you might want, together with a beautiful UI. But maybe it's not what you want. Maybe you just have a set of web TV streams that you want to play without having to go through multiple menus. Also, maybe your RaspberryPi is not fast enough to run a media center without lags. If it's the case, then you're at the right place. Because that's exactly what I needed myself.
I developed this small Python program for my RaspberryPi Zero W and a standard definition screen ; for HD, it might be worth consedering a more powerful RPi. This program was originally based on daaanny90's Remote-Raspberry project, which introduced me to Flask (yes I'm a beginner) and served as a model for mine.
I'm assuming you're using Raspberry Pi OS (aka Raspbian) with username pi.
- Clone the repo into your Raspberry Pi's home folder.
- Install Flask if not already installed with
sudo apt install python3-flaskor (not tested)sudo pip install flask - Add
python3 /home/pi/RasPiTV/server.pyto your /etc/rc.local file - Strongly recommended: increase GPU memory to at least 128MB (I set it to 192MB for my Pi Zero W but feel free to try other values)
- As this program is taylored for my own configuration, you might want to modify the omxplayer command (for example, remove the
-o alsa:hw:CARD=Deviceparameter if you want the audio to be sent to the HDMI instead of dedicated card) - Put your streams in
channels.py. The filechannels_hd.pyisn't used by the program by default. You can put ASCII-style logos inlogos.py - Youtube-DL is temporarily not supported. If you plan to play videos from Youtube, download and install the latest version of Youtube-dl
Important notes
- If you did follow the steps above, then the server starts automatically on startup. It is run as root. I know this isn't good practice, and VLC complains about it. Maybe it will be improved in the future, maybe not.
- The streams addresses in the files
channels.pyandchannels_hd.pyare French TV streams from https://github.com/HugoPoi/9boxtv. They are here as an example. It's not free content; use them only if you have the right to do so.
When the server is running, you can reach the frontend writing the IP address of your Raspberry Pi on the browser. This address is given under the RasPiTV logo at startup.
This is what you will see (from a smartphone):

Just press a button to start watching TV. I suggest to give a static IP to your Pi and put a shortcut on the home screen of your phone.
If you want to play a custom stream, paste the link and click on Submit custom stream. If you want to play a Youtube video, paste the link to that video and click on Submit Youtube video. It will use youtube-dl to get the MP4 link that will be forwarded to OMXPlayer. Please note that this can take some time.