Project

General

Profile

IPTV - buffering, stalls, general drop outs. Settings that resolved things for me.

Added by J Smith about 7 years ago

Figured I'd share this, as I struggled for a long time with IPTV feeds - they would frequently stall, drop out, replay previous 10 seconds or so, etc.

When using the pipe:// method with FFMpeg, everything played flawlessly, making me suspect a setting or two somewhere causing problems when using the 'IPTV Automatic' network and importing an M3U with regular HTTP streams - I'd rather not have edited a number of URLs manually to include pipe:// FFmpeg etc! So I started to twiddle some knobs to try and find a solution....

As a few people seemed to also note, when playing the IPtv feeds with VLC directly they would play flawlessly, adding some weight to the IPTV stream not being at fault. Running 2 instances of TVheadend, they would drop out at completely different times, again adding weight to the IPTV stream itself not being at fault.

I'm running the latest 4.3 unstable release at the time of writing, with OSMC frontends running on Raspi3 (with MPEG2 licenses) Key settings for me, are/were as follows, I can't advise the fall-out of changing these settings, but they seem to have more or less completely resolved my issues with IPtv stalling on TVHeadend, whilst I still see some 'service instance is bad, reason: No input detected' in the logs, the feed reconnects and streams without stalling and without skipping back 10 seconds or so and replaying:

- Configuration
- Stream
- Stream Profiles
- Pass
- Timeout 0 (may need to experiment with between 5-10 second)
- Restart on error, Enabled
- Rewrite Service ID, set to 0
- Disable ALL rewrite options (PMT, PAT, SDT, EIT), these settings had the biggest impact for me.
- Save

- Configuration
- Stream
- Stream Profiles
- HTSP
- Timeout 0 (may need to experiment with between 5-10 second)
- Restart on error, Enabled)
- Save

- Configuration
- General
- Base
- Packet Backlog, enabled
- Save


Replies (71)

RE: IPTV - buffering, stalls, general drop outs. Settings that resolved things for me. - Added by Rap Tor about 7 years ago

thanks for these. I'll try them out.

Have you had an issue where the stream aspect ratio is confused in certain players for certain programs? Unfortunately it is not recurring, e.g. the same channel will show the correct aspect ratio (typical widesreen), an hour later, the same channel and the same player will show up as ultra-wide (so squashed). Can't seem to solve it.

RE: IPTV - buffering, stalls, general drop outs. Settings that resolved things for me. - Added by J Smith about 7 years ago

I can't say I've seen that myself, I would have thought thats more the frontend part that makes that decision?

I stumbled across another post that gave me another idea - download the M3U, process it to include the pipe:/// ffmpeg aspects, then import into tvheadend. Something like:

  1. Download m3u file
    wget "http:/iptv.com/username/xxxxxxxx"
  1. Use perl to process, replace http with the full ffmpeg pipe http
    perl -pi -e 's/^http\:\/\//pipe\:\/\/\/usr\/bin\/ffmpeg\ \-loglevel\ fatal\ \-re\ -\i\ http\:\/\//g' <downloaded m3u file>
  1. Find the .ts part of the address, add on tail of ffmpeg command
    perl -pi -e 's/\.ts/\.ts\ \-c\ copy\ \-f\ mpegts\ \-tune\ zerolatency\ pipe\:1/g' <downloaded m3u file>

Then, add a new IPTV Automatic Mux, specify file:///path/to/processed/m3u-file for the URL, disable Use A/V Library if on 4.3, make sure to remember to set a stream limit otherwise you will spawn a shed load of ffmpeg processes!

EDITED: only match http at the beginning of the line, to leave logos alone

RE: IPTV - buffering, stalls, general drop outs. Settings that resolved things for me. - Added by J Smith about 7 years ago

Whilst the first post certainly cut down my stalls, I still had a couple but no where near as frequent, the latter method to re-write the m3u to include the ffmpeg pipe seems to be the way to go - mashed the above into a simple script, loaded into cron, problem solved for me.

