r/FieldStation42 • • Oct 15 '26

Does anyboy know of an automated tool for adding chapters to videos that dont have them and export an EDL of text or other format to remux them in?

I have a lot of older TV shows/VHS rips/Laserdisc rips that have no chapter data of any sort.

I understand the process of making a chapter file in various video tools, and using mkvtools to remux it into the file so FS42 can detect it.

But im talking about 10,000+ individual files with no existing chapters. So there is no way i can get this done manually by searching for good spots on my own and marking them, exporting an edl, then going to mkvtollnix and remuxing it in. Anyone know of any tool that can reliably find scenes and add ~8 chapters per tv show and ~20 per movie (as opposed to davinci resolve, which ive tried to use to cut old commercial repos into individual files, and it just makes thousands of 1 second clips... haha)

8 Upvotes

21 comments sorted by

10

u/wrong-dog Oct 15 '26

For chapters, I made this thing called chapter-marker-thingy specifically for FieldStation42 users as a Christmas gift last year: https://github.com/shane-mason/chapter-marker-thingy - it will add chapters if the file doesn't have them. You should be able to run it over an infinite number of files - you can set the maximum number of breaks per hour and the max gap between breaks.

Under the hood, it uses FFMPEG black detect, scene detect and silence detect filters. It pools the results and finds overlap to increase confidence - then it will pick the most confident matches.

By default, it doesn't write any changes, so you can test it to see what gets the best results.

1

u/TheKlaxMaster Oct 15 '26 edited Oct 15 '26

Did a little reading. Seems like a good fit. Thanks for the comment.

What I didn't see, or maybe missed, is does it/can it ignore a file if it already has chapters? I do have a hefty amount with chapters already. Wouldn't want to risk changing them and making it worse

3

u/wrong-dog Oct 15 '26

Yep - you pass in "--skip-existing" and it will ignore any files that already have chapter markers.

1

u/TheKlaxMaster Oct 15 '26

can you, or anyone else, help explain how or why this is safe, im not an experienced dev, so i dont know all the intricacies.

The Verdict

File 1 (cmchapter.py) and File 2 (cmsplit.py) are Secure. They execute subprocesses safely using lists.

File 3 (cmthingy.py) contains a Critical Security Vulnerability due to the use of shell=True combined with unvalidated user input via filenames.

Key Risks

Command Injection: If any part of the command string comes from untrusted user input, an attacker can inject malicious shell metacharacters (such as ;, &&, |, or \) to execute arbitrary commands on your system (e.g., ; rm -rf /). [[1](https://www.google.com/goto?url=CAESkAEB6zswFX36bvKuGvmqUTlmxuvPpCxkBjl2MeosxTAihbfRsN1oGr4ueWP4zJ0lEwqer__YcHD4fWzL9wz4YukXfGv7avR4hmBhuDQRf7uNXLMzSsfDNWD15rNMTpkKiIL3BwBwTptPaBNRorpjifupVc_sLK1Hd6qNCEq2d9bKz-BGrHpCnu6fs6Ik_zOJHL4)]`

Unnecessary Attack Surface: Even without direct user input, parsing strings through a shell introduces extra complexity, quoting issues, and unexpected behavior from shell expansion rules. [1]

Unsafe Convenience: Developers often use shell=True for shortcuts like wildcards (*.txt), pipes (|), or environment variable expansion, which can be handled safely without a shell. [1]

Safe Alternatives

Pass the command and its arguments as a list of strings instead of a single formatted string with shell=False (the default). [1]

Use built-in Python modules (such as glob for file patterns or native file operations) instead of shell commands. [1]

If you have a specific subprocess snippet you are working with, share it and I can show you how to rewrite it safely without shell=True.

Since this thing will be handling video files on my main NAS, i want to be sure of everything it can and should do, and what could go wrong if it went catastrophic

1

u/wrong-dog Oct 15 '26 edited Oct 15 '26

What its telling you is that you should not get random strings (words, filenames etc) from the internet and use it on the command line (like rm -rf /) - but this is true of any program. Don't put unsafe strings into any programs you run and not specific to this. All I can tell you is that its been used by hundreds of people on the discord server, many like myself have large collections and I've never heard anyone say it did anything bad for them. My recommendations:

A) Use it on a small selection of copies of your files first and make sure it does what you expect.
B) Don't use the --overwrite switch - it will work on copies. If your happy with what it does, then you can use them over the originals.
C) Go find a different program that your AI trusts that will work for you.

This is a local application being run by you, so you are fully in charge of what you put on the command line.

1

u/TheKlaxMaster Oct 15 '26 edited Oct 15 '26

I'm sorry if I offended you. But I don't know you or anyone here, so I don't think it should be something to snap at me for, just because I went to Google to ask about potential security oversights in random code I got from a random stranger on the internet. And then going to a real human to ask about So i can learn. When people like you get upset over questions, can you blame anyone for not wanting to ask a real human? I avoid AI as much as possible. But it certainly is beneficial to ask low stake questions to ai, and leave the deep dive for a real human. (And in my case, ai means Google. I have never used chatgpt or Claude or whatever else there is, but I can't help it if Google's main search is now integrated with ai)

