How to build up DVB-C TVHeadend Server with RaspberryPi as Networking TV Client and put Logo on output stream with ffmpeg

How to build up DVB-C TVHeadend Server with RaspberryPi as Networking TV Client and put Logo on output stream with ffmpeg

What we need:

  1. Raspberry Pi (Version 3+ Recommended)
  2. Fritzbox Cable or DVB-C Adpter (Xbox Tuner)
    - Fritz!Box 6591: https://amzn.to/3b3JGIe
    - Fritz!Box 6490: https://amzn.to/2u77MRX
    - Fritz!Box 6660: https://amzn.to/370BxkC
    - Fritz!Box 6430: https://amzn.to/36UQswQ
    - Fritz!WLAN Repeater DVB-C
  3. Coax Cables / Adpters

First step: Create your Coax Cable or Adapter with the DVB-C Port and start your Tuner:

Here you can see FB6490 with extened scan 1MHz steps. Maybe you can also do a more extended range 130 - 890 Mhz

You have to do two scans here for best results: QAM64 for SD / QAM256 for HD

Step two: Run Kodi on your Raspberry Pi (Libreelec / OSMC) and install tvheadend server and HTSPclient

Also login with ssh on your raspberry and set IP's for your tuner.

For example here a script which can be put to /storage/.config/autostart.sh

#!/bin/bash
echo "set up tvh tuner IPs"
sleep 2
##
## setup tvh ips

ip addr add 10.16.22.10/16 dev wlan0
ip addr add 10.16.22.11/16 dev wlan0
ip addr add 10.16.22.12/16 dev wlan0
ip addr add 10.16.22.13/16 dev wlan0

exit 0

#Starting tvh server with paramaters...
here you have to replace IPs with your wished IPs and wlan0 with the Rasp Interface

Step Three: Starting of TVHServer and Config your Muxes

Now start your thx server with: http://<IPOFTHERASPBERRYPI>:9981

#XMLFILE:
http://<IPOFFRITZ>:49000/satipdesc.xml

Setup Tuner Cards:

Set DVB-4 and for every tuner set the virtual IP and Pass specinv unset against other manuals in the net!

Setup Muxes:

Here you can see (use) my predefined Muxes for Vodafone / Satelite with Headstation: (BetaDigital)

Important info for headstations / unknown frequencies!
It is recommended to scan first with w_scan2 or some other tools like the Fritzbox itselfes:
You will get something like that:
#created on 2022-08-11 
#w_scan2 -A 2 -fc -c DE -x > channel_xine.all
#dvb-format-convert -I CHANNEL -O DVBV5 channel_xine.all de-HES-HEAD-VF 

[CHANNEL]
    DELIVERY_SYSTEM = DVBC/ANNEX_A
    FREQUENCY = 306000000
    SYMBOL_RATE = 6900000
    INNER_FEC = NONE
    MODULATION = QAM/64
    INVERSION = AUTO

[CHANNEL]
    DELIVERY_SYSTEM = DVBC/ANNEX_A
    FREQUENCY = 314000000
    SYMBOL_RATE = 6900000
    INNER_FEC = NONE
    MODULATION = QAM/64
    INVERSION = AUTO

[CHANNEL]
    DELIVERY_SYSTEM = DVBC/ANNEX_A
    FREQUENCY = 346000000
    SYMBOL_RATE = 6900000
    INNER_FEC = NONE
    MODULATION = QAM/64
    INVERSION = AUTO

[CHANNEL]
    DELIVERY_SYSTEM = DVBC/ANNEX_A
    FREQUENCY = 466000000
    SYMBOL_RATE = 6900000
    INNER_FEC = NONE
    MODULATION = QAM/64
    INVERSION = AUTO

[CHANNEL]
    DELIVERY_SYSTEM = DVBC/ANNEX_A
    FREQUENCY = 362000000
    SYMBOL_RATE = 6900000
    INNER_FEC = NONE
    MODULATION = QAM/64
    INVERSION = AUTO

[CHANNEL]
    DELIVERY_SYSTEM = DVBC/ANNEX_A
    FREQUENCY = 370000000
    SYMBOL_RATE = 6900000
    INNER_FEC = NONE
    MODULATION = QAM/64
    INVERSION = AUTO

[CHANNEL]
    DELIVERY_SYSTEM = DVBC/ANNEX_A
    FREQUENCY = 402000000
    SYMBOL_RATE = 6900000
    INNER_FEC = NONE
    MODULATION = QAM/64
    INVERSION = AUTO

[CHANNEL]
    DELIVERY_SYSTEM = DVBC/ANNEX_A
    FREQUENCY = 442000000
    SYMBOL_RATE = 6900000
    INNER_FEC = NONE
    MODULATION = QAM/64
    INVERSION = AUTO