RE: IPTV - buffering, stalls, general drop outs. Settings that resolved things for me. - Added by Rap Tor about 7 years ago

Can I ask a question about the A/V Library setting? Does this make tvheadend pipe ffmpeg on its own before reading the streams? It was on by default with result that I had a list of streams in an m3u and it found no services. As soon as I switched it off, it found all the channels.

Should this in general be on or off? For example I had another m3u file with channels, and it found the channels both with A/V Library on and off.

I'm on 4.3-596

RE: IPTV - buffering, stalls, general drop outs. Settings that resolved things for me. - Added by J Smith about 7 years ago

My understanding is that 'Use A/V Library' enabled, TVH will try to convert the various streams to the format that it likes using libav - which was forked from FFMpeg if I recall - but you can do it with ffmpeg instead by using the pipe option, but it spawns a separate ffmpeg process to do so.

In my testing, when you pipe to ffmpeg the option needs to be disabled to get anything to work, I don't know if that's how its intended but lacks checks in place to warn the user, or a bug. Either way, it would seem redundant to have 2 things likely doing the same job.

With some feeds likely using mpeg2, others using x264, I suspect those that worked were already in mpeg2 format - those that didnt were in x264 and thus required converting before TVH could use them. I might be wrong, but I suspect it's something like that.

RE: IPTV - buffering, stalls, general drop outs. Settings that resolved things for me. - Added by J Smith about 7 years ago

Script on the below bug report seems like a pretty good option as well:

https://tvheadend.org/issues/3885

Could use something similar to the below to rewrite a downloaded m3u with perl, to include the above script as a pipe instead ffmpeg directly:

perl -pi -e 's/^http\:\/\//pipe\:\/\/\/home\/hts\/scripts\/continuous\-ffmpeg\.sh\ http\:\/\//g' <downloaded m3u file>

With the script in the bug report in /home/hts/scripts/continuous-ffmpeg.sh

RE: IPTV - buffering, stalls, general drop outs. Settings that resolved things for me. - Added by Rap Tor about 7 years ago

I've been trying to set this up but the url's are not working

is there some way to debug this? or do you see soemthing wrong here?

my url

pipe:///usr/bin/ffmpeg -loglevel fatal -i http://redacted/redacted/redacted/redacted/redacted.ts -vcodec copy -acodec copy -metadata service_provider=Russia -metadata service_name=Moscow -f mpegts -tune zerolatency pipe:1

RE: IPTV - buffering, stalls, general drop outs. Settings that resolved things for me. - Added by Rap Tor about 7 years ago

here is the debug

2017-11-03 10:09:45.801 [ INFO]:mpegts: pipe:///usr/bin/ffmpeg -loglevel fatal -i http://redacted/32.ts -vcodec copy -acodec copy -metadata service_provider=Russia -metadata service_name=Moscow -f mpegts -tune zerolatency pipe:1 - tuning on IPTV
2017-11-03 10:09:45.802 [ INFO]:subscription: 0004: "scan" subscribing to mux "pipe:///usr/bin/ffmpeg -loglevel fatal -i http://redacted/32.ts -vcodec copy -acodec copy -metadata service_provider=Russia -metadata service_name=Moscow -f mpegts -tune zerolatency pipe:1", weight: 6, adapter: "IPTV", network: "ffmpeg trial", service: "Raw PID Subscription"
2017-11-03 10:09:45.803 [ INFO]:spawn: Executing "/usr/bin/ffmpeg"
2017-11-03 10:09:47.477 [ ERROR]:iptv: stdin pipe unexpectedly closed: No data
2017-11-03 10:10:00.801 [ INFO]:mpegts: pipe:///usr/bin/ffmpeg -loglevel fatal -i http://redacted/32.ts -vcodec copy -acodec copy -metadata service_provider=Russia -metadata service_name=Moscow -f mpegts -tune zerolatency pipe:1 - scan no data, failed
2017-11-03 10:10:00.801 [ INFO]:subscription: 0004: "scan" unsubscribing