And we should be encouraging security paranoia and education, not condescending it....

For all I knew there was some bit of code in there that installed a pubkey or some other potential back door. so you can't fault me for looking, and trying to understand what I'm doing. I don't know it's history, and I'm not privy to people conversations about it

Blindly taking code on the internet and running it without a thought is just as dumb as generating code from AI and running it.

Thanks for your help this far. Again, sorry to have made you upset by asking a question about safety

1

u/wrong-dog Oct 15 '26

I had already edit my comment by the time you posted this to make it not sound condescending. You're correct to take security seriously - I don't see this one as an issue though, just don't pass anything but valid filenames on the command line.

1

u/wrong-dog Oct 15 '26

And, to note, if you're using FieldStation42 on your computer, you're already running my code. I am the creator and maintainer of FieldStation42.

1

u/TheKlaxMaster Oct 15 '26

Well thanks Shane. But my FS42 is on a pi5 with read only access to my nas using symlinks, so it can't modify anything (only commercials are kept local since they play and seek more frequently)

This was more cause for concern because it will need to be run on something that has write access to my nas, which means it can be detrimental

1

u/wrong-dog Oct 16 '26

Makes sense to me.

1

u/TheKlaxMaster Oct 15 '26 edited Oct 16 '26

Naturally the show I tested it on had a good example in the pilot episode.

Ep2+ it wasn't finding anything after1 minute mark. Took a look at the episode, and they use wipe transitions with both audio, and visual (cgi) added in, so there is no visual or auditory gaps. Lol

So i used the max gap flag, and max breaks flag to control it, and I'm a little confused...

$ python cmthingy.py -f /target.mkv --write-chapter --overwrite --max-gap 6 --max-breaks-per-hour 8

Processing: Bone Chillers, S1E03 - Back To School.mkv
/tagert.mkv
Video duration: 1282.49 seconds (21.37 minutes)
Detecting black spaces...
Found 10 black periods
Detecting silence periods...
Found 0 silence periods
Detecting scene changes...
Found 35 scene changes
Cleaned to 6 natural break points (black frames)
Analyzing optimal break points...
Selected 3 commercial break points

                        Commercial Break Points                         
┏━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃ # ┃ Timestamp ┃ Time (seconds) ┃    Type     ┃ Confidence ┃ Silence? ┃
┡━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ 1 │   0:46    │         46.71s │ Black Frame │    HIGH    │          │
│ 2 │   7:50    │        470.48s │ Black Frame │    HIGH    │          │
│ 3 │   14:41   │        881.94s │ Black Frame │    HIGH    │          │
└───┴───────────┴────────────────┴─────────────┴────────────┴──────────┘

Writing chapters to video file...
✓ Chapters written successfully!
Updated: /target.mkv

But the difference between the last chapter made (14:41 / 881.94s) and the end of the episode (1282.49s) is GREATER than 6 minutes (360 seconds)

so why didnt one one more chapter get made? (also the gap between chpater 1 and 2 is 7 minutes and a few seconds, also going over 6 mins)

My best guess would be that all those blanking periods are in the first half, and it's not finding a suitable break, and that supercedes the requested max gap and there is no min breaks per hour?

2

u/wrong-dog Oct 16 '26

Oh - looking at this again, your max-breaks-per-hour is too low. It found 6 black frames where a break could go ("Cleaned to 6 natural break points"). The cap turns "per hour" into a fixed number for this episode. 8 per hour on a 21-minute episode works out to 2.85, which rounds up to 3 breaks allowed. Can you run it again with more than 8 breaks per hour? It should be 12, but even 10 should work here. The cap will always supersede the gap argument.

1

u/TheKlaxMaster Oct 16 '26

I want to say I definitely did, (and also excluded that argument, leaving it for the default 12)

But for sanity check I will do it again when I can and let you know

1

u/TheKlaxMaster Oct 16 '26

Well, cleary i didnt do something i thought i did, because with gap=6 and per hour left at default, the above file gets 6 chapters 2 in the first minutes, then 7, 8, 14 and 15 minute marks, which i think is good enough - definitely a better experience than the default evenly distributed if it can be avoided.

however, still having an issue with the previously mentioned blues clues, i assume it has to do with black periods? and i assume the black periods are the result of the quality recording?

$ python cmthingy.py -f /target.mp4

Processing: Blue's Clues S01E01 Snack Time.mp4 --max-gaps 6
/target.mp4
Video duration: 1474.07 seconds (24.57 minutes)
Detecting black spaces...
Found 2 black periods
Detecting silence periods...
Found 602 silence periods
Detecting scene changes...
Found 75 scene changes
Cleaned to 0 natural break points (black frames)
Analyzing optimal break points...
Selected 1 commercial break points

                         Commercial Break Points                         
┏━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃ # ┃ Timestamp ┃ Time (seconds) ┃     Type     ┃ Confidence ┃ Silence? ┃
┡━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ 1 │   12:57   │        777.81s │ Scene Change │    HIGH    │    ✓     │
└───┴───────────┴────────────────┴──────────────┴────────────┴──────────┘

