Project

General

Profile

[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

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


Replies (99)

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

Sure you can even two ways - choose desired show in EPG and setup record OR setup Autorecording by the name of the show and channel (again from EPG of event or from DVR/Autorecs)

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

I want to record the whole day of a channel. But the recordings should be separated by the informations of the shows in the epg.

for example:

record whole day of channel 1
and then automatically the following happens:

from 1:00pm-2:00pm Movie 1 -> record Movie 1
from 2:00pm-2:00pm TV Show -> record TV Show
from 3:00pm-4:00pm News -> record News
from 5:00pm-6:00pm Movie 2 -> record Movie 2

is there such a function?

Because this would be also the solution for catchup-TV for how I understand it.

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

Even without Catchup you can do that.

Idea of catchup is more simple
ex.
Russia have 9 time zones do news in 20:00 need to be 9 time "in air"
Morning news in Moscow are in launch time in Kamchatka.

RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by Thom Asv over 5 years ago

great feature, Is it possible to run this way at the same time for example 5 channels?

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

THE VALLEY wrote:

great feature, Is it possible to run this way at the same time for example 5 channels?

There is no limit.

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

If the provider permits as many connection at the same time.

RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by Thom Asv over 5 years ago

yop, that was the problem. I can stream at the same time max 3 streams. But its working now. Just one question. If I want to add there water mar /text or transparent picture/ +1 in the bottom right corner. Is it possible?
Something like you can se here

ffmpeg -i birds.mp4 -i watermark.png \
-filter_complex "overlay=x=(main_w-overlay_w)/2:y=(main_h-overlay_h)/2" birds2.mp4

http://ksloan.net/watermarking-videos-from-the-command-line-using-ffmpeg-filters/

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

Yes you can, this is simple ffmpeg nothing more
of course share command later ;)
Keep in mind this is equal to transcoding
/get involved in the mess some GPU to do that ;) /

using transparent PNG image

ffmpeg -i pipe:0 -i logo.png \
-filter_complex "[1:v][0:v]scale2ref=iw*0.05:-1[logo1][base]; \
 [base][logo1]overlay=0:0[v]" \
-map [v] -map 0:a -y -b:v 1600k -c:v libx264 -profile high -level 4.1 \
-c:a libfaac -b:a 128k pipe:1

RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by Thom Asv over 5 years ago

this is code I am using

#!/bin/bash
/home/media/ffmpeg -reconnect 1 -reconnect_at_eof 1 -reconnect_streamed 1 -reconnect_delay_max 2 -y -nostdin \
-hide_banner -loglevel fatal \
-i SOURCE.M3U8 \
-vcodec copy -acodec copy -scodec copy -g 60 \
-fflags +genpts -user_agent HLS_delayer -metadata service_provider="TimeShift" -metadata service_name="CHANNEL +1" \
-f hls -hls_flags delete_segments -hls_time 10 -hls_list_size 360 -hls_wrap 361 \
-hls_segment_filename /home/viewdns/timeshift/playlist_segments/CHANNEL+1/_%03d.ts /home/viewdns/timeshift/playlist_segments/CHANNEL+1/playlist.m3u8

Where to insert the lines?

RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by Thom Asv over 5 years ago

Hey guys,

I wanted to ask. What is the best config for pipe and bash script?
After watching about 5-7 minutes stream freeze. I am using this pipe syntax

pipe:///usr/bin/ffmpeg -live_start_index -99999 -i /home/lib/catch-up/hls_407_.m3u8 -c copy -f mpegts pipe:1


-live_start_index -99999 is this the only way how to "shift" back in broadcasting?

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

Did you

And choose option "Use A/V library" to "Don't use" 

I didn't have any freezes or interruption with that pipe.
And yes, the only way to start from the beginning of playlist is to set start index at -99999. That means actually to the oldest chunk. If you want another offset could use -XX ( number of chunk multiplied by XX )

RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by Thom Asv over 5 years ago

yes I option A/V library is se to "Don't use"

what is your pipe syntax?

And one more question. I was asking earlier about putting transparent logo in this shifted channels.
I have png icon logo.png in /home/pics/logo.png
If I want to identify the channel as +1 I would like to have there the icon. The right place to put it is tvheadend pipe or this in bash script which creates the playlist.m3u8? I am kinda stucked and don't know how to continue

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

Overlaying with logo will transcode stream

remove from command line

-vcodec copy -acodec copy

and put on it's place
-i logo.png \
-filter_complex "[1:v][0:v]scale2ref=iw*0.05:-1[logo1][base]; \
 [base][logo1]overlay=0:0[v]" \
-map [v] -map 0:a -y -b:v 1600k -c:v libx264 -profile high -level 4.1 \
-c:a libfaac -b:a 128k

RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by Thom Asv over 5 years ago

thx for hints. Is there way how to check and restart script if it crash or stops working?

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

test as live output without storage part play it on VLC for example.

