Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add #EXT-X-DISCONTINUITY support to ffmpeg for IPTV streams such as Stirr and Pluto #57

Open
jcdick1 opened this issue Dec 29, 2020 · 46 comments
Labels
enhancement New feature or request help wanted Extra attention is needed upstream

Comments

@jcdick1
Copy link

jcdick1 commented Dec 29, 2020

There are issues with IPTV streams that use the DISCONTINUITY tag in the HLS playlist, causing dropouts, freezing, etc.

Compiling ffmpeg with support for this flag will be an improvement for IPTV users.

See this thread and scroll down to around the May 2020 time frame for a discussion of the issue for Kodi and ffmpeg with Pluto and Stirr:

https://forums.whirlpool.net.au/archive/9nk7ly73

@Artiume
Copy link

Artiume commented Jan 12, 2021

@eqpaisley
Copy link

+1 for interest in hearing if we can handle DISCONTINUITY in JF.

@m0ngr31
Copy link

m0ngr31 commented Jan 20, 2021

Would also like this

@Protektor-Desura
Copy link

I would love to see this supported as well. It would also also be nice to see inputstream.adaptive from Kodi supported as well to support WideVine DRM like Kodi supports.

@heyhippari
Copy link

support WideVine DRM

That seems like a massive open door for DMCA issues.

@Protektor-Desura
Copy link

Protektor-Desura commented Feb 12, 2021

Why would supporting DRM open an issue for DMCA? That makes zero sense. You will still have to pay to use the service and still need a login and password. Kodi officially supports Netflix, Amazon, Disney+ and other plugins. I don't see the problem here. If anything it seems like it would move away from being a product "mostly for pirating" and make it more legitimate since you are supporting legal streaming.

@watchydev
Copy link

Would love to see this added. Seems it could fix issues with us and Live TV issues.

@bobcoup
Copy link

bobcoup commented Sep 5, 2021

Can I +1 this? Would also like it to be implemented. Thanks.

@yarafie
Copy link

yarafie commented Dec 18, 2021

Yes I vote for this

@cvium
Copy link
Member

cvium commented Dec 18, 2021

You can vote and +1 it all you want, but it's not going to change anything. Someone needs to implement it.

@yarafie
Copy link

yarafie commented Dec 18, 2021

@Protektor-Desura
Copy link

Protektor-Desura commented Dec 19, 2021

https://github.com/jjustman/ffmpeg-hls-pts-discontinuity-reclock

This one is a great start just needs to patched to the most current version of ffmpeg since that version looks to be about a 3 year old fork of ffmpeg. Not to mention there are links above to multiple patches to add support for this in ffmpeg.

The issue isn't code but the more the dev team applying these patches to their version of ffmpeg.

@neo-neo1
Copy link

Would love to see this added.

@SR-Lut3t1um
Copy link

It seems like the current work is done here:

It's possible to apply the patch and build ffmpeg. Since I have no stream that encounters this issue I can't say if the patch fixes every issue. It does however no longer skip EXT-X-DISCONTINUITY.

@Shadowghost
Copy link
Contributor

I think someone has but they need to apply it.

The issue isn't code but the more the dev team applying these patches to their version of ffmpeg.

If it's that easy, please provide a properly tested patchset as a PR, we are always happy if new people contribute features we don't have the time or interest (we're all just volunteers, doing work we're willing to invest time in) in implementing.

@TeknikalDomain
Copy link

TeknikalDomain commented Jan 10, 2022

Since I have no stream that encounters this issue I can't say if the patch fixes every issue. It does however no longer skip EXT-X-DISCONTINUITY.

I do, and I can say it still complains readily about (and freezes with) a Non-monotonous DTS in output stream, so unless something is wrong with my system (Don't think there is, and it's definitely using the newly-built version), I don't think that's all there is to it.

@wertercatt
Copy link

Since I have no stream that encounters this issue I can't say if the patch fixes every issue. It does however no longer skip EXT-X-DISCONTINUITY.

I do, and I can say it still complains readily about (and freezes with) a Non-monotonous DTS in output stream, so unless something is wrong with my system (Don't think there is, and it's definitely using the newly-built version), I don't think that's all there is to it.

If it’s legal to do so, please post the m3u8 link to help troubleshoot.

@TeknikalDomain
Copy link

If it’s legal to do so, please post the m3u8 link to help troubleshoot.