[CHANNEL]
    DELIVERY_SYSTEM = DVBC/ANNEX_A
    FREQUENCY = 378000000
    SYMBOL_RATE = 6900000
    INNER_FEC = NONE
    MODULATION = QAM/256
    INVERSION = AUTO

[CHANNEL]
    DELIVERY_SYSTEM = DVBC/ANNEX_A
    FREQUENCY = 386000000
    SYMBOL_RATE = 6900000
    INNER_FEC = NONE
    MODULATION = QAM/256
    INVERSION = AUTO

[CHANNEL]
    DELIVERY_SYSTEM = DVBC/ANNEX_A
    FREQUENCY = 410000000
    SYMBOL_RATE = 6900000
    INNER_FEC = NONE
    MODULATION = QAM/256
    INVERSION = AUTO

[CHANNEL]
    DELIVERY_SYSTEM = DVBC/ANNEX_A
    FREQUENCY = 450000000
    SYMBOL_RATE = 6900000
    INNER_FEC = NONE
    MODULATION = QAM/256
    INVERSION = AUTO

[CHANNEL]
    DELIVERY_SYSTEM = DVBC/ANNEX_A
    FREQUENCY = 458000000
    SYMBOL_RATE = 6900000
    INNER_FEC = NONE
    MODULATION = QAM/256
    INVERSION = AUTO

[CHANNEL]
    DELIVERY_SYSTEM = DVBC/ANNEX_A
    FREQUENCY = 474000000
    SYMBOL_RATE = 6900000
    INNER_FEC = NONE
    MODULATION = QAM/256
    INVERSION = AUTO

[CHANNEL]
    DELIVERY_SYSTEM = DVBC/ANNEX_A
    FREQUENCY = 122000000
    SYMBOL_RATE = 6900000
    INNER_FEC = NONE
    MODULATION = QAM/256
    INVERSION = AUTO

[CHANNEL]
    DELIVERY_SYSTEM = DVBC/ANNEX_A
    FREQUENCY = 322000000
    SYMBOL_RATE = 6900000
    INNER_FEC = NONE
    MODULATION = QAM/256
    INVERSION = AUTO

[CHANNEL]
    DELIVERY_SYSTEM = DVBC/ANNEX_A
    FREQUENCY = 170000000
    SYMBOL_RATE = 6900000
    INNER_FEC = NONE
    MODULATION = QAM/256
    INVERSION = AUTO

[CHANNEL]
    DELIVERY_SYSTEM = DVBC/ANNEX_A
    FREQUENCY = 130000000
    SYMBOL_RATE = 6900000
    INNER_FEC = NONE
    MODULATION = QAM/256
    INVERSION = AUTO

[CHANNEL]
    DELIVERY_SYSTEM = DVBC/ANNEX_A
    FREQUENCY = 138000000
    SYMBOL_RATE = 6900000
    INNER_FEC = NONE
    MODULATION = QAM/256
    INVERSION = AUTO

[CHANNEL]
    DELIVERY_SYSTEM = DVBC/ANNEX_A
    FREQUENCY = 146000000
    SYMBOL_RATE = 6900000
    INNER_FEC = NONE
    MODULATION = QAM/256
    INVERSION = AUTO

[CHANNEL]
    DELIVERY_SYSTEM = DVBC/ANNEX_A
    FREQUENCY = 154000000
    SYMBOL_RATE = 6900000
    INNER_FEC = NONE
    MODULATION = QAM/256
    INVERSION = AUTO
adding in kodi to /.kodi/addons/service.tvheadend42/dvb-scan/dvb-c/de-Hes-myFreqs
Alternative add manual mux

Mapping of wished channels and setup EPG

Map all services first
Dont check merge and crypted channels

Set icons

Icons can be load here: https://download.avm.de/tv/logos/

#todo renaming script:

# wget -r -l1 --no-parent https://download.avm.de/tv/logos/ -P /tmp/picons/
# zip -r picons1.zip *.png
Better way to download picons:
#!/bin/sh
wget https://github.com/picons/picons/releases/download/2022-08-11--18-58-57/snp-13e.19e.23e.28e.220x132-190x102.dark.on.reflection_2022-08-11--18-58-57.symlink.tar.xz -P /storage/picons/tvh/
cd /storage/picons/tvh/ ; tar -xvf snp* 
mv snp-13e.19e.23e.28e.220x132-190x102.dark.on.reflection_2022-08-11--18-58-57 snp
exit 0

Go to Configuration → General → Base and set the right path for picions

The %C.png is important for the right service usecase 

Now go to: Configuration → Channel / EPG → Channels and choose all with Reset ans Save again. Now the pics are coming:

most icons are now found

Setup recording / timeshift etc:

Configuration → Recording → (a profile)

setting up rec - Profile with path

Timeshift:

setup timeshift -storage path with buffer 46MB to RAM

Setup the NAS Server (fritzbox) and Client (tvhserver) with Samba:

