<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Saisurya on Medium]]></title>
        <description><![CDATA[Stories by Saisurya on Medium]]></description>
        <link>https://medium.com/@saisurya8143?source=rss-1c3abe9ab56c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*jMqMpcQWiN-5Erdj</url>
            <title>Stories by Saisurya on Medium</title>
            <link>https://medium.com/@saisurya8143?source=rss-1c3abe9ab56c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 14:29:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@saisurya8143/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Finding Intros and End-Credits in TV Episodes: An Audio-Fingerprint + OCR + Vision-Model Pipeline]]></title>
            <link>https://medium.com/@saisurya8143/finding-intros-and-end-credits-in-tv-episodes-an-audio-fingerprint-ocr-vision-model-pipeline-914722c50d65?source=rss-1c3abe9ab56c------2</link>
            <guid isPermaLink="false">https://medium.com/p/914722c50d65</guid>
            <category><![CDATA[vlm]]></category>
            <category><![CDATA[audio-fingerprinting]]></category>
            <category><![CDATA[binge-watching]]></category>
            <category><![CDATA[ocr]]></category>
            <category><![CDATA[ott]]></category>
            <dc:creator><![CDATA[Saisurya]]></dc:creator>
            <pubDate>Fri, 28 Aug 2026 10:43:53 GMT</pubDate>
            <atom:updated>2026-08-28T10:43:53.101Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PkX2haUlR3qIZggLkYy4Kg.png" /></figure><p>Every streaming app has two little buttons that feel like magic: <strong>Skip Intro</strong> and <strong>Next Episode</strong>. Both depend on knowing, per episode, exactly where the intro sits and exactly where the end-credits begin. Get it wrong by a few seconds and the experience breaks — you skip into the middle of a scene, or the “next episode” prompt covers dialogue that still matters.</p><p>I spent a good chunk of the last few months building a system that generates these markers automatically across a large, messy catalog of unscripted and scripted series. This post is about the engineering: what signals to use, where the naive approach falls apart, and how to make the whole thing survive contact with production.</p><p>Everything here is described in general terms. The techniques are broadly applicable; the specific numbers come from an internal evaluation on 100+ episodes spanning a dozen different series and genres.</p><h3>The problem, stated precisely</h3><p>For each episode we want two time intervals in milliseconds:</p><ul><li><strong>Intro</strong> — the recurring opening sequence (theme music, title card, recap).</li><li><strong>End-credits</strong> — where the closing credits start, plus any post-credits content.</li></ul><p>Two constraints make this harder than it sounds:</p><ol><li><strong>Accuracy is judged at the boundary.</strong> A marker that’s “roughly right” isn’t good enough. We measure with Intersection-over-Union (IoU) against hand-labeled ground truth and track mean absolute error on the start/end timestamps in milliseconds.</li><li><strong>The catalog is heterogeneous.</strong> Different genres, different intro styles, cold opens, animated logos, disclaimers, burned-in captions, multiple audio languages. Anything that assumes a fixed template breaks on the next series.</li></ol><h3>Two problems that look similar but aren’t</h3><p>The key early insight: intros and credits are best found with completely different signals.</p><ul><li><strong>Intros are an audio problem.</strong> The opening theme is nearly identical across every episode of a season. That repetition is a gift — you can find it by matching audio to itself.</li><li><strong>Credits are a visual problem.</strong> End-credits are defined by scrolling or static <em>text</em> on screen. Audio during credits is arbitrary (music, dialogue bleed, silence), so you have to <em>read the screen</em>.</li></ul><p>Treating them as one problem is the mistake. Splitting them let each half use the right tool.</p><h3>Part 1 — Intros via audio fingerprinting</h3><h3>The core idea</h3><p>Take the first several minutes of audio from multiple episodes of the same season. The intro is the segment that repeats. So:</p><ol><li>Convert each episode’s opening audio into a compact <strong>fingerprint</strong> — a sequence of frames, each capturing a few dominant frequency bins and their magnitudes.</li><li><strong>Cross-match</strong> episodes against each other. Where many episodes align on the same offset, that’s your intro.</li><li>Store that season-level fingerprint once. For any new episode, match it against the stored fingerprint to locate the intro in that specific episode.</li></ol><p>This is a two-phase design: an expensive <strong>discovery</strong> step per season, then a cheap <strong>detection</strong> step per episode.</p><h3>How the matching actually works</h3><p>The heart of it is an <strong>offset histogram</strong>. Given two fingerprints A and B, for every pair of similar frames you compute the time offset between them and drop it in a histogram. If A and B genuinely share an intro, one offset bin lights up far above the noise — that’s the alignment where the intros overlap.</p><p>A few things make this robust in practice:</p><ul><li><strong>Magnitude gating.</strong> Only keep frames whose energy is above a percentile threshold, so you match on prominent audio features, not background hiss.</li><li><strong>Fuzzy frame matching.</strong> Exact frequency-bin equality is too brittle after re-encoding. Allowing a small bin tolerance recovers matches that a strict comparison would miss.</li><li><strong>Smoothed scoring.</strong> Slide one fingerprint against the other at the candidate offset and score frame by frame, with a smoothing window so a couple of noisy frames don’t fragment an otherwise clean match.</li><li><strong>Content-bleed correction.</strong> Sometimes the detected region spills past the real intro into regular content. A correction step pulls the boundary back to where the shared signal actually ends.</li></ul><h3>The bug that taught me the most</h3><p>Here’s a failure mode that’s easy to ship and easy to miss.</p><p>When you store a season fingerprint, you often store <em>several</em> intro patterns (variants happen — different openings, alternate recaps). When a new episode is matched, it gets compared against each stored pattern independently. Each comparison detects the same intro with slightly different boundaries.</p><p>The result: instead of one clean intro marker, one episode came back with <strong>20 overlapping markers</strong>, all covering roughly the same 68–87 second region.</p><p>The root cause was subtle. There <em>was</em> a deduplication step, but it keyed on exact (offset, duration) pairs. Twenty near-identical-but-not-equal matches all survived dedup because none of them were <em>exactly</em> equal.</p><p>The fix was a proper <strong>overlap merge</strong> after deduplication:</p><ul><li>Sort candidate segments by start time.</li><li>Walk them in order; if the next segment starts before the current one ends (plus a small gap tolerance), merge them.</li><li>The merged marker takes the earliest start, the latest end, and the highest confidence of the group.</li></ul><p>Twenty markers collapsed into one: start=68075ms, end=87050ms, confidence=0.985.</p><p>The lesson: <strong>deduplication and merging are different operations.</strong> Dedup removes exact repeats. Merge consolidates things that are <em>close enough to be the same</em>. If your domain has fuzzy boundaries, you almost always need both, and forgetting the merge produces output that’s technically correct per-comparison but useless downstream.</p><h3>A quieter lesson: episode 1 is a liar</h3><p>Fingerprint quality improved noticeably once I <strong>excluded episode 1</strong> from discovery. First episodes frequently have extended or modified intros, cold opens, or “previously on” segments that don’t represent the season’s normal opening. Including them dragged the shared pattern off. Dropping episode 1 (while still enforcing a minimum episode count for a reliable fingerprint) was a small change with an outsized quality payoff.</p><h3>Intro results</h3><p>On the evaluation set, intro detection landed at a <strong>mean IoU around 0.97</strong> and <strong>mean F1 around 0.98</strong>, with average start error in the low hundreds of milliseconds — well inside “feels instant” for a Skip Intro button. Series with clean, consistent openings hit effectively perfect alignment; the misses clustered in series with genuinely variable intros, which is exactly where you’d expect an audio-repetition method to struggle.</p><h3>Part 2 — End-credits via OCR</h3><h3>Why OCR</h3><p>Credits are text. The reliable signal is: <em>when does the screen start showing a lot of credit-like text?</em> So the pipeline downloads the <strong>last few minutes of video</strong> (video-only — we don’t need audio here) and reads frames with an OCR engine.</p><h3>Coarse-to-fine scanning</h3><p>Running OCR on every frame of a five-minute clip is wasteful. Instead:</p><ol><li><strong>Coarse scan.</strong> Sample frames at wide intervals. For each, run OCR and count how much text is present. A sliding window looks for the point where “lots of text” starts persisting — the candidate credits region.</li><li><strong>Fine scan.</strong> Around that candidate, sample at one-second intervals to pin the credit-start boundary to sub-second precision.</li></ol><p>This gets you accuracy where it matters (the boundary) without paying OCR cost everywhere.</p><h3>The masking trick</h3><p>Channel logos (“bugs”) sit in the corners and contain text that fools the detector. Masking the four corners of each frame before OCR removed a whole class of false positives. It’s a crude geometric trick and it worked well — a good reminder that a cheap heuristic beats a clever model when the signal is this structured.</p><h3>The tradeoff I couldn’t fully win</h3><p>This is the honest, interesting part. Credit detection lives on a knife-edge between two failure modes:</p><ul><li><strong>Threshold too high</strong> (say, require 20+ characters on screen): you miss credits that show only short strings — a single name, a one-word role like “Editor.” The sliding window never triggers and you report “no credits.”</li><li><strong>Threshold too low</strong> (say, 10 characters): you start catching <em>everything</em> — burned-in subtitles, on-screen signage, lower-third name graphics, a phone screen in a scene. False credit starts everywhere.</li></ul><p>There’s no single threshold that’s right for the whole catalog. The approaches that helped:</p><ul><li><strong>A credit-keyword dictionary.</strong> Words like “directed,” “producer,” “editor,” “starring,” “cinematography,” “composer.” If a low-character frame contains credit vocabulary, promote it; if a borderline frame has none, demote it. Microseconds to check, zero new dependencies, and it directly targets the ambiguous middle.</li><li><strong>Subtitle-zone masking.</strong> Extending the corner mask to also cover the bottom of the frame kills the single biggest false-positive source (captions). Real credits get detected higher in the frame anyway.</li><li><strong>Multiple-text-block reasoning.</strong> Credits tend to have several separated text regions spread vertically (names + roles). Captions are one or two lines at the bottom. Using text-block count and spatial spread as a second signal separates the two better than raw character count alone.</li></ul><p>I also added <strong>strict OCR failure thresholds</strong>. Under thread-pool saturation the OCR workers could silently time out and the scanner would quietly finish with “no credits found” — a <em>false</em> negative dressed up as a real one. Now, too many skipped frames or three consecutive OCR failures aborts the job with an explicit timeout error instead of a confident wrong answer. <strong>Failing loudly beats succeeding falsely.</strong></p><h3>Credit results</h3><p>Against ground truth, credit-start detection hit the boundary reliably (<strong>100% hit rate at IoU ≥ 0.5</strong> on the labeled subset, mean IoU around 0.86). End-to-end across the full set, roughly <strong>95% of episodes completed successfully</strong>; the rest split between low-confidence results (flagged, not silently wrong — usually short credits or credits-over-video) and a handful of genuinely unavailable media. Mean detection confidence sat around 0.66, which reflects how deliberately conservative the thresholds are.</p><h3>Part 3 — When heuristics aren’t enough: vision-language models</h3><p>Audio fingerprinting handles the <em>audio</em> of an intro, but it can’t tell you that the first few seconds are actually a <strong>network logo</strong> or a <strong>legal disclaimer</strong> rather than the intro proper. If “Skip Intro” includes three seconds of a logo animation, that’s a papercut.</p><p>So I ran a research spike: can a vision-language model (VLM) look at frames and classify them into <strong>logo / disclaimer / intro / content</strong>?</p><h3>Frame strips</h3><p>VLMs reason over images, not video. The trick was to build <strong>frame strips</strong>: sample the clip at ~1 fps, compose the frames into a grid, and <strong>burn a timestamp onto each frame</strong>. Now a single image gives the model both the visual content and the temporal reference it needs to say “intro starts here.”</p><h3>The model bake-off</h3><p>I evaluated seven configurations on a labeled set of strips. The tradeoff space was accuracy vs latency vs hardware cost:</p><ul><li>Small models were fast but weak — they confused production logos with intros.</li><li>A large general model was strong (~90% accuracy) but slow (minutes per strip).</li><li>The sweet spot was a mid-size model with <strong>speculative decoding (multi-token prediction)</strong> and reasoning enabled, with an automatic <strong>fallback</strong> to a faster no-reasoning mode for the occasional strip that blew its token budget. That combination held ~90% accuracy at tens of seconds per strip on a single mid-range GPU.</li></ul><p>A separate finding worth calling out: <strong>prompt tuning alone moved accuracy by a few points</strong> in the faster no-reasoning mode, narrowing the gap with the slow mode while staying more than twice as fast. Before reaching for a bigger model or more compute, rewrite the prompt and re-check your ground truth. Some of my early “model errors” were actually mislabeled ground truth.</p><h3>The residual error</h3><p>Even the best config had a ~10% error rate, concentrated in a predictable place: <strong>±2–3 second boundary over-detection at clip edges</strong>, and animated logos that genuinely look like intros. Knowing <em>where</em> the errors live matters more than the headline accuracy number — it tells you whether a cheap post-processing rule can clean them up, and whether the remaining errors are inside your downstream tolerance.</p><p>The complementary path I also explored was a <strong>visual logo fingerprint</strong>: match known network-logo frames directly so intro markers can be trimmed to exclude logo/disclaimer content. Visual matching as a refinement layer on top of the audio baseline, rather than a replacement for it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yzzHmNn1gyW7yYNd91vb2g.png" /></figure><h3>What I’d tell someone starting this</h3><ul><li><strong>Match the signal to the sub-problem.</strong> Audio for repetition, vision for text. Forcing one technique onto both halves is the first wrong turn.</li><li><strong>Dedup and merge are not the same thing.</strong> If your boundaries are fuzzy, you need both.</li><li><strong>Cheap heuristics punch above their weight</strong> when the signal is structured — corner masking and a keyword dictionary beat a lot of cleverness.</li><li><strong>Tune the prompt and fix the labels before you scale the model.</strong> Some of your “model errors” are your ground truth being wrong.</li><li><strong>Prefer a loud failure to a confident wrong answer.</strong> A flagged low-confidence result is useful; a false “no credits” is a landmine.</li></ul><p>The detectors were the fun part. The state machine, the publishing contract, and the recovery races were the part that actually decided whether any of it worked in production.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=914722c50d65" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>