RE: IPTV - buffering, stalls, general drop outs. Settings that resolved things for me. - Added by J Smith about 7 years ago

Can you run the ffmpeg command successfully on the cli?

If so, suspect 'Use A/V Library' is enabled either on the network, and/or the mux. Or, are you running OpenElec?

"Note: FFmpeg flag '-tune zerolatency' depends on the x264 encoder (libx264), remove the flag if x264 encoder isn't available on your system (e.g. OpenELEC)."

https://www.tvheadend.org/projects/tvheadend/wiki/Custom_MPEG-TS_Input

RE: IPTV - buffering, stalls, general drop outs. Settings that resolved things for me. - Added by Rap Tor about 7 years ago

Can you run the ffmpeg command successfully on the cli?

yes

output:

/usr/bin/ffmpeg
ffmpeg version 2.8.11-0ubuntu0.16.04.1 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 20160609
  configuration: --prefix=/usr --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --cc=cc --cxx=g++ --enable-gpl --enable-shared --disable-stripping --disable-decoder=libopenjpeg --disable-decoder=libschroedinger --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzvbi --enable-openal --enable-opengl --enable-x11grab --enable-libdc1394 --enable-libiec61883 --enable-libzmq --enable-frei0r --enable-libx264 --enable-libopencv
  WARNING: library configuration mismatch
  avcodec     configuration: --prefix=/usr --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --cc=cc --cxx=g++ --enable-gpl --enable-shared --disable-stripping --disable-decoder=libopenjpeg --disable-decoder=libschroedinger --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzvbi --enable-openal --enable-opengl --enable-x11grab --enable-libdc1394 --enable-libiec61883 --enable-libzmq --enable-frei0r --enable-libx264 --enable-libopencv --enable-version3 --disable-doc --disable-programs --disable-avdevice --disable-avfilter --disable-avformat --disable-avresample --disable-postproc --disable-swscale --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libvo_aacenc --enable-libvo_amrwbenc
  libavutil      54. 31.100 / 54. 31.100
  libavcodec     56. 60.100 / 56. 60.100
  libavformat    56. 40.101 / 56. 40.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 40.101 /  5. 40.101
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  2.101 /  1.  2.101
  libpostproc    53.  3.100 / 53.  3.100
Hyper fast Audio and Video encoder

'Use A/V Library' is off (I learnt my lesson)

this is running on a Linux Mint 18.2 with kernel 4.8.0-58 and it has libx264

RE: IPTV - buffering, stalls, general drop outs. Settings that resolved things for me. - Added by J B over 6 years ago

Is there anyway to keep subtitles when passing the stream to ffmpeg?

RE: IPTV - buffering, stalls, general drop outs. Settings that resolved things for me. - Added by Robert Cameron over 6 years ago

Sure. If you're only interested in the first subtitle stream, adding -c:s copy will simply copy the first subtitle stream into the output. In fact, if you are just copying the streams and only care about the first/default stream of each type (video/audio/subtitle), you can replace the -vcodec copy -acodec copy options to -c copy, which uses copy for all codec types. If you want to include all audio and subtitle streams, not just the first/default streams, then additionally use the -map 0 option, which will include all streams present in the source in the output. (Also note, the -tune zerolatency option is useless when copying codecs or if you aren't using libx264 as your video codec, as the -tune options are for passing additional options to the x264 encoder.)

Essentially, your pipe:// command ought to look something like:

pipe:///usr/bin/ffmpeg -loglevel fatal [-re] -i "${URL}" -map 0 -c copy -f mpegts pipe:1

Just replace ${URL} with your input stream. If your input stream is not a live stream (meaning its a video file stored somewhere), add -re before the -i option so that ffmpeg will output the stream as a livestream; otherwise leave it out.

