Forums » Tutorial and setups »
[HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ?
Added by Dimitar Maznekov over 6 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¶
Replies (99)
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by Dimitar Maznekov almost 6 years ago
That ffmpeg things are put in .sh script which you must run in autostartup manner.
I thought there was pre- and post-mux way to start it but not so sure....
BTW you miss something cause you dont have input data stream.
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by Dimitar Maznekov almost 6 years ago
saen acro wrote:
With experimenting things go to success
instead of %d use %Y%m%d%H%M%S
Some clarifications:
To use indexing like %Y%m%d%H%M%S you must have option in ffmpeg line -strftime 1
BUT in meaning of goal is UNACCEPTABLE because created .ts chunks are NOT overwriten from newer chunks so you will become very quickly out-of-space.
So it's fine to use %03d and newer files will overwrite older.
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by saen acro almost 6 years ago
FFMpeg self-clean chunks out of playlist file
#!/bin/bash.
#Put your storage location
STORAGE=/tmp/catchup-tv
rm -rf $STORAGE *.ts
/usr/bin/ffmpeg -reconnect 1 -reconnect_at_eof 1 -reconnect_streamed 1 -reconnect_delay_max 2 -y -nostdin \
-hide_banner -loglevel fatal \
-user_agent CatchUP-delayer_1h_channel-X # show client in TVH
-i http://127.0.0.1:9981/stream/channelnumber/101 \ #channel url
-vcodec copy -acodec copy -scodec copy \
-f segment -segment_list_type m3u8 -segment_time 60 -segment_list_flags +live -segment_wrap 60 \
-hls_flags delete_segments \
-segment_list $STORAGE/101+1.m3u8 \
-segment_format mpegts $STORAGE/ch_101_stream_%d.ts
need more set for variables
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by Dimitar Maznekov almost 6 years ago
Ummm, not actualy:
#!/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 \ -user_agent CatchUP_1h_channel-$1 \ -f segment -segment_list_type m3u8 -segment_list_flags +live \ -segment_time 60 -segment_wrap 60 \ -segment_list /home/lib/catch-up/$1+1.m3u8 \ -segment_format mpegts /home/lib/catch-up/ch_$1_%d.ts
That's overwrite older .ts chunks. Tested with 60x1s, now I'm testing with 60x60(1h)
And add according service file
/etc/systemd/system/timeshift_Nova.service [Unit] Description=Timeshift Nova TV After=tvheadend.service [Service] #Type = forking ExecStart=/home/lib/catch-up/timeshift_ts.sh 103 & [Install] WantedBy=default.target
$ sudo systemctl daemon-reload
$ sudo systemctl enable timeshift_Nova.service # to enable startup exec
$ sudo systemctl start timeshift_Nova.service
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by saen acro almost 6 years ago
Lets put this as new project in GITHUB
it shod
-hls_flags delete_segments
https://ffmpeg.org/ffmpeg-formats.html#Options-5
hls_delete_threshold size
Set the number of unreferenced segments to keep on disk before hls_flags delete_segments deletes them. Increase this to allow continue clients to download segments which were recently referenced in the playlist. Default value is 1, meaning segments older than hls_list_size+1 will be deleted.
hls_ts_options options_list
Set output format options using a :-separated list of key=value parameters. Values containing : special characters must be escaped.
hls_wrap wrap
This is a deprecated option, you can use hls_list_size and hls_flags delete_segments instead it
This option is useful to avoid to fill the disk with many segment files, and limits the maximum number of segment files written to disk to wrap.
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by Dimitar Maznekov almost 6 years ago
HLS chunks will test later today ;)
Oh you meant it should delete old chunks.... nope, that's separate options in FFMPEG "-f segment" instead of HLS. Anyway will test that way (which is new for me but looks more easier)
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by Dimitar Maznekov almost 6 years ago
So dear fellows, thanks to the ideas and help of Sean Sean acro can say - HLS chunks, even the same stream format (MPETS) are much easier and better than segments in FFMPEG. Litle cons are missing direct way to setup file name templates. They're derivatives of playlist name but anyway that's not so important. Just the name of playlist put in mux.
Here you are:
#!/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 \ -fflags +genpts -user_agent HLS_delayer \ -hls_flags delete_segments -hls_time 10 -hls_list_size 360 /home/lib/catch-up/hls_$1_.m3u8
Pros - little faster, little smaller files (IDK why?) much easier to setup.
Recommend to set hsl_time to shorter time intervals. That way will be faster to start mux a.k.a play channel. So here is 360 chunks by 10sek = 1h
Could be more fine tunning pleas feel free to adjust.
The script and the service file could be made the same way as https://tvheadend.org/projects/tvheadend/activity?from=2019-01-04
Now I'm testing full lenght 1h timeshift and after that will update Topic with that workaround.
Thanks again to anyone who helped with ideas, know how and whit push
PS:Just put it here MUX format but need testing
pipe:///usr/bin/ffmpeg -live_start_index -99999 -i /home/lib/catch-up/hls_407_.m3u8 -c copy -f mpegts pipe:1
And choose option "Use A/V library" to "Dont use"
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by saen acro almost 6 years ago
Missing is
pipe:///usr/bin/ffmpeg \
-live_start_index -99999 \
-i /home/lib/catch-up/hls_407_.m3u8 \
-c copy \
-f mpegts \
-metadata service_provider="Some provider" \
-metadata service_name="Channel +1" \
-loglevel fatal \
pipe:1
this will solve Service01 name and provider for tag and spam in log
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by Dimitar Maznekov almost 6 years ago
Nice, what can I do w/o cheks from you
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by saen acro almost 6 years ago
There maby more optimisations with can be done.
Any responses are welcome.
Dimitar Maznekov wrote:
Nice, what can I do w/o cheks from you
Ще пиеме по едно безалкохолно
In translation:
Will drink one soft drink.
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by Dimitar Maznekov almost 6 years ago
Soft drink...you meant beer ?
Just tell me when n where
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by saen acro almost 6 years ago
Dimitar Maznekov wrote:
Soft drink...you meant beer ?
Just tell me when n where
As was modern before 20y ago "You've Got Mail"
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by Dimitar Maznekov almost 6 years ago
Little update to prevent disk space leaking
#!/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" -metadata service_name="NovaTV +1" \ -f hls -hls_flags delete_segments -hls_time 10 -hls_list_size 360 -hls_wrap 361 \ -hls_segment_filename /disk2/timeshift/$1_%03d.ts /disk2/timeshift/$1_hls.m3u8
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by saen acro almost 6 years ago
Dimitar Maznekov wrote:
Little update to prevent disk space leaking
[...]
Just to explain to more beginners, that value $1
is used this way
./hls_catchup_stream.sh [channel number]
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by saen acro almost 6 years ago
If any one have suggestions
https://github.com/Saentist/HLS-TV-channel-delay
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by deganza 11 over 5 years ago
after learning some basics about linux and ffmpeg I was able to implement this script.
But now I've another problem: how do I combine that whith the epg?
The script produces the .ts segments and then I read the $1_hls.m3u8 url as new iptv-network.
When I combine this new network with the epg I'm able to view the channel from the hls.m3u8 but
I'm not able to rewind back to the previous shows.
This is the code that I'm using and in the image in the attachement channel number 4 is my catch up channel.
#!/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" \
-metadata service_name="TeleZuri" \
-f hls -hls_flags delete_segments \
-hls_time 10 \
-hls_list_size 360 \
-hls_wrap 361 \
-hls_segment_filename /home/hts/timeshift/$1_%03d.ts /home/hts/timeshift/$1_hls.m3u8
Catchup_1.jpg (101 KB) Catchup_1.jpg |
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by saen acro over 5 years ago
metadata service_name="TeleZuri +1"
dvb inputs > netwotk add ofset
channels/epg > channels "Reuse EPG from"
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by Dimitar Maznekov over 5 years ago
Just to add few more tips and tricks about Timeshift service according restart TimeShift service when resart TVHeadend service:
[Unit]
Description=Timeshift Nova TV
After=tvheadend.service
PartOf=tvheadend.service
Restart=always
[Service]
ExecStartPre=/bin/mkdir -p /disk2/timeshift/
ExecStart=/home/lib/catch-up/timeshift_hls.sh 103 &
ExecStop=/bin/rm -rf /disk2/timeshift
[Install]
WantedBy=default.target
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by deganza 11 over 5 years ago
ok I did the following:
- I changed the following in the hls script: metadata service_name="TeleZuri +1".
- channels "Reuse EPG from"
I don't know how to add the offset.
When I load the catchup channel, do I've to merge the two channels when I map the service?
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by saen acro over 5 years ago
merging is not good idea.
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by deganza 11 over 5 years ago
I did it not merge but it's not working anyway.
I've the saved ts-files from the hls-script but it does not rewind...
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by saen acro over 5 years ago
This is not timeshift, cannot be used to move back forward time is fixed.
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by deganza 11 over 5 years ago
But how do I play a show from 1 hour ago?
I've the channel Nr 1004 which is used in the hls script and the channel Nr 4 which is the catchup channel.
Now when I'm in Kodi for example how do I recall older shows? (I'm using the TVH-Plugin who works very well)
The files are saved in the Timeshift directory but how to combine them with the epg?
Should I change the storage path in Timeshift and use the one in the hls-script?
Catchup_1.jpg (145 KB) Catchup_1.jpg |
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by Dimitar Maznekov over 5 years ago
Just use (already mapped) 1004 channel as usual channel. You will watch a hour ago your channel 4. Can pause/play and that's all.
If you setup your MUX in new network for exmpl TimeShift, in setup of that network you could set -1h. If you in CET zone UTC will be -1 so a hour ago you have to setup as UTC-2. And re-use in setup channel 1004 EPG data for 4 channel.
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by deganza 11 over 5 years ago
ok, maybe it's not the same understanding that I had about catch up tv.
What about to use the Autorec function in TVH?
Is there a way to record every show of a channel for the last day?
I mean not to record just the whole day but one sho at the time from the epg?