For testing purposes I was using this list for Pluto, using... whatever channel was airing TV shows, not movies (since Pluto does their own thing with channels, I can't remember, but it shouldn't matter as they all behave the same way, just that they run more ad segments on TV programming)

@Protektor-Desura
Copy link

Protektor-Desura commented Jan 22, 2022

It is legal for Xumo, Stirr, Pluto and Plex TV streams

Pluto TV
https://raw.githubusercontent.com/matthuisman/i.mjh.nz/master/Plex/us.m3u8
https://raw.githubusercontent.com/matthuisman/i.mjh.nz/master/Plex/us.xml

Vizio Free TV Streaming
https://www.apsattv.com/vizio.m3u

Here is a whole bunch of free and legal steaming channel and guides here:
https://i.mjh.nz/
https://i.mjh.nz/PBS/
https://i.mjh.nz/Plex/
https://i.mjh.nz/PlutoTV/
https://i.mjh.nz/SamsungTVPlus/
https://i.mjh.nz/Stirr/

Should be plenty of legal public streaming TV for anyone to test things out and see the problems.

@Protektor-Desura
Copy link

Protektor-Desura commented Jan 22, 2022

One of the major issues is that RFC-8216 is not fully supported in FFMPEG

https://datatracker.ietf.org/doc/html/rfc8216

#EXT-X-DISCONTINUITY is just one of the things from RFC-8216 that isn't supported properly in FFMPEG.
#EXT-X-DISCONTINUITY-SEQUENCE is also not supported properly either.

Just look through the RFC and you still see things missing from FFMPEG.

@wertercatt
Copy link

One of the major issues is that RFC-8216 is not fully supported in FFMPEG

https://datatracker.ietf.org/doc/html/rfc8216

#EXT-X-DISCONTINUITY is just one of the things from RFC-8216 that isn't supported properly in FFMPEG.

#EXT-X-DISCONTINUITY-SEQUENCE is also not supported properly either.

Just look through the RFC and you still see things missing from FFMPEG.

It might be worth replacing FFmpeg as an m3u8 parser with https://github.com/globocom/m3u8, which is an Expat licensed RFC-8216 player, for now. And then I can work on getting FFmpeg up to compliance without Jellyfin users continuing to be inconvienced.

@Protektor-Desura
Copy link

Not sure what you mean by Expat license for:
https://github.com/globocom/m3u8
Since it is listed as an open source MIT license.

@wertercatt
Copy link

Not sure what you mean by Expat license for:

https://github.com/globocom/m3u8

Since it is listed as an open source MIT license.

Calling something the 'MIT license' is unclear, as MIT has used several different licenses over time. The more accurate term for the specific one in use by that project is the Expat License, as you can read about at https://www.gnu.org/licenses/license-list.html#Expat

@Shadowghost Shadowghost added enhancement New feature or request help wanted Extra attention is needed labels Jun 7, 2022
@MirCola
Copy link

MirCola commented Jun 19, 2022

Is it possible to bypass #EXT-X-DISCONTINUITY with using TVHeadend? I found this: https://tvheadend.org/boards/5/topics/43052?page=1&r=45733 and it looks promising, but i didn't test it yet.

@TeknikalDomain
Copy link

I can test that later today, to see if we at least have a workaround

@ASHuenchuleo
Copy link

ASHuenchuleo commented Aug 23, 2022

Is it possible to bypass #EXT-X-DISCONTINUITY with using TVHeadend? I found this: https://tvheadend.org/boards/5/topics/43052?page=1&r=45733 and it looks promising, but i didn't test it yet.

After seeing this message, I attempted to use Cabernet, but it has very little documentation. The best I got was getting the stream to close when the commercials started, and to get it to resume as soon as the commercials ended by pressing play again (A black screen is shown until then, and sometimes it just doesnt load). Here's a sample of my config file:

[m3u_plutomx]
label = M3U PlutoTV Mexico
channel-m3u_file = https://i.mjh.nz/PlutoTV/mx.m3u8
epg-xmltv_file = https://i.mjh.nz/PlutoTV/mx.xml
enabled = True
channel-group_name = plutomx
player-enable_pts_resync = True
channel-import_groups = True
epg-min_refresh_rate = 3600
player-enable_url_filter = True
player-url_filter = ^.(_ad/|google.com|plutotv_filler|Well_be_right|_AdPod|_Promo|Filler).$
player-pts_resync_type = ffmpeg
player-stream_type = internalproxy
player-enable_pts_filter = False

