Project

General

Profile

[HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ?

Added by Dimitar Maznekov over 2 years ago

I'm trying to make catchup for IPTV to have +1, +2 etc hours back timeshift for channels which are not recorded by provider.
I've made that setups

1.Mux Schedule for two channels as follow:

2.Setup Timeshift:

There are two streams, but not see any files recorded in /home/hts/timeshift/
And if I'll make that timeshift, how to setup another Mux to start it from -1h ChannelID and watch it one hour ago ?

WORKAROUND

Script file

/home/lib/catch-up/timeshift_hls.sh

#!/bin/bash
/usr/bin/ffmpeg -reconnect 1 -reconnect_at_eof 1 -reconnect_streamed 1 -reconnect_delay_max 2 -y -nostdin \
-hide_banner -loglevel fatal \
-i http://127.0.0.1:9981/stream/channelnumber/$1 \
-vcodec copy -acodec copy -scodec copy -g 60 \
-fflags +genpts -user_agent HLS_delayer -metadata service_provider="TimeShift" \
-f hls -hls_flags delete_segments -hls_time 10 -hls_list_size 360 -hls_wrap 361 \
-hls_segment_filename /timeshift/$1_%03d.ts /timeshift/$1_hls.m3u8
chmod +x /home/lib/catch-up/timeshift_hls.sh

Manual run
./timeshift_hls.sh [channel number]

Service file

/etc/systemd/system/timeshift_Nova.service

[Unit]
Description=Timeshift Nova TV
After=tvheadend.service
PartOf=tvheadend.service
Restart=always

[Service]
ExecStartPre=/bin/mkdir -p /timeshift/
ExecStart=/home/lib/catch-up/timeshift_hls.sh 103 &
ExecStop=/bin/rm -rf /timeshift/

[Install]
WantedBy=default.target
$ sudo systemctl daemon-reload
$ sudo systemctl enable timeshift_Nova # to enable startup exec
$ sudo systemctl start timeshift_Nova

MUX in TVH

pipe:///usr/bin/ffmpeg -live_start_index -99999 -i /timeshift/hls_103_.m3u8 -c copy -f mpegts pipe:1

And choose option "Use A/V library" to "Dont use"

Link to fork at github

https://github.com/Saentist/HLS-TV-channel-delay


Replies (98)

RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by deganza 11 over 1 year ago

ok, thanks a lot!

as you said: the teletext subs where the problematic part.

with -map 0:0 -map 0:2 -map 0:3 it's working

RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by Brad T 4 months ago

Hello, I've been trying to get this to work as a service to startup when my raspberry pi boots, but so far I've had no luck.

Any tips would be appreciated:

I'm trying to run a bash script on startup as a systemd service, I'm doing this on a Raspberry Pi 4 with Raspbian Buster Lite.

I'm able to execute the bash script if I run it manually ./hls.sh and I am able to also run the service if I do sudo service tv start but the tv.service does not appear to be able to execute the bash script hls.sh on start. I did give permissions chmod 777 for both the service and the bash file as well.

Bash Script

#!/bin/bash
/usr/bin/ffmpeg -reconnect 1 -reconnect_at_eof 1 -reconnect_streamed 1 -reconnect_delay_max 2 -y -nostdin \
-hide_banner -loglevel fatal \
-i http://10.0.0.11:9981/stream/channelnumber/2 \
-vcodec copy -acodec copy -scodec copy -g 60 \
-fflags +genpts -user_agent HLS_delayer \
-metadata service_provider="TimeShift" \
-metadata service_name="TV 1" \
-f hls -hls_flags delete_segments \
-hls_time 60 \
-hls_list_size 480 \
-hls_wrap 481 \
-hls_segment_filename /home/pi/hls/1_%03d.ts /home/pi/hls/1_hls.m3u8

Service

[Unit]
Description=Timeshift TV
After=tvheadend.service
PartOf=tvheadend.service
Restart=always

[Service]
ExecStartPre=/bin/mkdir -p /home/pi/hls/
ExecStart=/home/pi/hls.sh 103 &
ExecStop=/bin/rm -rf /home/pi/hls

[Install]
WantedBy=default.target

What I get when I boot and do a systemctl status

● tv.service - Timeshift TV
Loaded: loaded (/etc/systemd/system/tv.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Mon 2020-05-18 05:36:40 BST; 45s ago
Process: 465 ExecStartPre=/bin/mkdir -p -m777 /home/pi/hls/ (code=exited, status=0/SUCCESS)
Process: 472 ExecStart=/home/pi/hls.sh 103 & (code=exited, status=1/FAILURE)
Main PID: 472 (code=exited, status=1/FAILURE)

May 18 05:36:39 tv3 systemd1: Starting Timeshift TV...
May 18 05:36:39 tv3 systemd1: Started Timeshift TV.
May 18 05:36:40 tv3 systemd1: tv.service: Main process exited, code=exited, status=1/FAILURE
May 18 05:36:40 tv3 systemd1: tv.service: Failed with result 'exit-code'.

RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by saen acro 4 months ago

ExecStart=/home/pi/hls.sh 103 &

Where this 103 come from?

RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by Dimitar Maznekov 4 months ago

saen acro wrote:

[...]
Where this 103 come from?

Number 103 is the number of the channel where we do like to have timeshift

RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by Dimitar Maznekov 4 months ago

Brad T wrote:

Hello, I've been trying to get this to work as a service to startup when my raspberry pi boots, but so far I've had no luck.

Any tips would be appreciated:

I'm trying to run a bash script on startup as a systemd service, I'm doing this on a Raspberry Pi 4 with Raspbian Buster Lite.

I'm able to execute the bash script if I run it manually ./hls.sh and I am able to also run the service if I do sudo service tv start but the tv.service does not appear to be able to execute the bash script hls.sh on start. I did give permissions chmod 777 for both the service and the bash file as well.

Bash Script

#!/bin/bash
/usr/bin/ffmpeg -reconnect 1 -reconnect_at_eof 1 -reconnect_streamed 1 -reconnect_delay_max 2 -y -nostdin \
-hide_banner -loglevel fatal \
-i http://10.0.0.11:9981/stream/channelnumber/2 \
-vcodec copy -acodec copy -scodec copy -g 60 \
-fflags +genpts -user_agent HLS_delayer \
-metadata service_provider="TimeShift" \
-metadata service_name="TV 1" \
-f hls -hls_flags delete_segments \
-hls_time 60 \
-hls_list_size 480 \
-hls_wrap 481 \
-hls_segment_filename /home/pi/hls/1_%03d.ts /home/pi/hls/1_hls.m3u8

Service

[Unit]
Description=Timeshift TV
After=tvheadend.service
PartOf=tvheadend.service
Restart=always

[Service]
ExecStartPre=/bin/mkdir -p /home/pi/hls/
ExecStart=/home/pi/hls.sh 103 &
ExecStop=/bin/rm -rf /home/pi/hls

[Install]
WantedBy=default.target

What I get when I boot and do a systemctl status

● tv.service - Timeshift TV
Loaded: loaded (/etc/systemd/system/tv.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Mon 2020-05-18 05:36:40 BST; 45s ago
Process: 465 ExecStartPre=/bin/mkdir -p -m777 /home/pi/hls/ (code=exited, status=0/SUCCESS)
Process: 472 ExecStart=/home/pi/hls.sh 103 & (code=exited, status=1/FAILURE)
Main PID: 472 (code=exited, status=1/FAILURE)

May 18 05:36:39 tv3 systemd1: Starting Timeshift TV...
May 18 05:36:39 tv3 systemd1: Started Timeshift TV.
May 18 05:36:40 tv3 systemd1: tv.service: Main process exited, code=exited, status=1/FAILURE
May 18 05:36:40 tv3 systemd1: tv.service: Failed with result 'exit-code'.

You've been made heavy change in script and due to this service script at part

ExecStart=/home/pi/hls.sh 103 & 

couldn't be started - 103 is the number of channel wich we want to record but in script there is no $1 variable (as the first parameter of script)

RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by saen acro 4 months ago

Dimitar Maznekov wrote:

saen acro wrote:

[...]
Where this 103 come from?

Number 103 is the number of the channel where we do like to have timeshift

then why

-i http://10.0.0.11:9981/stream/channelnumber/2 \

maby you forget variabes $1
-i http://10.0.0.11:9981/stream/channelnumber/$1 \

see repo
https://github.com/Saentist/HLS-TV-channel-delay

RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by Dimitar Maznekov 4 months ago

The user heavly changed script, that's what I'm talking about.

RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by saen acro 4 months ago

Dimitar Maznekov wrote:

The user heavly changed script, that's what I'm talking about.

That's whay I ask a question to Brad T where "103" come in his logic.
Seting a hardlink will not use variables.

RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by Brad T 4 months ago

Honestly, I had no idea what the 103 did in the script originally, but even when I remove it I still have the same issue. If I setup the script as intended where $1 represents the channel number, the result is the same too.

RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by saen acro 4 months ago

$1 is variable with represent 103 in this case
103 is number of channel in tvh in example.

But you can skip it by set url to channel taking it from playlist of tvh
(http://user:[email protected]:9981/playlist/auth/channels)

RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by Dimitar Maznekov 4 months ago

Saentist reminds me - @Brad T did you have anonimouse local access setup in your TVH? Couse the script assume to have it.
Could you run

/home/pi/hls.sh 103

and put the result here

RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by saen acro 4 months ago

Dimitar Maznekov wrote:

Saentist reminds me - @Brad T did you have anonimouse local access setup in your TVH? Couse the script assume to have it.
Could you run
[...]
and put the result here

little corrections

user * with pasword * and access fron 127.0.0.1 or local network ex. 192.168.0.0/24

also is location where hls chunk is written are in web server folder
ex

RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by Dimitar Maznekov 4 months ago

Yes just test it. Without anonymous user script wont work.
You should have user setup like

RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by Dimitar Maznekov 4 months ago

saen acro wrote:

also is location where hls chunk is written are in web server folder
ex

Not necessary as per +1 channel you setup hls.m3u8 file from anywhere at local machine

RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by saen acro 4 months ago

Dimitar Maznekov can you update first post to contain more concentrated information for this HOW-TO

P.S. do not delete content just add new on top with separation "new line, ---, new line"
link to github repo if you wish

RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by Brad T 4 months ago

I added an anonymous user, but the service still won't start. Everything still works manually though.

RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by saen acro 4 months ago

Brad T wrote:

I added an anonymous user, but the service still won't start. Everything still works manually though.

you not fallow steps to make it work:
1. if there's public access to TVH limit ip access to IP range for "*" user
2. make choice if you will use channel number or channel url
3. see logs or test via FFPROBE

RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by Brad T 4 months ago

Okay, I changed the range.

I am using the direct url

#!/bin/bash
/usr/bin/ffmpeg -reconnect 1 -reconnect_at_eof 1 -reconnect_streamed 1 -reconne$
-hide_banner -loglevel fatal \
-i http://10.0.0.11:9981/stream/channelnumber/2 \
-vcodec copy -acodec copy -scodec copy -g 60 \
-fflags +genpts -user_agent HLS_delayer \
-metadata service_provider="TimeShift" \
-metadata service_name="TV 1" \
-f hls -hls_flags delete_segments \
-hls_time 60 \
-hls_list_size 480 \
-hls_wrap 481 \
-hls_segment_filename /opt/hls/tmp/%03d.ts /opt/hls/tmp/hls.m3u8

The service looks like:

[Unit]
Description=Timeshift tv
After=tvheadend.service
PartOf=tvheadend.service

[Service]
ExecStartPre=/bin/mkdir -p -m777 /opt/hls/tmp
ExecStart=/opt/hls/hls.sh
ExecStoPostp=/bin/rm -rf /opt/hls/tmp

[Install]
WantedBy=default.target

When I run it manually:

[email protected]:/etc/systemd/system $ sudo systemctl status tv3 service
Unit service.service could not be found.
● tv3.service - Timeshift tv
Loaded: loaded (/etc/systemd/system/tv3.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2020-05-23 14:32:35 BST; 16s ago
Process: 781 ExecStartPre=/bin/mkdir -p -m777 /opt/hls/tmp (code=exited, status=0/SUCCESS)
Main PID: 782 (hls.sh)
Tasks: 2 (limit: 4915)
Memory: 18.2M
CGroup: /system.slice/tv3.service
├─782 /bin/bash /opt/hls/hls.sh
└─784 /usr/bin/ffmpeg -reconnect 1 -reconnect_at_eof 1 -reconnect_streamed 1 -reconnect_delay_max 2 -y -nostdin -hide_banner -loglevel fa

May 23 14:32:35 tv3 systemd1: Starting Timeshift tv...
May 23 14:32:35 tv3 systemd1: Started Timeshift tv.

This is what happens when I check the service on boot:

tv3.service - Timeshift tv
Loaded: loaded (/etc/systemd/system/tv3.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sat 2020-05-23 14:36:41 BST; 2min 18s ago
Process: 464 ExecStartPre=/bin/mkdir -p -m777 /opt/hls/tmp (code=exited, status=0/SUCCESS)
Process: 471 ExecStart=/opt/hls/hls.sh (code=exited, status=1/FAILURE)
Main PID: 471 (code=exited, status=1/FAILURE)

May 23 14:36:40 tv3 systemd1: Starting Timeshift tv...
May 23 14:36:40 tv3 systemd1: Started Timeshift tv.
May 23 14:36:41 tv3 systemd1: tv3.service: Main process exited, code=exited, status=1/FAILURE
May 23 14:36:41 tv3 systemd1: tv3.service: Failed with result 'exit-code'.

Something I noticed while watching the TVH log is that on boot I never see a connection attempt.

Are there any other logs I should provide, and if so, how do I provide them?

RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by saen acro 4 months ago

Seems as ownership problem.

RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by Dimitar Maznekov 4 months ago

@Brad T your service file should be corrected:

ExecStart=/opt/hls/hls.sh &
ExecStop =/bin/rm -rf /opt/hls/tmp

If you can start/status/stop it then enabled it at boot with
systemctl enable tv3
That's all

RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by Brad T 4 months ago

It appears the problem was that Debian / Raspbian systemd doesn't properly support After=, I solved this by doing RestartSec=5s. Everything works now.

https://unix.stackexchange.com/questions/209832/debian-systemd-network-online-target-not-working

RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by Dimitar Maznekov 4 months ago

Brad T wrote:

It appears the problem was that Debian / Raspbian systemd doesn't properly support After=, I solved this by doing RestartSec=5s. Everything works now.

https://unix.stackexchange.com/questions/209832/debian-systemd-network-online-target-not-working

I'm not so sure that was the problem: https://www.raspberrypi.org/documentation/linux/usage/systemd.md

RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by Dimitar Maznekov 4 months ago

saen acro wrote:

Dimitar Maznekov can you update first post to contain more concentrated information for this HOW-TO

P.S. do not delete content just add new on top with separation "new line, ---, new line"
link to github repo if you wish

Changed the first post Saentist ;)

(76-98/98)