$python cmthingy.py -f /target.mp4 --max-gap 6 --max-breaks-per-hour 15

Processing: Blue's Clues S01E01 Snack Time.mp4
/target.mp4
Video duration: 1474.07 seconds (24.57 minutes)
Detecting black spaces...
Found 2 black periods
Detecting silence periods...
Found 602 silence periods
Detecting scene changes...
Found 75 scene changes
Cleaned to 0 natural break points (black frames)
Analyzing optimal break points...
Selected 1 commercial break points

                         Commercial Break Points                         
┏━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃ # ┃ Timestamp ┃ Time (seconds) ┃     Type     ┃ Confidence ┃ Silence? ┃
┡━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ 1 │   12:57   │        777.81s │ Scene Change │    HIGH    │    ✓     │
└───┴───────────┴────────────────┴──────────────┴────────────┴──────────┘

1

u/wrong-dog Oct 16 '26

You command looks right so it definitely should have added a break in there. In situations like the 7 minute break between 1 and 3, it basically will choose the center point between detected breaks if there are no candidate positions. On the big gape at the end, I'll need to trace through and see what's going on.

1

u/TheKlaxMaster Oct 16 '26

i felt like i was hitting a wall, because even in another test video i was getting only 1 break at 12:57. so i ended up kind of brute forcing it by changing some parameters around, and my end result is i made it kind of hyper specific to 18-29 minute shows. it will do a minimum of 3 breaks aimed for the around 6, 12 and 18 minute marks. and skips any show not within the 18-29 minute length. i'll have to make another one for hour shows, and another one for movie lengths (unless i dont, because those will generally be better quality)

if you wanted to use a specific video, i was using s01e01 of blues clouse (only finding 12:57 with gap at 6 and max per hour at 10):

from here
https://archive.org/details/blues-clues-s-03-e-59-blues-big-musical-movie

1

u/wrong-dog Oct 16 '26

If you're picking set points, that's how FS42 works without chapter markers already. It will break the base content into even increments and insert them there.

1

u/TheKlaxMaster Oct 16 '26

No, not set. It's still using scene detection but it's looser detection, and stricter timing.

1

u/TheKlaxMaster Oct 16 '26 edited Oct 16 '26

here is an example output of the version i tweaked did:

═══ File 121/7221 ═══

Processing: Big Bad Beetleborgs S01E41 - Something.Fishy.mkv
/target.mkv
Video duration: 1220.38 seconds (20.34 minutes)
Detecting black spaces...
Found 18 black periods
Detecting silence periods...
Found 126 silence periods
Detecting scene changes...
Found 102 scene changes
Cleaned to 16 natural break points (black frames)
Analyzing optimal break points...
Selected 3 commercial break points

                        Commercial Break Points                         
┏━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃ # ┃ Timestamp ┃ Time (seconds) ┃    Type     ┃ Confidence ┃ Silence? ┃
┡━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ 1 │   5:37    │        337.04s │ Black Frame │    HIGH    │    ✓     │
│ 2 │   10:40   │        640.04s │ Black Frame │    HIGH    │    ✓     │
│ 3 │   17:10   │       1030.17s │ Black Frame │    HIGH    │          │
└───┴───────────┴────────────────┴─────────────┴────────────┴──────────┘

vs what the original did:

Processing: Big Bad Beetleborgs S01E41 - Something.Fishy.mkv
/target.mkv
Video duration: 1220.38 seconds (20.34 minutes)
Detecting black spaces...
Found 6 black periods
Detecting silence periods...
Found 126 silence periods
Detecting scene changes...
Found 102 scene changes
Cleaned to 4 natural break points (black frames)
Analyzing optimal break points...
Selected 4 commercial break points

                        Commercial Break Points                         
┏━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃ # ┃ Timestamp ┃ Time (seconds) ┃    Type     ┃ Confidence ┃ Silence? ┃
┡━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ 1 │   0:32    │         32.08s │ Black Frame │    HIGH    │    ✓     │
│ 2 │   6:05    │        365.73s │ Black Frame │    HIGH    │          │
│ 3 │   10:40   │        640.02s │ Black Frame │    HIGH    │    ✓     │
│ 4 │   18:52   │       1132.00s │ Black Frame │    HIGH    │    ✓     │
└───┴───────────┴────────────────┴─────────────┴────────────┴──────────┘

so its maybe doing just a tad better on specific files in my playlist, while not destroying the result of the bulk of media compared to the OG? i guess

2

u/wrong-dog Oct 16 '26

I think its the lack of silence that's the main cause likely. Max gap is really more of a hint than anything else - it won't fire unless it finds silence near a scene transition. The documentation for max-gap says "Maximum gap in minutes before inserting scene-based break" - but if it can't find a scene based transition with silence, it doesn't just pick the centerpoint, it leaves it alone and moves on. I think this is the right behavior ultimately, because otherwise you end up with mid-sentence breaks and FS42 is pretty good at adding those itself if there are no chapter markers. Ultimately, chapter-marker-thingy isn't perfect, but its better than evenly spaced intervals. I'll update the documentation to reflect that its just a hint. I'm also open to ideas on how it should behave in these cases.