I also attempted to feed cabernet into tvheadend, then into Antenna and then into jellyfin but it work worse.

@wilsonssss

This comment was marked as spam.

@jedthe3rd
Copy link

jedthe3rd commented Mar 6, 2023

I got this patch applied to a local copy of jellyfin-ffmpeg-v5.1.2-8 (http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20180316/739542e4/attachment.obj)

I just need some help getting my wrapper script that passes the new parameter (-force_dts_monotonicity) into the commands jellyfin passes. I have tried just putting the full path to the .bat file in the transcoding configuration but it seems to be failing some sort of internal check. I put the bat file in the same location as my original ffmpeg.exe so all the other files (ffprobe.exe, etc) are there.

I am testing with a Windows jellyfin install on 10.8.9.

Error:
We're unable to find FFmpeg using the path you've entered. FFprobe is also required and must exist in the same folder. These components are normally bundled together in the same download. Please check the path and try again.

Edit: Figured it out, needed to handle version in my wrapper.

Edit 2: Got the patch working and a wrapper that adds the parameter. Streams are definitely more stable now and will continue to play. There are still some streams that seem to have hiccups or just refuse to play. Probably because this only addresses part of the RFC-8216 spec compatibility holes.

@jedthe3rd
Copy link

jedthe3rd commented Mar 7, 2023

Something I discovered while delving into this issue:
You can use Channels DVR as a tuner for jellyfin and Channels DVR has more complete support for HLS streams.
https://community.getchannels.com/t/use-channels-dvr-as-a-tuner-for-emby/22486

Now my main question:

Now that I have tested the patch and validated that it still works, is this type of patch (adding optional parameter for use by the server) something that should be added to jellyfin-ffmpeg? Edit: Realized we can also set it as a default option (no wrapper needed) if that is something that fits with the goals of jellyfin-ffmpeg.

Original Patch Link: http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20180316/739542e4/attachment.obj

@chilman408
Copy link

Something I discovered while delving into this issue: You can use Channels DVR as a tuner for jellyfin and Channels DVR has more complete support for HLS streams. https://community.getchannels.com/t/use-channels-dvr-as-a-tuner-for-emby/22486

Now my main question:

Now that I have tested the patch and validated that it still works, is this type of patch (adding optional parameter for use by the server) something that should be added to jellyfin-ffmpeg? Edit: Realized we can also set it as a default option (no wrapper needed) if that is something that fits with the goals of jellyfin-ffmpeg.

Original Patch Link: http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20180316/739542e4/attachment.obj

Hello, I'm not very savvy with this. Can you explain how to get your patch working step-by-step?

@jsnotlout
Copy link

Do we have any updates on this?

@Shadowghost
Copy link
Contributor

There is not much to update on as long as either someone provides a patch working with the current FFmpeg or it is fixed upstream.

@Johnny-Larue

This comment has been minimized.

@Slack-FX

This comment has been minimized.

@cvium

This comment has been minimized.

@Slack-FX

This comment has been minimized.

@cvium

This comment has been minimized.

@Johnny-Larue
Copy link

Still no update on this ):??

I just have my local channels and plutotv on my m3u, and pluto tv is completely unwatchable via jellyfin because of this issue. Every ad break crashes the stream, and streams won't play if an ad break is occurring.

Given one or two patches exist for past versions of FFMPEG mentioned earlier in this thread, surely there is a way to fix this for the current version of ffmpeg?

I look forward to your contribution!

Well I did just spend the day trying to understand the problem better, not sure where the attitude is coming from? Sheesh

Have you read the other comments? There is no update on this issue because we don't use this feature.

I'm sorry, I don't understand: Jellyfin doesn't use this feature, or the users don't use this feature?

@gnattu
Copy link
Member

gnattu commented Apr 28, 2024

Please stop arguing, that is not helpful.

Let me clarify the situation for you, as there may be some misunderstanding.

Regarding the "working" patches mentioned, it's important to note that they are not a spec-compliant implementation for streams with discontinuity. Instead, they are more of a hack that overrides all timestamps, and just hope the underlying muxer would smooth the playback for it, which is not considered a proper fix. While this approach might work for some streams, it's not guaranteed to work for all, and it was rejected by upstream ffmpeg for being too hacky.

