Jellyfin Forum
Comskip and Media Segments - Printable Version

+- Jellyfin Forum (https://forum.jellyfin.org)
+-- Forum: Support (https://forum.jellyfin.org/f-support)
+--- Forum: General Questions (https://forum.jellyfin.org/f-general-questions)
+--- Thread: Comskip and Media Segments (/t-comskip-and-media-segments)

Pages: 1 2


RE: Comskip and Media Segments - esvee - 2025-03-25

I’m finding media segments not entirely reliable. If I record the same show using Plex and jellyfin at the same time, and pass each through the same script, the output that imports automatically into jellyfin does not skip ads. But importing the one from Plex does. Both have the chapter markers.

My suspicion is that there is something going on with the library refreshing during the recording and media segments not getting picked up (because they don’t exist yet).

But @TheDreadPirate you say the metadata is tied to file? So shouldn’t the comskipped remux file get its own database and media segment entries?

is there a way to manually purge chapter segment info from the database? - as deleting and reimporting the file doesn’t help, nor does triggering any metadata refresh or segment scan.. Smiling-face


RE: Comskip and Media Segments - TheDreadPirate - 2025-03-25

"Replace all metadata" should purge chapter segment info, right?

Also, media segments scans do not run on library import. It is a separate job in Scheduled Tasks.


RE: Comskip and Media Segments - esvee - 2025-03-25

(2025-03-25, 01:45 PM)TheDreadPirate Wrote: "Replace all metadata" should purge chapter segment info, right?

Also, media segments scans do not run on library import.  It is a separate job in Scheduled Tasks.

I’ve tried replace all metadata and also have media segments scheduled for every 30 minutes. Chapter segments aren’t triggering any skipping if there was previously a ts version of the file in the library. 

So as a workaround, ive found an ignore glob pattern plugin, to ignore ts files. That way the converted mp4 file is the first in the library, and com chapters skip as expected.


RE: Comskip and Media Segments - AustinL - 2025-03-31

I am making good progress with this project.  I can use the API to enumerate media segments for an item and I can delete media segments (if the Media Segments API plugin is installed on my server)... But I am having a real problem creating media segments.  The URL I am posting to is

http://myserver/MediaSegmentsApi/{itemId}

Where {itemId} is the ID of the parent item, and the request body is something like this:

{
"Id":"baaac615-a238-4cf2-8dcc-fb22afce9782",
"ItemId":"5a7af56b-eec6-f219-6cd0-d445b5bc87ad",
"Type":1,
"StartTicks":123527,
"EndTicks":345475
}

But... the API is expecting a URL parameter called providerId and I have absolutely no idea what this is - if I use a random string, I get the response:

{
    "message": "Provider with id 'RandomString' not found."
}

Any ideas? - What is a "provider" in this context, and how do I get an ID for it?

Thanks,
Austin


RE: Comskip and Media Segments - TheDreadPirate - 2025-04-01

I have recently been informed that you should avoid using the Media Segments API. It is a legacy implmentation prior to official media segment support in the server and is problematic post 10.10.

The proper media segments endpoints are documented here.

https://api.jellyfin.org/#tag/MediaSegments


RE: Comskip and Media Segments - AustinL - 2025-04-01

Ah, OK, thanks... the problem is that the native API only allows enumeration of media segments (which works perfectly for me), but it doesn't allow adding or removing segments, which is really what I'm trying to do with this project.

I can remove segments with the Media Segments API, but I can't add new segments... and from what you're telling me, I'm going about it the wrong way anyway :-(

Oh well... back to the drawing board - many thanks for all your guidance, it's really useful! I will post back here when (if) I make any further progress!

Thanks,
Austin


RE: Comskip and Media Segments - AustinL - 2025-04-01

Oh... I think I've just solved it!... if I use "Chapter Segments Provider" for the provider ID parameter, it seems to work - I can add new media segments to an item.

(Although that's using the third party API which you have advised against... so maybe it's not the ideal solution)

Complete code to follow in a few days when I've tidied it all up.


RE: Comskip and Media Segments - AustinL - 2025-04-02

All in Visual Basic, I'm afraid... I'm such an amateur.

First, a few constants:

Code:
        Const MyServer = "http://localhost:8096"
        Const PathToComSkip = "C:\ComSegments\comskip\comskip.exe"
        Const PathToComSkipINI = "C:\ComSegments\comskip\comskip.ini"
        Const AuthToken = "MediaBrowser Token=""MyAPIToken"""
        Const ProviderID = "Chapter Segments Provider"
        Const ComskipEDLFile = "C:\ComSegments\working\tmp.edl"

Next, Analyse the media file with Comskip and generate EDL file:

Code:
        Dim psi As ProcessStartInfo
        Dim p As Process

        psi = New ProcessStartInfo(PathToComSkip)
        psi.ArgumentList.Add(FileToAnalyse)
        psi.ArgumentList.Add("--ini=" & PathToComSkipINI)
        p = Process.Start(psi)
        p.WaitForExit()


And finally, mark the media segments:

Code:
        Dim lines = File.ReadAllLines(ComskipEDLFile)
        Dim LineParts() As String

        For Each line In lines
            LineParts = line.Split(vbTab)
            ms = New MediaSegment
            ms.Id = Guid.NewGuid
            ms.ItemId = Guid.Parse(ItemId)
            ms.Type = MediaSegmentType.Commercial
            ms.StartTicks = LineParts(0) * 10000000
            ms.EndTicks = LineParts(1) * 10000000
            h = New StringContent(JsonConvert.SerializeObject(ms), Encoding.UTF8, "application/json")
            Await Client.PostAsync(MyServer & "/MediaSegmentsApi/" & Guid.Parse(ItemId).ToString & "?providerId=" & ProviderID, h)
        Next


I'm still running this manually because I can't find a way of getting the ID of an item from the recording post processing command, but actually that's OK for me because only a few programmes that I record are on commercial TV.  I'm happy with it for my purposes, no need for any muxing, converting, creating chapters, or deleting - it doesn't even touch the source file.  If anyone is interested in taking the idea and making it into a plugin, that would be wonderful (not me, I don't have the skills or the patience), and it would be really cool if the Jellyfin geniuses could expand the native Media Segments API to allow creation and deletion and avoid the need to use the third party Media Segments API plugin.

And my wife is happy because she now gets a "Skip Ads" button when she watches her favourite soaps :-)

Many thanks to TheDreadPirate and esvee for pointing me in the right direction!

Austin