RE: IPTV - buffering, stalls, general drop outs. Settings that resolved things for me. - Added by J B over 6 years ago

Awesome, thanks. Hope to see this bug fixed one of these days.

RE: IPTV - buffering, stalls, general drop outs. Settings that resolved things for me. - Added by Dean Steele over 6 years ago

J Smith wrote:

Script on the below bug report seems like a pretty good option as well:

https://tvheadend.org/issues/3885

Could use something similar to the below to rewrite a downloaded m3u with perl, to include the above script as a pipe instead ffmpeg directly:

perl -pi -e 's/^http\:\/\//pipe\:\/\/\/home\/hts\/scripts\/continuous\-ffmpeg\.sh\ http\:\/\//g' <downloaded m3u file>

With the script in the bug report in /home/hts/scripts/continuous-ffmpeg.sh

I know this was an age ago, but I managed to get this up and running (once my steep learning curve of scripting leveled off) - so massive thanks!

I seem to be getting a huge amount of ffmpeg respawns in my "log window" (at the bottom of the web interface) with slightly less kills. Any ideas what could be up?

UPDATE: I think I've worked it out - I think it was due to the "clone entry on error" in the recording profile, or the "restart on error" option in stream ("pass") profile - switching both off seems to have stopped the respawns.

RE: IPTV - buffering, stalls, general drop outs. Settings that resolved things for me. - Added by Tom Johnson about 6 years ago

J Smith wrote:

Script on the below bug report seems like a pretty good option as well:

https://tvheadend.org/issues/3885

Could use something similar to the below to rewrite a downloaded m3u with perl, to include the above script as a pipe instead ffmpeg directly:

perl -pi -e 's/^http\:\/\//pipe\:\/\/\/home\/hts\/scripts\/continuous\-ffmpeg\.sh\ http\:\/\//g' <downloaded m3u file>

With the script in the bug report in /home/hts/scripts/continuous-ffmpeg.sh

I too just found this and it worked for me. I literally was about to give up on tvheadend (after literally weeks of getting it configured where I wanted it), and now, it's perfect.

Thank you for this excellent posting.

RE: IPTV - buffering, stalls, general drop outs. Settings that resolved things for me. - Added by Johan Albrektsson about 6 years ago

As stated by some here this was ages ago that J Smith found this and informed us.

I have been running TVHeadend for a little over a year and it might be the most useful piece of software I have ever had the luxury to run privately, donations, donations :)...But it was always "almost" perfect. Up until today. I have been trying out alot of approaches regarding intermittent stalls in IPTV streams, strange pixelation, lags, freeze etc. But just adding the pipe ffmpeg they all go away. Running TVH on Debian VM and have tried ALOT of things: New Linux dist, higher performance (even though processes dont seem to need alot of RAM/CPU), all tweaks and settings, VPN, separate streams so that only one streamm on each network, Milhouses alpha of Kodi, with/without timeshift etc etc. All fruitless.

...until i decided to try this pipe and ffmpeg and modifying the m3u. Created a new network for this m3u, scanned muxes and updated services merging all with the same name so no hassle with channel numering, EPGs etc.

Been running 2 continuously streams without any freezes or lags for 6 hours now. Been zapping the channel list from time and again and not....one....glitch. OK, i have 2 or three transport stream DTS discontinuity in the log but nothing that have freezed the stream with the client connected and downloading 0 kbps that normally would happen intermittently.

Trying to figure out why this pipe command isnt standard on IPTV automatic Network when enabling A/V. Anyone knows?

Thank you all contributing here!!

RE: IPTV - buffering, stalls, general drop outs. Settings that resolved things for me. - Added by Cooper Dev almost 6 years ago

Hello all,

I did the same thing as you with the pipe and ffmpeg but I have to admit the quality of the stream is way better but the zapping time is much more longer than before. Almost 5 secondes to load a channel.
Do you have the same as me ? Anyway to improve it ?

Raspbian on a raspberry pi 3B+, kodi and tvheadend on last version.

