Start with what a good break is
- It sits in a natural pause of the story, not in the middle of a sentence.
- It keeps some distance from speech, so the cut does not clip a word.
- It lands on a frame that a player or packager can cut cleanly, normally a keyframe.
- It stays out of the opening and closing credits and away from the first and last moments of the programme.
- It is far enough from the previous break, and the total fits the limits your ad operations or contract set.
Step 1: collect candidates
ffmpeg can list timestamps for the usual pause signals without editing the file. The thresholds below are starting points, not recommendations; tune them per title and genre.
ffmpeg -i episode.mp4 -vf "blackdetect=d=0.1:pix_th=0.10" -an -f null -ffmpeg -i episode.mp4 -af "silencedetect=noise=-35dB:d=0.5" -vn -f null -ffmpeg -i episode.mp4 -vf "select='gt(scene,0.4)',showinfo" -an -f null -None of these signals is a break on its own. Many files have no fades to black, silence often happens under music or effects, and a shot change is just a cut. They produce candidates.
Step 2: rank the candidates
- A black frame together with a quiet stretch is stronger than either alone.
- A shot change right after a speaker finishes is stronger than one in the middle of a conversation.
- Speech timing matters most. Transcript or voice-activity timestamps give you the end of each phrase, so you can measure how far every candidate is from the nearest speech.
- Keep the reason for each pick, such as “dark screen” or “end of a phrase”, so a reviewer can judge it quickly.
Step 3: apply the rules
| Rule | Why it exists | What you set |
|---|---|---|
| Skip the start and the end | Keeps the opening and the close of the programme intact | Seconds ignored at each end |
| Minimum gap between breaks | Stops breaks from clustering | Shortest allowed distance between two breaks |
| Number of breaks by programme length | A feature film and a short episode need different amounts | Minimum and maximum breaks per length band |
| Minimum confidence | Filters weak candidates before a person sees them | A score threshold |
| Distance from speech | Avoids clipping dialogue | Shortest allowed gap to the nearest speech |
| Credits | Opening and closing credits are not story pauses | Detect and exclude the credit range |
There is no universal number for any of these. Take them from your ad operations policy and your platform’s rules, and test them on a few titles.
Step 4: put the break on a cuttable frame
For SCTE-35 and HLS markers the splice should fall on a keyframe or a segment boundary. Otherwise the packager has to cut late, or the player has to decode extra frames. This command lists video packets with a K flag for keyframes, so you can find the nearest one after each chosen time.
ffprobe -v error -select_streams v:0 -show_entries packet=pts_time,flags -of csv=p=0 episode.mp4 | grep ",K"Step 5: review and export
Reviewing a shortlist of a dozen candidates is much faster than scrubbing a whole file, and a person keeps the last word on taste and context. Keep a record for every break: time, reason, confidence, distance to speech and whether it was accepted. That record lets you tune the rules later. Then write the accepted times in the form your downstream system ingests; this guide explains the options.
Doing it for a whole library
The method does not change at library scale, but consistency matters more. Use the same presets for programmes of the same length, process files as they arrive instead of in one big batch, and watch how often reviewers reject breaks, because that is the quickest signal that a rule is off.
AdBreak runs steps 1 to 4 on a finished file. It reads scene changes, dark frames, speech, silence, loudness and motion, applies presets set by programme length (minimum confidence, time skipped at the start and the end, the shortest gap between breaks and the minimum and maximum number of breaks), detects opening and closing credits apart from the breaks, and returns each break with a time, a reason, a confidence and the distance to speech. See how it works, or estimate the effort with the cost calculator.