Now, when it comes to supporting certain TV providers like Pluto, simply supporting discontinuity streams is not enough. This is because streams from providers like Pluto often break the HLS RFC spec in various ways, and a spec-compliant HLS demuxer would reject these streams as well.

To illustrate, proper support for the #EXT-X-DISCONTINUITY tag requires the HLS stream to have an EXT-X-DISCONTINUITY-SEQUENCE header to mark which discontinuity sequence the current playlist is in. However, PlutoTV manifests may have inconsistent numbers between updates, with values jumping from 2 to 0 or 1. According to the RFC, a decreasing number is not allowed.

In summary, the patch mentioned in this issue is deemed too hacky, and supporting TV providers like Pluto would require more than just an RFC-compliant HLS demuxer. So if you ask why there is no update, because there is no one want to solve all the challenges I mentioned for ffmpeg. The ticket is created for 8 years and the only thing we have now is a hacky patch that was rejected. What can we update with?

If someone wants to help, then we can have some updates and that's why we said "PRs are always welcome". I attempted to look at this once, and then I realized that the TV providers are more broken than I previously thought which made my attempt failed. Even if we do have disconituity tag support, malformed manifest update can lead to any kind of playback oddities, such as segments played multiple times, or periods switched before the end of their playback, due to the impossibility of determining the right sequence number and segment to be played.

@Johnny-Larue
Copy link

Johnny-Larue commented Apr 28, 2024

I apologize, I didn't mean to come off like I was arguing, I just want a better handle on the situation, because it seems wild to me that something would go this long without a fix, and I couldn't really understand why. Your explanation is exactly what I think was needed here, and as I understand it, the blame really rests with the content providers breaking spec, possibly intentionally, to throw a wrench into any efforts to use non-authorized streaming methods. So, if I understand the rest correctly - this ball is in the upstream ffmpeg developer community's court?

@jedthe3rd
Copy link

I apologize, I didn't mean to come off like I was arguing, I just want a better handle on the situation, because it seems wild to me that something would go this long without a fix, and I couldn't really understand why. Your explanation is exactly what I think was needed here, and as I understand it, the blame really rests with the content providers breaking spec, possibly intentionally, to throw a wrench into any efforts to use non-authorized streaming methods. So, if I understand the rest correctly - this ball is in the upstream ffmpeg developer community's court?

It's in the court of whomever wants to work on this. Either by adding fully functional patches to jellyfin-ffmpeg or contributing them to upstream ffmpeg. I ended up switching to using channelsdvr to act as my iptv management and just pass the streams from channelsdvr to jellyfin.

@Slack-FX
Copy link

Slack-FX commented Apr 29, 2024

Still no update on this ):??

I just have my local channels and plutotv on my m3u, and pluto tv is completely unwatchable via jellyfin because of this issue. Every ad break crashes the stream, and streams won't play if an ad break is occurring.

Given one or two patches exist for past versions of FFMPEG mentioned earlier in this thread, surely there is a way to fix this for the current version of ffmpeg?

I look forward to your contribution!

Well I did just spend the day trying to understand the problem better, not sure where the attitude is coming from? Sheesh

Have you read the other comments? There is no update on this issue because we don't use this feature.

"Have you read the other comments? There is no update on this issue because we don't use this feature" not sure why you're speaking for an open source volunteer community, but uhh, you do you bro.

Having a go at me when I was willing to take some time to work this out seems entirely childish, it was my first comment on a lengthy thread and tbh you seem needlessly rude, so i'll take a pass on wasting any more time on this issue, I was willing to help though, so nice work man.

Edit: gunna go out on a limb here and say, in my time looking in to this issue, I came across a number of reddit threads/and forum posts discussing this issue, generally in relation to Jellyfin - so "we don't use it", is more like, "i don't personally know how to fix it/and don't care to", and its fine to feel that way, but no need to be rude to other users who are otherwise interested in the feature/fixing the bug - and obviously its not like this issue is impossible to solve, given tivimate default player/and a number of other players can handle ad breaks just fine https://i.imgur.com/Iyc4hvA.png.

@cvium
Copy link
Member

cvium commented Apr 29, 2024

Look, you come in here complaining about a lack of updates (classic entitled user behaviour, not contributor). You don't mention wanting to contribute, you simply refer to the set of patches that have already been discussed. How is that helpful?

I'm sorry that you feel sarcasm is unhinged behaviour (yes, I see the edit). I'm gonna stop replying now, because it's a complete waste of time. If you want to contribute, then do. Actual contributors ask constructive questions and/or create PRs. They don't come in here pointlessly adding to the pile of "omg, no updates?".

