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 saen acro over 6 years ago
Dear Mitko,
In near feature, when HLS is adopted in project, all this will work as you expect
For now start to play channel, set on pause, go to WC, take drink and continue to watch, nothing more.
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by Dimitar Maznekov over 6 years ago
Dear Saen that's mean "On-demand" doesn't work actually ?
Is it than in roadmap feature as Catchup channels ...
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by deganza 11 almost 6 years ago
Hi Dimitri
Did you find a solution for your catch up problem.
I would also be interested in such a solution.
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by Dimitar Maznekov almost 6 years ago
Nope, I thought there isn't way to make it. Keep wait to adopt new features in development tree...
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by deganza 11 almost 6 years ago
Do you know if there is such a feature in development?
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by saen acro almost 6 years ago
It can be done with FFMPEG delay can be set etc.
ex
TVH ch1 > ffmpeg > HLS segmenting > storage
Storage > ffmpeg tsstream > TVH ch1 +1h
delay control is harder part, second instance of ffmpeg need to be started later
maby something as this project
https://github.com/voc/hls-relive
EPG is other problem in this case
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by deganza 11 almost 6 years ago
Thanks for the hint but could you give me a concrete example?
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by saen acro almost 6 years ago
ffmpeg -i "http://127.0.0.1:9981/stream" -acodec copy -vcodec copy -f segment -segment_time 1 -segment_list_flags live -segment_list_size 60 -segment_wrap 0 -segment_list /storage/hls/catchup-1h/playlist.m3u8 -segment_format mpegts segment_%05d.ts
tuning on parameters is needed
6 segments of 10 min or
12 segments of 5 min or
60 segments of 1 min
input in tvh as iptv source
then
https://forum.videohelp.com/threads/371484-Optimizing-m3u8-streaming-with-ffmpeg
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by deganza 11 almost 6 years ago
Thank you again!
At the moment I've the following IPTV source:
file:///usr/local/tvheadend/var/tv_sender_tvh.m3u
Now where I've to put this playlist link? In this part:
-segment_list /storage/hls/catchup-1h/playlist.m3u8
or at the beginning after the ffmpeg command?
And can I overvrite the actuel iptv source or do I've to set up a new IPTV source?
Sorry for the lot of questions. I'm quite new with TVH.
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by saen acro almost 6 years ago
This is a location where ffmpeg will create and store .m3u8 index and .ts chunks
normally this is somewhere in http served folders
/if you dont want to use apache tons of settings etc use THTTPD or some of other acme http servers /
finally you can read it by
http://localhost.or.ip:port/path/playlist.m3u8
p.s.
ffmpeg clean older files out of m3u8 index file
to be more easy to be understand replace in upper command naming of chunks to
ch_name_stream_%Y%m%d%H%M%S.ts
with will set date in format
ch_name_stream_20181228122016.ts
read this
https://ffmpeg.org/ffmpeg-formats.html#hls-2
http://hlsbook.net/segmenting-video-with-ffmpeg/
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by deganza 11 almost 6 years ago
thank you again!
As I'm a completely newby, do I've to write a script for this?
Where do I've to save the script?
Are there some good tutorials or introduction books?
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by saen acro almost 6 years ago
start can be done by scheduled task, where to put commands.
Keep in mind that if by some reason process die it will not start automatically,
also will start recording on clean.
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by Dimitar Maznekov almost 6 years ago
That's could work, but it's pritty "outside" of the tvhbox. Same way could be setup VLC to save stream and to be played after. But not as MUX Channel+1, Channel2+1 or Channel+2 etc.
For me that isn't TVH style resolution.
Edit: BTW it's posible to setup M3Us like channel muxes as:
pipe:///usr/bin/ffmpeg -i <M3U8 URL HERE> -c copy -f mpegts pipe:1
Must give it a try with local created M3U8.
Thanks for the idea.
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by saen acro almost 6 years ago
There is no other FREE solution for now.
https://github.com/mediadata/hbbts
same solution via Cesbo ASTRA
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by deganza 11 almost 6 years ago
I've tried to implement the following code
ffmpeg -i "http://127.0.0.1:9981/stream" -acodec copy -vcodec copy -f segment -segment_time 1 -segment_list_flags live -segment_list_size 60 -segment_wrap 0 -segment_list /storage/hls/catchup-1h/playlist.m3u8 -segment_format mpegts segment_%05d.ts
I've tried different storage paths but I get always permission errors:
2019-01-03 16:18:10.765 spawn: [segment 0x112f720] Opening 'segment_00000.ts' for writing
0x112f720] Failed to open segment 'segment_00000.ts'
2019-01-03 16:18:10.765 spawn: [segment
2019-01-03 16:18:10.765 spawn: Could not write header for output file #0 (incorrect codec parameters ?): Permission denied
But what about redording a timer for every channel? Would it be possible to combine the recorded channel in the same epg-guide of the live-channel?
Or maybe just to combine the redorded channel with the epg guide?
In switzerland every tv-provider has catch up tv of the last 7 days. They call "catch up" as "replay tv".
And I'm wondering how they do it.
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by saen acro almost 6 years ago
Is location "/storage/hls/catchup-1h/" exist,
and is it have permission to be writable?
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by deganza 11 almost 6 years ago
I tried different locations.
for example the same location where are also my TVH recordings:
/volume1/TVH/
But I got always permission denied.
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by saen acro almost 6 years ago
create folder for example in /tmp/hls
# mkdir -p -m 0777 / /tmp/hls
and try
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by deganza 11 almost 6 years ago
same issue. I thik that it has to do with the codec parameters.
2019-01-03 18:38:51.329 spawn: [segment 0x1488d40] Opening 'segment_00000.ts' for writing
0x1488d40] Failed to open segment 'segment_00000.ts'
2019-01-03 18:38:51.329 spawn: [segment
2019-01-03 18:38:51.329 spawn: Could not write header for output file #0 (incorrect codec parameters ?): Permission denied
2019-01-03 18:38:51.329 spawn: Stream mapping:
2019-01-03 18:38:51.329 spawn: Stream #0:0 -> #0:0 (copy)
2019-01-03 18:38:51.329 spawn: Stream #0:1 -> #0:1 (copy)
2019-01-03 18:38:51.330 spawn: Last message repeated 1 times
2019-01-03 18:38:51.333 iptv: stdin pipe unexpectedly closed: No data
But what about redording a timer for every channel? Would it be possible to combine the recorded channel in the same epg-guide of the live-channel?
Or maybe just to combine the redorded channel with the epg guide?
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by saen acro almost 6 years ago
#sudo ffmpeg -reconnect 1 -reconnect_at_eof 1 -reconnect_streamed 1 -reconnect_delay_max 2 -y \ -nostdin -hide_banner \ -loglevel quiet \ -fflags +genpts \ -user_agent HLS_CH1_delayer \ -i http://192.168.1.222:9981/stream/channelid/1165510174 \ -vcodec copy -acodec copy -scodec copy \ -hls_flags delete_segments -hls_time 10 -hls_list_size 6 /tmp/1_.m3u8
if process stop remove
-loglevel quiet \
or to show some status put
-loglevel info \
On second terminal
#watch -d ls -al /tmp total 40904 drwxrwxrwt 5 root root 4096 яну 3 21:37 . drwxr-xr-x 22 root root 4096 дек 21 09:11 .. -rw-r--r-- 1 root root 5120368 яну 3 21:35 1_10.ts -rw-r--r-- 1 root root 4714476 яну 3 21:35 1_11.ts -rw-r--r-- 1 root root 3531768 яну 3 21:35 1_12.ts -rw-r--r-- 1 root root 2156172 яну 3 21:35 1_13.ts -rw-r--r-- 1 root root 2658696 яну 3 21:35 1_14.ts -rw-r--r-- 1 root root 2244344 яну 3 21:36 1_15.ts -rw-r--r-- 1 root root 2074956 яну 3 21:36 1_16.ts -rw-r--r-- 1 root root 1951628 яну 3 21:36 1_17.ts -rw-r--r-- 1 root root 2287208 яну 3 21:36 1_18.ts -rw-r--r-- 1 root root 2294728 яну 3 21:36 1_19.ts -rw-r--r-- 1 root root 2306760 яну 3 21:36 1_20.ts -rw-r--r-- 1 root root 3452432 яну 3 21:37 1_21.ts -rw-r--r-- 1 root root 1835068 яну 3 21:37 1_22.ts -rw-r--r-- 1 root root 2546084 яну 3 21:34 1_8.ts -rw-r--r-- 1 root root 2652116 яну 3 21:35 1_9.ts -rw-r--r-- 1 root root 236 яну 3 21:37 1_.m3u8
this work on my PC
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by Dimitar Maznekov almost 6 years ago
Should be:
ffmpeg -loglevel fatal -thread_queue_size 512 -i http://127.0.0.1:9981/stream/channelnumber/NUM .....
I think he is missing channelnumber/NUM where the NUM is number of desired channel.
Not bulletproof with channelnumber instead of channelid but it's way easy for me.
Ouch, that was so obviouse ....I didn't catch the mistake - missing %d in .ts file
Thats works for me
/usr/bin/ffmpeg -reconnect 1 -reconnect_at_eof 1 -reconnect_streamed 1 -reconnect_delay_max 2 -y -nostdin \ -i http://127.0.0.1:9981/stream/channelnumber/101 \ -vcodec copy -acodec copy -scodec copy \ -f segment -segment_list_type m3u8 -segment_list_flags +live -segment_wrap 60 \ -segment_list /home/lib/catch-up/101+1.m3u8 \ -segment_format mpegts /home/lib/catch-up/ch_101_stream_%d.ts
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by Dimitar Maznekov almost 6 years ago
And proper script for 60 segments x60sek:
#!/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/101 \ -vcodec copy -acodec copy -scodec copy \ -f segment -segment_list_type m3u8 -segment_time 60 -segment_list_flags +live -segment_wrap 60 \ -segment_list /home/lib/catch-up/101+1.m3u8 \ -segment_format mpegts /home/lib/catch-up/ch_101_stream_%d.ts
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by saen acro almost 6 years ago
With experimenting things go to success
instead of %d use %Y%m%d%H%M%S
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by Dimitar Maznekov almost 6 years ago
Yeah, but there was another magic with date and %Y%m%d%H%M%S which I'm too lazy to remember... so %d is acceptable for me
RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by deganza 11 almost 6 years ago
Where do I've to put this code?
- in the Networks section as new IPTV-Network?
- in the Muxer-Section?
at the moment I got the following output:
2019-01-04 07:11:10.694 spawn: ffmpeg version 3.4.1 Copyright (c) 2000-2017 the FFmpeg developers
2019-01-04 07:11:10.694 spawn: built with gcc 4.9.3 (crosstool-NG 1.20.0) 20150311 (prerelease)
2019-01-04 07:11:10.694 spawn: configuration: --target-os=linux --cross-prefix=/spksrc/toolchains/syno-x64-6.1/work/x86_64-pc-linux-gnu/bin/x86_64-pc-linux-gnu- --prefix=/var/packages/ffmpeg/target --extra-cflags=-I/spksrc/spk/ffmpeg/work-x64-6.1/install/var/packages/ffmpeg/target/include --extra-ldflags=-L/spksrc/spk/ffmpeg/work-x64-6.1/install/var/packages/ffmpeg/target/lib --extra-libs='-lxml2 -ldl' --pkg-config=/usr/bin/pkg-config --ranlib=/spksrc/toolchains/syno-x64-6.1/work/x86_64-pc-linux-gnu/bin/x86_64-pc-linux-gnu-ranlib --enable-cross-compile --enable-rpath --enable-pic --enable-shared --enable-optimizations --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-fontconfig --enable-libass --enable-libbluray --enable-avresample --enable-libfdk-aac --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvo-amrwbenc --enable-l
2019-01-04 07:11:10.694 spawn: libavutil 55. 78.100 / 55. 78.100
2019-01-04 07:11:10.694 spawn: libavcodec 57.107.100 / 57.107.100
2019-01-04 07:11:10.694 spawn: libavformat 57. 83.100 / 57. 83.100
2019-01-04 07:11:10.694 spawn: libavdevice 57. 10.100 / 57. 10.100
2019-01-04 07:11:10.694 spawn: libavfilter 6.107.100 / 6.107.100
2019-01-04 07:11:10.694 spawn: libavresample 3. 7. 0 / 3. 7. 0
2019-01-04 07:11:10.694 spawn: libswscale 4. 8.100 / 4. 8.100
2019-01-04 07:11:10.694 spawn: libswresample 2. 9.100 / 2. 9.100
2019-01-04 07:11:10.694 spawn: libpostproc 54. 7.100 / 54. 7.100
2019-01-04 07:11:10.696 spawn: Trailing options were found on the commandline.
2019-01-04 07:11:10.696 spawn: Hyper fast Audio and Video encoder
2019-01-04 07:11:10.696 spawn: usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...
2019-01-04 07:11:10.696 spawn: Use -h to get full help or, even better, run 'man ffmpeg'
2019-01-04 07:11:10.698 iptv: stdin pipe unexpectedly closed: No data