Put your USB Disc to the USB Port of the FB and create new SMB User.

Important: Because of UNIX Extensions activate SMB 1.0 Protocol!

On Libreelec TVH Server, you can run this script (Before running this you have to check the SETUP section first):

#!/bin/bash
#
# (C) Suuhmer - 2022

# SETUP SHARE / USERPW / Filename / Path with your own system:
SYSMN=storage-nas-tvh.mount
SYSFN=/storage/.config/system.d/$SYSMN
user=smb
pw=passw0rrd
SHARE=//IP/smb.gw/SHARE/TVH01

echo "Create SMB systemd mount - Libreelec FS"; echo

cat > $SYSFN <<SYSD
[Unit]
Description=cifs mount script
Requires=network-online.service
After=network-online.service
Before=kodi.service

[Mount]
What=$SHARE
Where=/storage/nas/tvh
# BC of UNIX EXTENTIONS : SMBv1.0 , maybe noserverino
Options=username=$user,password=$pw,rw,uid=0,gid=39,file_mode=0664,dir_mode=0775,vers=1.0
Type=cifs

[Install]
WantedBy=multi-user.target
SYSD

sleep 2

echo "Creating dirs Recordings > rec / timeshift > ts"
mkdir -p /storage/nas/tvh/rec
mkdir -p /storage/nas/tvh/ts

sleep 2

echo; echo "Setup sysctl daemon end enable services..."
systemctl daemon-reload
systemctl enable $SYSMN
systemctl restart $SYSMN

echo "finished. now reboot..."
sleep 3; reboot

exit 0
simple script to emnable the systemd mount on startup 

Get playlist in VLC PLayer etc.:

http://YourTVHeadendIP:9981/playlist

With password access:
#From a web browser;

http://USERNAME:PASSWORD@YourTVHeadendIP:9981/playlist/channels.m3u?profile=YOURPROFILENAME

#with cURL

curl -u USERNAME:PASSWORD http://YourTVHeadendIP:9981/playlist/channels.m3u?profile=YOURPROFILENAME

#with wget

wget --user=USERNAME --password=PASSWORD http://YourTVHeadendIP:9981/playlist/channels.m3u?profile=YOURPROFILENAME

Creating Logo/ Watermark in stream with ffmpeg

New Network:

Configuration → DVB Inputs → Networks add Type IPTV Network

Pipe with Transcoding creation:

Configuration → DVB Inputs → Muxes add and use network IPTV

FFMPEG-Befehl > URL field > create:

# OLD STYLE ; SOME NOT SUPPORTED ANYMORE
pipe:///usr/bin/ffmpeg -i $_S_URL -i /opt/test-watermarl.png -filter_complex overlay=main_w-overlay_w-10:main_h-overlay_h-10 
-vcodec libx264 -preset veryfast -s 1280x720 -b 1500k -minrate 1500k -maxrate 1500k -bufsize 1500k -acodec libmp3lame -ab 128k -ar 44100 -strict experimental 
-metadata service_provider=IPTV -metadata service_name=Channel_name -f mpegts -tune zerolatency pipe:1

# NEW 2023
# https://tvheadend.org/boards/5/topics/44815
pipe://ffmpeg -i $_S_URL \
-i $W_LOGO -filter_complex overlay=x=main_w-overlay_w-10:y=10 \
-s 800x600 -b 1500k -minrate 1500k -maxrate 1500k -bufsize 1500k \
-metadata service_name=IPTV_channel_HD -metadata service_provider=IPTV-DE \
-mpegts_service_type advanced_codec_digital_sdtv -f mpegts pipe:1

END MAPPING

Configuration → DVB Inputs → Services and click on name of serv and map it to finish the process.

Script for easy creating m3u playlist and play with ffplay

# SCRPITER
wget https://raw.githubusercontent.com/jnk22/kodinerds-iptv/master/iptv/pipe/pipe.m3u -qO- | \
	sed 's/\-vcodec\ copy\ \-acodec\ copy/\-i\ \/var\/tmp\/logo.png \-filter_complex\ overlay\=x\=main\_w\-overlay\_w\-10\:y\=10/g' | \
	head -n$((8*2+1)) > newstreams_top8.m3u

# SET PLAYLIST URL:  file:///var/tmp/newstreams.m3u

NOW finished Configuration → Channel/EPG erscheinen.

httx://user:pass@IP:9981/stream/chanid/1132214813?ticket=T_ID&profile=pass

ffplay

.\ffplay "http://user:pass@$IP:9981/stream/chaid/?ticket=TID&profile=pass

Logo top right corner on ffplay output video streams example

LOCAL VIDEO

.\ffmpeg.exe -i C:\01TOOLS\ocx.mp4 -i C:\..\test\logo.png -filter_complex overlay=x=main_w-overlay_w-10:y=10 vid-logo.mp4