so "we don't use it", is more like, "i don't personally know how to fix it/and don't care to"

It's actually literally "we don't use it". gnattu is the only one on the team that uses a TV provider with ad breaks. We have no real incentive to grab a random set of patches, try to fix them up and then maintaining the mess, and you shouldn't want us to because it's never gonna be any good.

@Slack-FX
Copy link

Slack-FX commented Apr 29, 2024

(classic entitled user behaviour, not contributor)

I am mainly a user yes, but I do have some programming ability, and while I don't want to speak too soon, i MIGHT have found a possible pathway to a solution that uses something ffmpeg adjacent (sorta, will explain if testing pans out) -- I know I said I decided not to help, but I guess I couldn't help myself. At the moment I've gone through about 5-6 ad breaks on a plutotv stream (30 mins so far), and no crashes yet, will update with more details in a bit once I've done some more testing with a few channels.

Edit:

So I had been going around compiling different IPTV players to see how each of them handles ad breaks/discontinuity and i came across this https://github.com/Roshan-R/termv which is a CLI tool for MPV player --- when i found this earlier i didn't actually know about the main repo for mpv coz i'd never used it before https://github.com/mpv-player/mpv, so i just compiled roshan-r's CLI tool for it (comes with a bunch of the iptv channels by default, handy for testing if you don't have any playlists handy). (I compiled using Ming64 on windows after initially having trouble doing it via windows linux subsystem if anyone else wants to test channels using the CLI tool).

dev's or whatever might have heard of MPV player before because mpv shim exists, but as best I can tell, if it was possible to create a web-assembly for it/some kind of wrapper idk, it might be possible to have IPTV in Jellyfin be handled by MPV player instead and have it be server side.

To be clear, I haven't begun to imagine how this might be integrated in to Jellyfin/and even if it was, it seems like it might only be useful for IPTV, at this stage just here to confirm that MPV is a much more stable hls player than vanilla ffmpeg/or jellyfin ffmpeg, and if anyone wants to brainstorm how this could be approached, i'd possibly be game to try and help. At the time of writing this, MPV has been streaming several channels for 3-4 now 6 hours uninterrupted - the ads/pluto splash screen music even play, as opposed to freezing or blackscreen like you get with VLC. MPV was also originally built from ffmpeg, so that might be a point in favour of compatibility in terms of intergration.

I wasn't sure if trying to integrate MPV would be viable, or perhaps if it'd make sense to try and make Jellyfin FFMPEG offload handling of IPTV by primarily adapting Jellyfin FFMPEG/maybe have run headless window for mpv and have its output sent to ffmpeg which rebroadcasts it (bit of a hacky solution so probs not - but it does have API capabilities through ' JSON IPC API') either way I'm not confident at all that I'd be able to figure that out lol just throwing ideas out there. Also for testing purposes, I couldn't find any ready-made solutions that allow MPV to have its playback viewed in browser, so that would also need to be overcome i guess (i'm assuming lol, idk). Anyway i've updated this comment like 30 times, have conveyed all I've figured out for now, will probably keep tinkering to see how a solution might be applied.


Edit 2: https://github.com/video-dev/hls.js is also probably a potential candidate for integration and might make more sense as its already able to handle browser playback/and also has a high level of stability from my testing so far.

https://www.hlsplayer.org/ uses it, so im testing a bunch of channels now and if they all work will begin investigating ways to give hls.js as an option for iptv playback. It seems like it'd make sense to try and implement it as an optional way to playback iptv.

edit3: oh just realized exo-player is based on hls.js and so is available client side. Also similarly, mpv seems to have an android app as an option for a client side player but it doesn't seem to handle streams at all compared to its pc counterpart. I guess I am trying to envision a server-side solution rather than a client side one that bypasses these issues. Will continue to see if i can come up with some kind of solution/workaround.

@dukenukemx
Copy link

Have the same problem with Jellyfin on Linux Mint 21.3. So it seems FFMPEG needs HLS PTS Discontinuity Support? Doesn't look like it's been updated for 6 years. Will it still work with newest FFMPEG? Trying to make Jellyfin a replacement for cableTV for my parents and I'm sure they don't wanna be told to restart the video every 2-7 minutes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed upstream
Projects
None yet
Development

No branches or pull requests