⬆️ ⬇️

Stable IPTV broadcasting via VLC

I had to get acquainted with IPTV more closely, when in the company of the Internet provider where I worked, they decided to organize IPTV broadcasting. It turned out that the broadcast is carried out in linux and the program vlc, which is rumored to be the only one of its kind. A dish was installed and a SkyStar2 DVB-card, which supposedly should have been made in linux without any problems. So it was with all the new machines where the ubuntu server was installed. On Debian, it worked only after updating the kernel. Setup was relatively easy, since at that time there were already several articles on this topic and the documentation for the vlc was also very useful. After the launch, some problems started with the loss of sound and video on the channels and other problems described below. After their appearance, scripts were written to eliminate these problems. Now they have 3 servers with 5 dvb-cards in total, and 23 channels with 3 satellites are broadcast. Under the cut - a list of problems that may appear after the launch of IPTV broadcast via VLC in Linux and how to deal with them. We will fight using bash.





The initial setup and launch of IPTV broadcasting is well described in the article “Reception of satellite TV channels in linux” .

The main problems with IPTV broadcasting are a memory leak and video or sound is lost in one of the channels.



Memory leak



The problem of memory leakage is solved either by 1) restarting the vlc daemon once a day or more if necessary via crontab or 2) periodically checking the free memory and rebooting the daemon while reducing the summary memory to a certain value.

')

one)

crontab:

# Reboot vlc at 3 am

0 3 * * * /home/desecho/vlc/vlc_regular_reload.sh



vlc_regular_reload.sh:

#!/bin/bash <br/> echo "`date`;VLC regular reload" >> /home/desecho/vlc/logs/vlc_restart.log<br/>/home/desecho/vlc/vlc_starter.sh<br/>




2)

crontab:

# Check every 5 minutes

* / 5 * * * * /home/desecho/vlc/memory_check.sh



memory_check.sh:

#!/bin/bash <br/> # <br/>free_mem=$(free -m | grep ^M | awk -F ' ' '{print $4 }' )<br/> # <br/>mem_limit= 16 <br/> # <br/> if [ $free_mem -le $mem_limit ]<br/> then <br/> echo "`date`;Memory Overload" >> /home/desecho/vlc/logs/vlc_restart.log<br/> /home/desecho/vlc/vlc_starter.sh<br/> fi <br/>




Loss of video or sound



To solve the problem, it is necessary to periodically check the presence of video and sound in the channels.

The implementation of scripts on the example of broadcasting two channels. Broadcasting comes in two streams - original and compressed. Sometimes it helps to restart the problem channel, but sometimes a complete reboot of the daemon is necessary.



To run the script, you must run the following commands:



cp /usr/bin/vlc /usr/bin/vlc2<br/> touch /home/desecho/vlc/run.sh<br/> chmod +x /home/desecho/vlc/run.sh<br/>




Script start and reload channels:

vlc_starter.sh:

#!/bin/bash <br/> echo "`date`;Reloaded" >> /home/desecho/vlc/logs/vlc_restart.log<br/> <br/> # vlc <br/> killall - 9 vlc<br/> # <br/>vlc --no-stats -vvv --color --daemon --ttl 12 --ts-es-id-pid --dvb-adapter 0 --programs= 13 , 14 dvb: --dvb-frequency= 10995000 --dvb-srate= 20000000 --dvb-voltage= 13 --sout '#duplicate{dst=std{access=http,mux=asf,url=0.0.0.0:8001},select="program=13",dst=std{access=http,mux=asf,url=0.0.0.0:8002},select="program=14"}' <br/> # <br/> sleep 5 <br/> # 820Kbit/s 70Kbit/s <br/>vlc http: //127.0.0.1:8001 -vvv --daemon --color --sout '#transcode{vcodec=mp4v,vb=820,scale=1,acodec=mpga,ab=70,channels=1}:duplicate{dst=std{access=http,mux=asf,url=0.0.0.0:8011}' <br/>vlc http: //127.0.0.1:8002 -vvv --daemon --color --sout '#transcode{vcodec=mp4v,vb=820,scale=1,acodec=mpga,ab=70,channels=1}:duplicate{dst=std{access=http,mux=asf,url=0.0.0.0:8012}' <br/>




Channel check script:

vlc_restarter.sh:



#!/bin/bash <br/> <br/> # <br/> #$1 - id <br/> function rec {<br/> # <br/> b= "vlc2 http://127.0.0.1:80$1 -vvv --color --daemon --noaudio --sout '#duplicate{dst=std{access=file,mux=asf,dst=\"/home/desecho/vlc/0$1.avi\"}}'" <br/> # - - vlc <br/> echo $b > /home/desecho/vlc/run.sh<br/> /home/desecho/vlc/run.sh<br/> # <br/> b= "vlc2 http://127.0.0.1:80$1 -vvv --color --daemon --novideo --sout '#duplicate{dst=std{access=file,mux=asf,dst=\"/home/desecho/vlc/0$1.mp3\"}}'" <br/> echo $b > /home/desecho/vlc/run.sh<br/> /home/desecho/vlc/run.sh<br/> sleep 5 <br/> killall - 9 vlc2<br/>}<br/> <br/> # vlc <br/> #$1 - <br/> function reload {<br/> echo "`date`;$1 - Reload" >> /home/desecho/vlc/logs/vlc_restart.log<br/> /home/desecho/vlc/vlc_starter.sh<br/>}<br/> <br/> # <br/> #$1 - id <br/> #$2 - <br/> function check {<br/> # <br/> y= "$(du /home/desecho/vlc/0$1.avi | grep -oE --regexp='[0-9]+' | sed -n '1p')" <br/> # <br/> if [ $y -gt 10 ] ; then <br/> x011=1<br/> else <br/> x011=0<br/> fi <br/> # <br/> y= "$(du /home/desecho/vlc/0$1.mp3 | grep -oE --regexp='[0-9]+' | sed -n '1p')" <br/> if [ $y -gt 10 ] ; then <br/> x012=1<br/> else <br/> x012=0<br/> fi <br/> echo " $2 - $x011 $x012" >> /home/desecho/vlc/logs/vlc_restart.log<br/> let x01=x011+x012<br/> # , z=0 <br/> if [ $x01 != 2 ]<br/> then <br/> z=0<br/> else <br/> z=1<br/> fi <br/>}<br/> <br/> # <br/> #$1 - id <br/> #$2 - <br/> function check_full {<br/> # <br/> rec $1 <br/> # <br/> check $1 $2 <br/> # z <br/> if [ $z = 1 ] ; then <br/> z[ $1 ]= 1 <br/> fi <br/>}<br/> <br/> # <br/> #$1 - id <br/> #$2 - <br/> #$3 - id <br/> function restart {<br/> echo "`date`;$2 - Restart" >> /home/desecho/vlc/logs/vlc_restart.log<br/> # <br/> a= "$(ps -C vlc -o '%p%a' | grep " http: //127.0.0.1:80$3 -vvv --daemon --color --sout" | grep -oE --regexp='[0-9]+' | sed -n '1p')" <br/> kill $a <br/> # <br/> b= "vlc http://127.0.0.1:80$3 -vvv --daemon --color --sout '#transcode{vcodec=mp4v,vb=820,scale=1,acodec=mpga,ab=70,channels=1}:duplicate{dst=std{access=http,mux=asf,url=0.0.0.0:80$1}'" <br/> echo $b > /home/desecho/vlc/run.sh<br/> /home/desecho/vlc/run.sh<br/>}<br/> <br/> # <br/> #$1 - id <br/> #$2 - <br/> #$3 - id <br/> function fix {<br/> # <br/> if [ ${z[ $1 ]} != 1 ] ; then <br/> restart $1 $2 $3 <br/> sleep 5 <br/> # <br/> check_full $1 $2 <br/> fi <br/> # VLC <br/> if [ ${z[ $1 ]} != 1 ] ; then <br/> reload $2 <br/> exit <br/> fi <br/>}<br/> # 0 z <br/>z[ 11 ]=0<br/>z[ 12 ]=0<br/> <br/> # / <br/>check_full 11 perviy<br/> # / <br/>fix 11 perviy 01 <br/> <br/>check_full 12 rossiya<br/>fix 12 rossiya 02 <br/> <br/> echo "`date`;DVB - Status: Stable" >> /home/desecho/vlc/logs/vlc_restart.log<br/>




It remains to add an entry to the crontab:

* / 5 * * * * /home/desecho/vlc/vlc_restarter.sh



As a result, we get a system that will automatically restore the broadcast channels when video or audio is lost. All actions of the broadcast restoration scripts will be written to the log file.

Happy broadcasting!



UPD: Transferred to IPTV blog. PS Thanks for the karma!

UPD2: To neutralize a memory leak, you can collect vlc without the “optimisememory” flag or try updating vlc, see the article “Broadcasting video files using VLC multicast. With theory . Thank you Breaker .

Source: https://habr.com/ru/post/66351/



All Articles