replace on finish output

-f mpegts udp://236.0.0.1:2000

there is lot of service monitoring softwares, monit for example

RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by Thom Asv over 5 years ago

is there an optimal config. I mean how many chunks?

I had 360 chunks for 10 sec now I have 60 chunks for 60 sec. Or this doesn't matter actually

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

When have more channels chunk size meter on I/O performance of storage controller and web server.
Size 2-10mb is best in my experience, smaller make hdd hard to processing read/write,
bigger make web server to use very big network consumption.

So need to make calculation based on bitrate of channels.
But for one channel no big difference but for one hour back if part are 10 min long not mean one hour back it can be 50 min back.

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

saen acro wrote:

Overlaying with logo will transcode stream

remove from command line
[...]
and put on it's place
[...]

Hm, that's remind me another hack I've made - to broadcast with TVH two channels with PiP and both audio interchangeable within Kodi with key.
Should I share it here ?

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

This is MOSAIC scenario ;)
lets open new topic for this will share there my mosaic soft collection :P

RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by Thom Asv over 5 years ago

Do you have idea what could help me with looping channel?

I am using above posted script to create +1 hour channel. It works good. So far tested and works best with FFmpeg 3.3
In tvheadend I am using pipe

pipe:///home/ffmpeg-3.3/ffmpeg -loglevel fatal -live_start_index -359 -i http://localhost/playlist.m3u8 -i http://localhost/picon+1.png -qscale:v 1 -filter_complex "overlay=main_w-overlay_w-10:10" -f mpegts pipe:1

Unfortunately it ends with looping the channel. In tvh log I am getting this message

2019-03-21 15:57:48.471 tsfix: transport stream MPEG2AUDIO, DTS discontinuity. DTS = 62098, last = 1800898
....

RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by Thom Asv over 5 years ago

Thank you all for help.

I tried almost everything with the pipe syntax but the problem was still there. I tried to insert text so I knew its time shifted channel. There was no looping. I would like to share you with the pipe that did the trick for me

pipe:///home/ffmpeg-3.3/ffmpeg -loglevel fatal -live_start_index -358 -i http://localhost/playlist.m3u8 -qscale:v 8 -vf "drawtext=fontfile=/path/to/the/font/picont.ttf:font=picon: text='1': fontsize=58: fontcolor=b4bab2: x=w-tw-30:y=95" -f mpegts pipe:1

This is really hobby for me so I have created logo as font. Looks great and it is identical. Maybe somebody could use this.

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

with some channels the cachtup-script is working like a charm but when I'm using rtp-signals I got always the following error message:

[h264 0x556e39154140] non-existing SPS 0 referenced in buffering period
[h264
0x556e39154140] SPS unavailable in decode_picture_timing
[h264 0x556e39154140] non-existing PPS 0 referenced
[h264
0x556e39154140] non-existing SPS 0 referenced in buffering period
[h264 0x556e39154140] SPS unavailable in decode_picture_timing
[h264
0x556e39154140] non-existing PPS 0 referenced
[h264 0x556e39154140] decode_slice_header error
[h264
0x556e39154140] no frame!

I'm using the following which is working mostly on livestreams but not on channels with a rtp address.

#!/bin/bash
/usr/bin/ffmpeg -reconnect 1 -reconnect_at_eof 1 -reconnect_streamed 1 -reconnect_delay_max 2 -y -nostdin \
-i http://server:9981/stream/channelnumber/26 \
-vcodec copy -acodec copy -scodec copy \
-fflags +genpts -user_agent HLS_delayer \
-f hls -hls_flags delete_segments \
-hls_time 5 \
-hls_list_size 6 \
-hls_wrap 7 \
-hls_segment_filename /media/sdb1/timeshift/ARD/ard_%03d.ts /media/sdb1/timeshift/ARD/ard_hls.m3u8

here is the output for the original signal

Duration: N/A, start: 15725.842289, bitrate: N/A
Program 1
Metadata:
service_name : ORF1 HD
service_provider:
Stream #0:0[0x65]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(tv, bt709, progressive), 1280x720 [SAR 1:1 DAR 16:9], 50 fps, 50 tbr, 90k tbn, 100 tbc
Stream #0:1[0x115](deu,deu): Subtitle: dvb_teletext ([6][0][0][0] / 0x0006), 492x250
Stream #0:2[0x12d](deu): Audio: ac3 ([6][0][0][0] / 0x0006), 48000 Hz, 5.1(side), fltp, 448 kb/s (clean effects)
Stream #0:3[0x12e](aub): Audio: aac (HE-AAC) ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 95 kb/s

RE: [HowTo] Catchup IPTV a.k.a +1 hour TV (in work) ? - Added by Thom Asv over 5 years ago

I had similar problem with some channels. try to map the specific stream you want. e.g
-map 0:0 -map 0:2

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

Try to remove teletext/teletext subs this is problematic part.

(51-75/99)