Thanks

RE: IPTV - buffering, stalls, general drop outs. Settings that resolved things for me. - Added by Johan Albrektsson almost 6 years ago

I have the same lag in zapping and channel changes. Haven't nailed down why yet so any tip for a faster zapping would be appreciated.

Must be some ffmpeg-thing that is causing this....

RE: IPTV - buffering, stalls, general drop outs. Settings that resolved things for me. - Added by T Pedersen almost 6 years ago

Hi,

Finally it works perfect, but not with subtitles.

Tried to add subtitle stream aswell (-scodec copy) but then the streams acts as before, alot of lag, pixelations etc..
seems that this script by purpose exclude to copy the subtitle stream from sources.

Btw..
Thanks a bunch!

RE: IPTV - buffering, stalls, general drop outs. Settings that resolved things for me. - Added by Johan Albrektsson almost 6 years ago

Subtitles work for me (if there are any in the stream). How is your pipe in the .m3u/Mux? it should read something like this:

pipe:///usr/bin/ffmpeg -loglevel fatal -re -i http://ServiceproviderURL/channel.ts -map 0 -c copy -f mpegts -tune zerolatency pipe:1

RE: IPTV - buffering, stalls, general drop outs. Settings that resolved things for me. - Added by T Pedersen almost 6 years ago

This is how I embedded it in a scripts. actually works now, after i changed it to dvdsub decoder. :-)

/usr/bin/ffmpeg -loglevel fatal -fflags +igndts -re -i "$1" -acodec copy -vcodec copy -scodec dvbsub -metadata service_provider="$2" -metadata service_name="$2" -f mpegts pipe:1

running it on a rp2 with raspbien stretch, so thinks its not powerful enough for the -map 0 -c copy setting.

RE: IPTV - buffering, stalls, general drop outs. Settings that resolved things for me. - Added by T Pedersen almost 6 years ago

just a small update..

Think this workaround is not longer needed as the stable release works as a charm for me now. No stalls anymore.

The only difference is that with the ffmpeg fork does provide better stream picture quality. The downsides with the fork are sadly greater.. swap times are to long. maybe swap times are lower on rp3, but i only have rp2. oc the mmc and cpu. gpu_mem:16M

RE: IPTV - buffering, stalls, general drop outs. Settings that resolved things for me. - Added by Johan Albrektsson almost 6 years ago

Tom-Frode Pedersen wrote:

just a small update..

Think this workaround is not longer needed as the stable release works as a charm for me now. No stalls anymore.

The only difference is that with the ffmpeg fork does provide better stream picture quality. The downsides with the fork are sadly greater.. swap times are to long. maybe swap times are lower on rp3, but i only have rp2. oc the mmc and cpu. gpu_mem:16M

I think the swap time is on the server side. I run TVH on a VM Debian, not on RPi,

What version are you running of TVH?

RE: IPTV - buffering, stalls, general drop outs. Settings that resolved things for me. - Added by T Pedersen almost 6 years ago

I`m running 4.2.7-35~g44ac78d26 (Rasbien,Debian).

the cpu load and mem on the rp2b+ was not hit that hard with the ffmpeg fork, so guess its whats version ur using and that u have mapped syslog different.

After i mapped syslog to "/var/log/tvheadend.log" instead of standard the problems with stalling, dropouts & etc. stopped.

now I can swap channels instantly 0,5/1sec and no stalling/buffering whatsoever. tested with clients on my atv, mobile and laptop.

RE: IPTV - buffering, stalls, general drop outs. Settings that resolved things for me. - Added by Johan Albrektsson almost 6 years ago

Strange. i Run 4.3-1466~g0b8d903f2 and still must fork using ffmpeg.

Tom-Frode Pedersen wrote:

After i mapped syslog to "/var/log/tvheadend.log" instead of standard the problems with stalling, dropouts & etc. stopped.

How do you remap syslog? And how come that solved the stalling?

(1-25/71)