r/vhsdecode • • 1h ago

Archival Advice DiscMaster — Optical Media Copy, Recovery & Processing Studio

2 Upvotes

An open-source desktop application (Linux/Windows) to migrate aging VCDs, .cda audio tracks and .bin/.cue images into more up-to-date container formats, such as MP4 and FLAC.

During the development process of the processing pipeline, I encountered some interesting technical challenges regarding the use of legacy optical media:

• Video/Audio Synchronization: The MPEG-1 streams in the older VCD .dat files have lost synchronization or contain damaged sectors due to scratches, and the standard FFmpeg conversion causes the loss of synchronization.

• Directly Reading Tracks from the Files: Reading tracks without relying on operating system-level support in the form of a virtual CD-drive from .bin/.cue images.

• Merging VCD Splits: Correct merging of multiple parts of VCD without re-encoding artifacts.

If anyone here is involved in lower-level media processing, using FFmpeg options or dealing with legacy file systems:

  1. What are your approaches to compensate for the drift of timestamps in damaged MPEG-1/VCD streams?
  2. Have you faced any rare disc formats or sector errors during archiving of old media?

r/vhsdecode • • 4d ago

First Decode! Decoding native NTSC tape with PAL60/NTSC 4.43 VCR?

7 Upvotes

Living in PAL-land, I've been wondering if I could use my regular VCR that supports NTSC 4.43 and PAL60 output to decode native NTSC tapes. Are there any downsides to this, particularly with the color signal (4.43 vs 3.58)?


r/vhsdecode • • 5d ago

Help Wanted! Digitizing Tapes

Thumbnail reddit.com
1 Upvotes

r/vhsdecode • • 7d ago

First Decode! Help with digital connectivity, where the error lies on my chain

Thumbnail reddit.com
1 Upvotes

r/vhsdecode • • 9d ago

Real-time playback with chroma-decoding

76 Upvotes

Just a quick update for tbc-tools v3.3.2 release as we now have full colour decoding and 25/29.97 rate locked playout which has been long wanted.

Also audio monitoring is now added, bringing it to more of an NLE like experience for making in/out cut placements.


r/vhsdecode • • 9d ago

Newbie / Need Help Will this rabbit hole net me tangible gains with my setup/use case?

3 Upvotes

Hi all, I have a bunch of old hi8 tapes I’ve wanted to properly digitize for years now. I only had access to my dads original old camcorder for the longest time, which was composite out only and buzzed out of the audio output. Recently I bought a Sony GV-D800 and it seems like it’s in good order, but it took me the longest time to get FireWire adapters for it (I was going to try the DV out on analog tapes to see how that was) and then suddenly Apple pulled FireWire out of Tahoe root and stem. I bought a Mac mini from 2011, and I’m just needing to put an SSD in and I’ll be ready to try to start digitizing.

But, a friend sent me this project a few months ago and I’ve been thinking about it since. I always wondered why the preview looked so much better than the encodes/captures, I figure it’s basically the raw feed this project is capturing but I have no soldering experience and it mostly seems to be VHS focused? (TBH, there are lots of old VHS tapes to digitize, but I don’t even have a deck for it).

Has anyone had great results with hi8? Is my player even a device I can “tap into” easily? Appreciate a gut check, I’ve stalled out not wanting to put dozens of hours of work I might just have to redo if this is the way to do it.


r/vhsdecode • • 8d ago

Help Wanted! HD630 - is it good for decoding native NTSC 3.58/French SECAM/PAL?

2 Upvotes

The Panasonic NV-HD630 - I'm aware it outputs NTSC as PAL60/4.43 but will it also be an issue for decoding, or does it not matter as it can still track native NTSC (3.58)?


r/vhsdecode • • 10d ago

Showcase! MISRC GUI V1.2.8 - The end of the audio DAW & WFM Scopes

Thumbnail
gallery
51 Upvotes

Coming in V1.2.8 MISRC GUI now will have

- Real-time decoders are now line-locked and field-locked

- Waveform Monitor & Vectorscope for live and post playback inspection of any file.

- Field / Frame level view enabled with spectrogram

- Split / Field view modes (now mirroring all the tbc-analyse view modes)

- File Marking for FLAC-Chop ready cleanup of dead start/end segments

- Base Implementation of IOS app & web app in server mode


r/vhsdecode • • 10d ago

First Decode! My first decodes+remasters - NHK Music Fantasy DREAMS Vol. 1 and 2 VHS-Decode Remasters (1993)

Thumbnail
youtu.be
22 Upvotes

Volume 2 Link

Hi everyone,

I've just uploaded my first set of VHS-Decode remasters to youtube which includes NHK's Music Fantasy DREAMS tapes volumes 1 and 2. These were CGI shorts produced by NHK to show during childrens programming, inspired by things like Fantasia, to get kids interested in classical music. Each volume contains 5 shorts, and there are 95 shorts in total. I currently have tapes 1-15, and have been keeping my eye out for the last few I don't have to complete this series. Some individual shorts from this series are online, but the vast majority aren't, and the ones that are are fairly low quality.

I've been collecting CGI material from Japan and the US (and a few other places) for a while now and I'm sitting on about over 70 hours of CGI works that mostly don't exist online. My goal has been not only to archive them and make them available to everyone online, but present them in as high quality and close to the original rendered quality as possible. And using VHS-Decode to do that.

Info about the decode parameters and my post-processing pipeline are included in the description for the videos. The main reason the youtube uploads are 4k is just to get the maximum bitrate out of youtube without it totally destroying the video quality.

Both videos are also available on archive in AV1 and H264 as 960p high bitrate remasters. I'm also currently uploading the FLACs and other related files to archive as their own separate entries (links on the archive pages). These are my preferred copies, since youtube loves to destroy everything you upload there.

Vol.1 on archive

Vol.2 on archive

I'm very happy with how these first ones came out although there are a few things I think I can improve for future uploads. I spent a lot of time repairing and tuning my VCR while doing my RF taps, but there are still a few small things that I think could be improved like some slight tracking noise on the lower 1/3rd that occasionally shows up.

If you're interested in this kind of CGI stuff please give me a follow on youtube or favorite on archive because I have a ton of tapes (and LD's too) that I'm going to be uploading over the next however long it takes me to get them done.

I'd love any feedback or comments or ways you think I could improve.

Thanks!


r/vhsdecode • • 12d ago

Help Wanted! Symphonic VCR 6460 issues

1 Upvotes

Hello! I just thrifted a symphonic VCR and I was trying to play a VHS tape, but it wouldn’t take the tape unless I pushed extra hard. I ended up putting a brand new VHS tape in and it seemed to set in and start playing but that only happened for 2 seconds before it just started flashing channel 2 and this glasses looking icon? Does anyone know what the issue could be?


r/vhsdecode • • 14d ago

Help Wanted! Not able to get the Rust GUI to start decoding

4 Upvotes

I’m wanting to try out the Rust GUI and for some reason, the decode won’t start. I’m not using any commands outside of the ones on the GUI and I’m not getting any errors so I don’t know what’s going on. Any help is appreciated.


r/vhsdecode • • 16d ago

Newbie --use_saved_levels` took my decode from 1,265 torn frames to 0 — full-tape A/B on identical RF

Post image
24 Upvotes

**Setup:** cxadc on a Conexant CX23880 (PCI), 28.636 MSPS 8-bit, NTSC VHS, SP.
Decoded with vhs-decode, exported with tbc-video-export (`--chroma-decoder ntsc3d`).

**The problem:** every scene with blown-out highlights — stage strobes, white
flashes — came out destroyed. Frames torn horizontally with the blanking band
shoved into the picture, plus rainbow chroma smeared over whole passages.

I spent a while blaming the tape, the deck, my RF path, my gain setting. None of
it. The default per-frame video-level re-measurement mis-reads on clipped
highlight frames and takes the demodulation down with it.

`--use_saved_levels` removes all of it.

vhs-decode's own help says:

> Try re-using video levels detected from the first decoded fields instead of
> re-calculating each frame. Will be done by default once well tested

So I tried to do the "well tested" part.

---

**Method:** one RF capture (13.1 GB, 7 min 37 s, 27,390 frames), decoded twice.
Only that flag differs. Same binary, same export, same analysis scripts, same
everything else.

**Results — full tape, every frame:**

metricdefault--use_saved_levels
torn frames1,265 / 27,3920 / 27,390
max band width in a frame67.97 %0.00 %
rainbow chroma, body of tape17 regions / 27.69 s0 / 0.00 s
rainbow chroma, tape end1 region / 17.68 s1 region / 17.65 s
dropouts298304

---

**Three controls, because "it looks fixed" is not evidence**

Something that merely kills chroma and smooths frames would also zero the first
three rows. So:

**1. The dropout count does not fall.** 298 → 304 (±2 %, same RF — that's decode
jitter). If the flag were hiding defects rather than fixing them, this number
would drop.

**2. The genuine damage survives.** All 17 rainbow regions in the body of the
tape vanish. The real damage at the physical end of the tape (439.5–457.1 s)
stays, essentially unchanged. Indiscriminate desaturation would have taken that
too.

**3. Normal picture brightness doesn't move.** Sampled at 1 fps across the whole
tape, excluding all-black and all-white frames (380 frames):

mean lumablack point (1 %)white point (99 %)first halfsecond half
default91.9361.000185.00088.99295.438
saved levels92.6981.000184.00090.40195.447
difference+0.7620.000−1.000+1.409+0.009

The difference **shrinks** over time. If the saved levels were drifting away
from reality, it would grow.

---

**Caveats, up front**

- **One tape, 7 min 37 s. No long-run test.** If a 2-hour tape ends up brighter
or darker at the end than at the start, this flag is the first thing I would
suspect. I standardised on it anyway, with that written down.
- I also use a parallel decode mode that splits the RF into segments decoded by
separate processes. There, `--use_saved_levels` fixes levels from the first
field **of each segment**, so boundaries could disagree. Untested. If anyone
has looked at this, I'd like to hear it.
- My automated QC passed the *broken* version on all 15 of its checks. It only
verifies that the file isn't corrupt, not that the picture isn't. I also
caught myself calling it "fixed" twice from numbers alone before a human
watched the whole thing end to end. That step isn't skippable.

---

**The question:** does anyone know of material where per-frame re-measurement is
actually the better choice? If not, this looks ready to be the default — the
help text already says that's the intent.

Happy to share the analysis scripts (torn-frame detector, chroma-region
detector) if they're useful to anyone.


r/vhsdecode • • 18d ago

Help Wanted! Anyone in the UK got one of those VHS Is Life mould cleaners and can help me revive some of my tapes?

2 Upvotes

I can't afford one of these mould cleaners myself, especially since once I've cleaned these tapes it will just be sitting around.

If anyone here has a business that uses that cleaner to restore mouldy tapes then I'd be a very willing customer. I have around 20 tapes that have slight to medium levels of mould. Most of them just a few specs. Let me know and we can work things out. I live in London if you'd rather have me drop them off and pick them up.

Reddit recommended I repost here


r/vhsdecode • • 21d ago

Showcase! MISRC GUI - Interest for IOS support?

10 Upvotes

r/vhsdecode • • 23d ago

Newbie / Need Help George Blood or DT Heritage better? Or another organization you recommend?

5 Upvotes

I am looking to get some tapes (VHS tapes and mini cassettes) digitized professionally, and narrowed down to these 2 choices, and am wondering if anyone has any insight between these 2 choices (or is there another choice that you recommend that I am not aware of):

George Blood LP
Widely regarded as the leading technical expert in the academic and library archive world, George Blood LP (https://georgeblood.com/)handles massive, high-volume, and extremely rare institutional projects. Their specialized expertise is so deeply trusted that the Library of Congress (https://www.loc.gov/) commissioned them to author the definitive best-practices guidelines for video preservation.

However, there is a different company DT Heritage (heritage-digital transitions.com) that says on its website:

“Our equipment is designed for ergonomics, ease of use, and speed, and it exceeds national and international image quality standards.”

And:

“We can digitize anything at a level of detail you can’t get anywhere else.”

So between these 2 organizations, it is very difficult to tell, and as a commoner with no industry experience or insider knowledge I have no way else to tell.


r/vhsdecode • • 28d ago

Help Wanted! Tape-decode v4.0.1 not working.

2 Upvotes

I'm fairly new to all this, but so far I have been able to reliably decode using VHS decode. I thought I would try Tape-decode v4.0.1, and while it runs, and I can select the file for decoding along with selecting the appropriate options, nothing happens when I click on 'Launch selected tool'. I'm probably doing something wrong as I couldn't find any installation instructions, though I assume they are not needed as it is an appicon.

I'm using Debian Trixie. Tape decode was downloaded from here: https://github.com/harrypm/tape-decode-rust-gui/releases/tag/v4.0.1


r/vhsdecode • • 29d ago

Newbie The Rewind Hour

Thumbnail
youtube.com
1 Upvotes

r/vhsdecode • • Oct 28 '26

Setup & Workflow CXcard + clockgen question - Is the clockgen involved in capture initiation?

4 Upvotes

So I have recently acquired an old PCI card with 3x CX23880 chips and a PCI multiplexer chip. All run off one crystal, and all can be seen in Linux and spun up in OBS using the standard driver (haven't built cxadc yet). I think I just need to modify the front end and bypass some channel selector circuitry.

For separate CX cards, I understand what the point of the clockgen mod is: Provide a common clock to all cards so that the sample rates are locked at a sample level.

My question is:

At the beginning of a capture, is the clockgen mod involved at all?

Like, does the clockgen mod simply provide a controlled clock signal that can fanned out and adjusted? Or is it more sophisticated?

I imagine cxadc could initialize both CX cards and then the clockgen could start the clock to ensure sample #1 of both streams are taken on the same clock edge.

So far, they way I have found to initiate simultaneous capture is to start two instances of cat via cat /dev/cxadc0 |pv > CX_Card_28msps_8-bit.u8 , or use MISRC Capture, however it handles it. But running two separate commands to two separate devices will inevitably introduce some latency between them.

So yeah, I guess a secondary question is:

If you have 2+ CX cards with a shared clock source that is *not* the clockgen mod: Whats the best way of initiating a multi-channel capture?

Sample perfect start is not nessesarilly required for HiFi VHS capture, but it would be usefull for capturing transfer functions of emphasis circuits etc (I recently blew up my 2ch NI scope card 😔)


r/vhsdecode • • Oct 28 '26

First Decode! My first decodes

7 Upvotes

While I'm still waiting on parts to arrive for the RF buffer amps and the clockgen mod, I decided to try my first RF decode. I swapped the stock 28.6 MHz crystal in the CX card with a 40 MHz one. As all my crystals are overtone types, I did a small temporary hack to force it to oscillate at the correct frequency. For the buffer amps, I used a small wideband amplifier module I had lying around.

As I have a large collection of test pattern generators, I chose to use test patterns for my tests. These were recorded on a JVC HR-S5700AM VCR. Playback was on the same VCR. Test patterns I used were the Philips PM5544, and a 5.5 MHz monochrome sweep.

VHS

Results look pretty good, though the colour looks a bit grotty compared to how it looks on the VCR's output. Bandwidth peters out a bit above 3MHz, which is to be expected, and which compares well with the VCR's own output as shown below.

Sweep from VCR video output.

I tried the same patterns using S-VHS:

S-VHS

Colour was still grotty, but the luminance was nice and clean, though very much lacking in bandwidth compared to the VCR's own video output as shown here:

Sweep from VCR's output.

I had to double check that I hadn't mistakenly used the VHS sweep image instead of the S-VHS one when I was compiling my comparison images, they look so similar. I don't know why I'm getting such poor bandwidth. Could it be my RF buffer amp? or an incorrect software setting in MISRC gui, VHS decode, or TBC-tools? It seems there is a filter that is optimised for VHS and not S-VHS.

Any suggestions?


r/vhsdecode • • Oct 27 '26

Help Wanted! MIRSC 1.5a amplifier question

4 Upvotes

A few months ago a posted about my clockgen setup and made a bit of progress before I saw a batch of the MIRSC 1.5a up on the ko-fi store

My question: As Ive read, all the methods run best with an amplifier setup, but for the MIRSC it’s not required to get serviceable results right? I’m so eager to jump in especially with the GUI options

I’m at a point where I’d rather run the MIRSC setup for ease of use (rather, I haven’t found the time to fix my clockgen mods after I broke my first set of CX cards)

My budget is pretty strung out due to poor planning and lack of full commitment to clockgen vs MIRSC so I’d love to not order anything more and get a real “first pass” of VHSdecode tape archives. I have my set of USB converter archives but I’d rather clean those out for a minimum-viable-setup output, without spending anything more, if possible.

P.S. I know the MIRSC batches are only 5 at a time and fully tested but was wondering if anyone that ordered the recent batch got theirs yet? I ordered mine without an account so I figured I’m not gonna know until it’s in the post. Thanks all!


r/vhsdecode • • Oct 27 '26

RF Tap Does anyone know if the Sony CCD-TRV67E has a tapping point? found one for cheap but unsure if i can tap into it.

Post image
7 Upvotes

r/vhsdecode • • Oct 27 '26

Archival Advice Staxrip post processing - Seeking input

0 Upvotes

I'm working on restoring some animated footage captured from LaserDisc, and the goal is to clean up the analogue video artefacts without turning the image into a blurry, overprocessed mess. I captured with the DdD via a Pioneeer CLD-V2600 and ran through LD decode. The LD content was sourced from a tape master. Telecined as it was intended for NTSC broadcasts and was produced as such.

The biggest problem is the bead-like texture across otherwise flat areas of the image. Large patches of blue sky, grey metal, dark shadows and painted backgrounds can have a distracting pattern of tiny light and dark fluctuations. In some areas, it looks like little beads or dots. In others, it forms repeating ridges, stripes or a herringbone-like pattern. The texture also isn't always consistent across the picture, so one section of a flat colour can look rougher than another.

I'm also dealing with chroma broiling, where colour fluctuates or crawls within areas that should be relatively stable. This can make solid colours look blotchy or speckled, with apparent changes in hue and saturation from frame to frame. The aim is to stabilize the colour without bleeding it across edges or damaging the original cel shading.

Other problems include:

  • RF and carrier interference: Repeating ripples, stripes and structured patterns overlaid on the image, especially noticeable in large, relatively uniform colour fields.
  • Dot crawl and cross-colour interference: Dotted patterns, crawling edges and false colours around fine lines and high-contrast details.
  • Rainbowing and chroma-phase noise: Unwanted coloured fringes or streaks near edges, along with smaller fluctuations in the colour channels.
  • Ringing, halos and analogue echoes: Bright or dark bands around high-contrast edges, or trails extending from bright objects and lettering.
  • Isolated dropouts and scanline defects: Small white or black anomalies that can appear as short horizontal marks or abrupt changes in brightness.
  • Banding: Visible tonal steps in gradients, particularly in skies and other smooth backgrounds.
  • Frame jitter and cadence issues: Unwanted image movement or incorrect frame matching that needs to be addressed separately from the noise.

The real challenge is that the defects overlap with the actual artwork's fine detail. A one-pixel ink line, a tiny star, a highlight or a subtle painted texture can occupy the same spatial frequencies as the interference. A filter that simply averages neighbouring pixels may reduce the noise, but it can also erase the very detail I'm trying to preserve.

My restoration pipeline therefore separates the work into several categories. Chroma denoising targets colour fluctuations, edge-aware spatial filtering targets repeating surface patterns, temporal denoising uses information from neighbouring frames, and separate filters address halos, echoes, dropouts and banding. I'm also experimenting with masks that protect actual ink lines and pinpoint stars from being mistaken for noise.

What I don't want is a completely smooth, plastic-looking image. Nor do I want to cover up the problem by adding synthetic grain. The aim is to remove the distracting structured interference, make the remaining texture consistent, stabilize the colours, and retain as much of the original animation detail as possible.

Some of the visible patterns may have multiple causes, so I can't assume every bead or ripple comes from one specific LaserDisc mechanism just by looking at a still frame. But the practical objective remains the same: clean up the transfer while preserving the artwork, rather than cleaning the image so aggressively that the original detail disappears.

This is the VS script I've cooked up in StaxRip. Would like to get advice on things I could change, tweak, or add.

import havsfunc

import muvsfunc

# StaxRip supplies vs and core.

# ========================================================================

# STAXRIP LASERDISC RESTORATION (VAPOURSYNTH 10-BIT)

# Conservative luma correction, stronger chroma-boil suppression,

# corrected zero-moat line/star mask, and no synthetic grain for comparison.

# ========================================================================

# GENERAL RESTORATION SETTINGS

DOTKILL_ITERATIONS = 3

CHECKMATE_THR = 12

CHECKMATE_MAX = 12

RAIN_THRESHOLD = 10

RAIN_SOFTEN = 6

CHROMA_PHASE_THR = 8

CHROMA_SHIFT_H = 0.5

CHROMA_SHIFT_V = 0.0

DROPOUT_DIFF_THR = 26

DROPOUT_TEMPORAL_TOL = 10

STABILIZE_JITTER = True

STAB_DXMAX = 3

STAB_DYMAX = 3

STAB_CUTOFF = 3.0

STAB_DAMPING = 1.0

DEHALO_RX = 1.5

DEHALO_RY = 1.5

DEHALO_DARKSTR = 0.00

DEHALO_BRIGHTSTR = 0.15

TEXT_DEHALO_RX = 2.5

TEXT_DEHALO_RY = 2.5

TEXT_DEHALO_DARKSTR = 0.00

TEXT_DEHALO_BRIGHTSTR = 1.30

CROP_LEFT = 4

CROP_RIGHT = 24

CROP_TOP = 4

CROP_BOTTOM = 4

# ========================================================================

# LINE & STAR MASK SETTINGS

# ========================================================================

LINE_CORE_LOW = 7.0

LINE_CORE_SPAN = 8.0

STAR_MAX_BG_LUMA = 85

STAR_MIN_DELTA = 10

# ========================================================================

# SURFACE-CLEANER SETTINGS

# ========================================================================

SURFACE_V_THR = 12

SURFACE_H_THR = 20

BEAD_MEDIAN_LIMIT = 3

# ========================================================================

# CHROMA AND LUMA DENOISING

# ========================================================================

CHROMA_DENOISE_TR = 3

CHROMA_DENOISE_THSAD = 420

CHROMA_DENOISE_THSADC = 580

CHROMA_DENOISE_LIMIT = 20

# Restored to the original spatial u/V correction strength.

CHROMA_SPATIAL_LIMIT = 4

LUMA_DENOISE_TR = 2

LUMA_DENOISE_THSAD = 240

# Kept conservative to avoid bringing back the previous luma blur.

LUMA_DENOISE_LIMIT = 3

# Mild debanding, with no grain generated by f3kdb.

DEBAND_RANGE = 10

DEBAND_Y = 12

DEBAND_CB = 12

DEBAND_CR = 12

# Disabled while evaluating the actual denoising and broiling suppression.

# The function remains available, but it will not add changing noise.

UNIFORM_GRAIN_VAR = 0.0

# ========================================================================

# CHROMA BLEED AND TEXT ECHO

# ========================================================================

CHROMA_WARP_DEPTH = 4

CHROMA_WARP_THRESH = 140

CHROMA_WARP_BLUR = 3

CHROMA_WARP_LIMIT = 8

TEXT_ECHO_TEXT_MIN = 185

TEXT_ECHO_REACH = 16

TEXT_ECHO_KEEP = 1

TEXT_ECHO_NEUTRAL_TOL = 24

TEXT_ECHO_REFERENCE_RADIUS = 4

TEXT_ECHO_ACTIVITY = 3

TEXT_ECHO_MAX_CHANGE = 12

TEXT_ECHO_STRENGTH = 0.70

# ========================================================================

# HELPER FUNCTIONS

# ========================================================================

def LD_ShiftRight(c, px):

return c if px <= 0 else core.resize.Point(c, src_left=-px)

def LD_ShiftLeft(c, px):

return c if px <= 0 else core.resize.Point(c, src_left=px)

def LD_ShiftDown(c, px):

return c if px <= 0 else core.resize.Point(c, src_top=-px)

def LD_ShiftUp(c, px):

return c if px <= 0 else core.resize.Point(c, src_top=px)

def LD_BoxH2(c):

return core.std.BoxBlur(c, hradius=2, vradius=0)

def LD_BoxH3(c):

return core.std.BoxBlur(c, hradius=3, vradius=0)

def LD_Box3x3(c):

return core.std.BoxBlur(c, hradius=1, vradius=1)

def LD_Blur3(c):

return core.std.Convolution(

c, matrix=[1, 2, 1, 2, 4, 2, 1, 2, 1]

)

def LD_VerticalProfile48(c):

return core.std.BoxBlur(c, hradius=0, vradius=12, vpasses=4)

def LD_PrevFrame(c):

return c[0] + c[:-1] if c.num_frames > 1 else c

def LD_NextFrame(c):

return c[1:] + c[-1] if c.num_frames > 1 else c

def LD_LocalDetailMaskY(y, threshold_8bit):

bits = y.format.bits_per_sample

scale = (1 << (bits - 8)) if bits > 8 else 1

max_val = (1 << bits) - 1

thr = threshold_8bit * scale

l1 = LD_ShiftRight(y, 1)

r1 = LD_ShiftLeft(y, 1)

u1 = LD_ShiftUp(y, 1)

d1 = LD_ShiftDown(y, 1)

detail = core.std.Expr(

[l1, r1, u1, d1],

f"x y - abs z a - abs max {thr} > {max_val} 0 ?"

)

detail = LD_Box3x3(detail)

return core.std.Expr(

[detail], f"x 0 > {max_val} 0 ?"

)

# ========================================================================

# ORTHOGONAL ZERO-MOAT LINEWORK & STAR KEEPOUT MASK

# ========================================================================

def LD_CleanLineAndStarMask(clp):

bits = clp.format.bits_per_sample

scale = (1 << (bits - 8)) if bits > 8 else 1

max_val = (1 << bits) - 1

y = core.std.ShufflePlanes(clp, 0, vs.GRAY)

# These are guides used only for mask construction. They are not

# substituted into the restored video.

y_vsmooth = core.std.Convolution(

y, matrix=[1, 2, 1], mode="v"

)

y_hsmooth = core.std.Convolution(

y, matrix=[1, 2, 4, 2, 1], mode="h"

)

l1 = LD_ShiftRight(y_vsmooth, 1)

r1 = LD_ShiftLeft(y_vsmooth, 1)

l2 = LD_ShiftRight(y_vsmooth, 2)

r2 = LD_ShiftLeft(y_vsmooth, 2)

u1 = LD_ShiftUp(y_hsmooth, 1)

d1 = LD_ShiftDown(y_hsmooth, 1)

u2 = LD_ShiftUp(y_hsmooth, 2)

d2 = LD_ShiftDown(y_hsmooth, 2)

# Core metric:

# max(min(abs(center-left1), abs(center-right1)),

# min(abs(center-left2), abs(center-right2)))

#

# A flat pixel beside a line has a large difference on only one side,

# so the min operation suppresses the unwanted protection moat.

expr_metric_1d = (

"x y - abs "

"x z - abs min "

"x a - abs "

"x b - abs min "

"max"

)

metric_h = core.std.Expr(

[y_vsmooth, l1, r1, l2, r2],

expr_metric_1d

)

metric_v = core.std.Expr(

[y_hsmooth, u1, d1, u2, d2],

expr_metric_1d

)

# Bright pinpoint stars in dark or mid-dark backgrounds.

star_bg_max = STAR_MAX_BG_LUMA * scale

star_delta = STAR_MIN_DELTA * scale

metric_star = core.std.Expr(

[y, y_vsmooth, y_hsmooth],

f"y z + 0.5 * {star_bg_max} <= "

f"x y z + 0.5 * - {star_delta} >= and "

f"{max_val} 0 ?"

)

lo_thr = LINE_CORE_LOW * scale

span_thr = LINE_CORE_SPAN * scale

line_mask = core.std.Expr(

[metric_h, metric_v],

f"x y max {lo_thr} - {span_thr} / "

f"0 max 1 min {max_val} *"

)

# Combine the actual line-core mask with the pinpoint-star mask.

return core.std.Expr(

[line_mask, metric_star],

"x y max"

)

# ========================================================================

# STAGE 1: CROSS-COLOUR CLEANUP & FILM CADENCE RECOVERY

# ========================================================================

def LD_CrossColorCleanUV(

clp, thr_8bit=12, max_8bit=12, iterations=3

):

bits = clp.format.bits_per_sample

scale = (1 << (bits - 8)) if bits > 8 else 1

thr = thr_8bit * scale

lim = max_8bit * scale

y = core.std.ShufflePlanes(clp, 0, vs.GRAY)

u = core.std.ShufflePlanes(clp, 1, vs.GRAY)

v = core.std.ShufflePlanes(clp, 2, vs.GRAY)

def _clean_chroma(p):

cur = p

for _ in range(iterations):

u1 = LD_ShiftUp(cur, 1)

d1 = LD_ShiftDown(cur, 1)

l1 = LD_ShiftRight(cur, 1)

r1 = LD_ShiftLeft(cur, 1)

notch = core.std.Expr(

[cur, u1, d1, l1, r1],

"x 4 * y + z + a + b + 8 /"

)

cur = core.std.Expr(

[cur, notch],

f"x y - abs {thr} <= "

f"y x - -{lim} max {lim} min x + x ?"

)

return cur

return core.std.ShufflePlanes(

[y, _clean_chroma(u), _clean_chroma(v)],

[0, 0, 0], vs.YUV

)

def LD_FilmCadenceRecovery(clp):

source10 = core.std.SetFieldBased(clp, 1)

source8 = core.resize.Point(

source10,

format=source10.format.replace(bits_per_sample=8)

)

if hasattr(core, "tivtc"):

matched10 = core.tivtc.TFM(

source8, order=0, field=0, mode=5, PP=6,

cthresh=9, MI=80, slow=2,

mChroma=True, chroma=False, micmatching=2,

clip2=source10

)

else:

matched10 = core.vivtc.VFM(

source8, order=0, field=0, mode=5,

cthresh=9, mi=80, mchroma=True,

chroma=False, clip2=source10

)

matched10 = core.std.SetFieldBased(matched10, 0)

matched_corrected10 = LD_CrossColorCleanUV(

matched10,

thr_8bit=CHECKMATE_THR,

max_8bit=CHECKMATE_MAX,

iterations=DOTKILL_ITERATIONS

)

metrics8 = core.resize.Point(

matched_corrected10,

format=source8.format

)

if hasattr(core, "tivtc"):

decimated10 = core.tivtc.TDecimate(

metrics8, mode=0, cycle=5, cycleR=1,

hybrid=0, chroma=False, noblend=True,

clip2=matched_corrected10

)

else:

decimated10 = core.vivtc.VDecimate(

metrics8, cycle=5, chroma=False,

clip2=matched_corrected10

)

return core.std.SetFieldBased(decimated10, 0)

# ========================================================================

# STAGE 1A: GLOBAL JITTER STABILIZATION

# ========================================================================

def LD_StabilizeJitter(clp):

if not STABILIZE_JITTER or not hasattr(core, "depan"):

return clp

try:

anal8 = core.resize.Point(

core.std.ShufflePlanes(clp, 0, vs.GRAY),

format=vs.GRAY8,

dither_type="ordered"

)

anal8 = LD_Blur3(anal8)

stab_data = core.depan.DePanEstimate(

anal8, range=1, trust=4.0,

dxmax=STAB_DXMAX, dymax=STAB_DYMAX,

zoommax=1.0, stab=1.0, pixaspect=1.0

)

return core.depan.DePanStabilize(

clp, data=stab_data,

cutoff=STAB_CUTOFF, damping=STAB_DAMPING,

initzoom=1.0, addzoom=False,

prev=0, next=0, mirror=15, blur=0,

dxmax=STAB_DXMAX, dymax=STAB_DYMAX,

zoommax=1.0, rotmax=0.0, subpixel=0,

pixaspect=1.0, fitlast=0, tzoom=3.0,

method=0

)

except Exception:

# Preserve the source if DePan's estimator fails.

return clp

# ========================================================================

# STAGE 2: SINGLE-FIELD RF DROPOUT REPAIR

# ========================================================================

def LD_RepairFieldDropouts(

clp, diff_thr_8bit=26, temp_tol_8bit=10

):

bits = clp.format.bits_per_sample

scale = (1 << (bits - 8)) if bits > 8 else 1

d_thr = diff_thr_8bit * scale

t_tol = temp_tol_8bit * scale

y = core.std.ShufflePlanes(clp, 0, vs.GRAY)

if y.num_frames < 3:

return clp

u1 = LD_ShiftUp(y, 1)

d1 = LD_ShiftDown(y, 1)

v_avg = core.std.Expr([u1, d1], "x y + 0.5 *")

v_agree = core.std.Expr([u1, d1], "x y - abs")

prv = LD_PrevFrame(y)

nxt = LD_NextFrame(y)

t_avg = core.std.Expr([prv, nxt], "x y + 0.5 *")

t_agree = core.std.Expr([prv, nxt], "x y - abs")

repaired_y = core.std.Expr(

[y, v_avg, t_avg, v_agree, t_agree],

f"x y - abs {d_thr} >= "

f"x z - abs {d_thr} >= and "

f"a {t_tol * 2} <= b {t_tol} <= and and "

f"y z + 0.5 * x ?"

)

return core.std.ShufflePlanes(

[repaired_y, clp], [0, 1, 2], vs.YUV

)

# ========================================================================

# STAGE 3: RAINBOW CLEANUP, CHROMA PHASE AND CHROMA DELAY

# ========================================================================

def LD_RainbowAndPhaseCleanUV(

clp, th_8bit=10, sft_8bit=6, phase_thr_8bit=8

):

bits = clp.format.bits_per_sample

scale = (1 << (bits - 8)) if bits > 8 else 1

max_val = (1 << bits) - 1

th = th_8bit * scale

lim = sft_8bit * scale

p_thr = phase_thr_8bit * scale

y = core.std.ShufflePlanes(clp, 0, vs.GRAY)

u = core.std.ShufflePlanes(clp, 1, vs.GRAY)

v = core.std.ShufflePlanes(clp, 2, vs.GRAY)

y_uv = (

core.resize.Bilinear(y, width=u.width, height=u.height)

if (u.width != y.width or u.height != y.height)

else y

)

yl1 = LD_ShiftRight(y_uv, 1)

yr1 = LD_ShiftLeft(y_uv, 1)

yu1 = LD_ShiftUp(y_uv, 1)

yd1 = LD_ShiftDown(y_uv, 1)

edge_gate = core.std.Expr(

[yl1, yr1, yu1, yd1],

f"x y - abs z a - abs max {12 * scale} >= {max_val} 0 ?"

)

flat_gate = core.std.Expr(

[yl1, yr1, yu1, yd1],

f"x y - abs z a - abs max {14 * scale} <= {max_val} 0 ?"

)

def _clean_plane(p):

u1 = LD_ShiftUp(p, 1)

d1 = LD_ShiftDown(p, 1)

u2 = LD_ShiftUp(p, 2)

d2 = LD_ShiftDown(p, 2)

l2 = LD_ShiftRight(p, 2)

r2 = LD_ShiftLeft(p, 2)

v_blur = core.std.Expr(

[p, u1, d1],

"x 2 * y + z + 4 /"

)

# Spatial edge-gated chroma reduction.

rain_mask = LD_Blur3(

core.std.Expr(

[p, u1, d1, edge_gate],

f"x y z + 0.5 * - abs {th} >= "

f"a 0 > and {max_val} 0 ?"

)

)

p_derain = core.std.MaskedMerge(

p,

core.std.Expr(

[p, v_blur],

f"y x - -{lim} max {lim} min x +"

),

rain_mask

)

# Flat-field chroma phase stabilizer.

phase_smooth = core.std.Expr(

[p_derain, u1, d1, u2, d2, l2, r2],

f"x 2 * "

f"x y - abs {p_thr} <= y x ? + "

f"x z - abs {p_thr} <= z x ? + "

f"x a - abs {p_thr} <= a x ? + "

f"x b - abs {p_thr} <= b x ? + "

f"x c - abs {p_thr} <= c x ? + "

f"x d - abs {p_thr} <= d x ? + 8 /"

)

return core.std.MaskedMerge(

p_derain, phase_smooth, flat_gate

)

return core.std.ShufflePlanes(

[y, _clean_plane(u), _clean_plane(v)],

[0, 0, 0], vs.YUV

)

def FixChromaShift(clp, h_shift=0.5, v_shift=0.0):

if h_shift == 0.0 and v_shift == 0.0:

return clp

y = core.std.ShufflePlanes(clp, 0, vs.GRAY)

u = core.std.ShufflePlanes(clp, 1, vs.GRAY)

v = core.std.ShufflePlanes(clp, 2, vs.GRAY)

u_shift = core.resize.Bilinear(

u, src_left=h_shift, src_top=v_shift

)

v_shift = core.resize.Bilinear(

v, src_left=h_shift, src_top=v_shift

)

return core.std.ShufflePlanes(

[y, u_shift, v_shift],

[0, 0, 0], vs.YUV

)

# ========================================================================

# STAGE 4: LEFT-EDGE DEFECT REPAIR

# ========================================================================

def LD_LeftEdgeDefectRepair(clp):

bits = clp.format.bits_per_sample

scale = (1 << (bits - 8)) if bits > 8 else 1

max_val = (1 << bits) - 1

zone = core.std.Crop(

clp, left=0, right=clp.width - 40,

top=0, bottom=0

)

rest = core.std.Crop(

clp, left=40, right=0, top=0, bottom=0

)

zy = core.std.ShufflePlanes(zone, 0, vs.GRAY)

zu = core.std.ShufflePlanes(zone, 1, vs.GRAY)

zv = core.std.ShufflePlanes(zone, 2, vs.GRAY)

zy_prof = LD_VerticalProfile48(zy)

zu_prof = LD_VerticalProfile48(zu)

zv_prof = LD_VerticalProfile48(zv)

mask_y = LD_BoxH3(

core.std.AddBorders(

core.std.BlankClip(

zy, width=28, height=zy.height, color=max_val

),

left=0, right=12, top=0, bottom=0, color=0

)

)

uv_active_w = int(round(28 * zu.width / 40.0))

mask_uv = LD_BoxH2(

core.std.AddBorders(

core.std.BlankClip(

zu, width=uv_active_w, height=zu.height,

color=max_val

),

left=0, right=zu.width - uv_active_w,

top=0, bottom=0, color=0

)

)

zy_corr = core.std.Expr(

[zy, LD_BoxH3(zy_prof), zy_prof],

f"x y z - {5 * scale} min -{5 * scale} max +"

)

zu_corr = core.std.Expr(

[zu, LD_BoxH2(zu_prof), zu_prof],

f"x y z - {4 * scale} min -{4 * scale} max +"

)

zv_corr = core.std.Expr(

[zv, LD_BoxH2(zv_prof), zv_prof],

f"x y z - {4 * scale} min -{4 * scale} max +"

)

zone_fixed = core.std.ShufflePlanes(

[

core.std.MaskedMerge(zy, zy_corr, mask_y),

core.std.MaskedMerge(zu, zu_corr, mask_uv),

core.std.MaskedMerge(zv, zv_corr, mask_uv)

],

[0, 0, 0], vs.YUV

)

return core.std.StackHorizontal([zone_fixed, rest])

# ========================================================================

# STAGE 5: EDGE-GATED RESIDUAL SURFACE CORRECTION

# ========================================================================

def LD_UniformSurfaceClean(clp, protect_mask):

"""

One bounded residual correction, not successive spatial blur passes.

Builds a horizontally edge-gated reference using samples five pixels

apart, computes the source residual, estimates a robust local residual

correction, and limits the change to BEAD_MEDIAN_LIMIT on the 8-bit scale.

The full-resolution line/star mask prevents correction of detected cores.

"""

bits = clp.format.bits_per_sample

scale = (1 << (bits - 8)) if bits > 8 else 1

max_val = (1 << bits) - 1

mid = 1 << (bits - 1)

y = core.std.ShufflePlanes(clp, 0, vs.GRAY)

h_thr = SURFACE_H_THR * scale

v_thr = SURFACE_V_THR * scale

change_limit = BEAD_MEDIAN_LIMIT * scale

left5 = LD_ShiftRight(y, 5)

right5 = LD_ShiftLeft(y, 5)

# Use distant samples only when they remain inside a similar luma region.

left5_safe = core.std.Expr(

[y, left5],

f"x y - abs {h_thr} <= y x ?"

)

right5_safe = core.std.Expr(

[y, right5],

f"x y - abs {h_thr} <= y x ?"

)

horizontal_reference = core.std.Expr(

[left5_safe, y, right5_safe],

"x y + z + 3 /"

)

# Residual encoded around the neutral midpoint.

diff = core.std.Expr(

[y, horizontal_reference],

f"x y - {mid} +"

)

# The centre residual difference is zero, represented by the midpoint.

diff_center = core.std.Expr([diff], f"{mid}")

# Residual differences to the two distant horizontal samples.

diff_left = core.std.Expr(

[diff, LD_ShiftRight(diff, 5)],

f"x y - {mid} +"

)

diff_right = core.std.Expr(

[diff, LD_ShiftLeft(diff, 5)],

f"x y - {mid} +"

)

# Soft-limit residual differences rather than smoothing pixels repeatedly.

k = 4.898979485566356 * scale

soft_map_expr = (

f"x {mid} - "

f"x {mid} - abs {scale} + {k:.12f} + / "

f"{k:.12f} * {mid} +"

)

mapped_center = core.std.Expr(

[diff_center], soft_map_expr

)

mapped_left = core.std.Expr(

[diff_left], soft_map_expr

)

mapped_right = core.std.Expr(

[diff_right], soft_map_expr

)

# Median of three residual-difference estimates.

median_diff = core.std.Expr(

[mapped_center, mapped_left, mapped_right],

"x y min x y max z min max"

)

reconstructed_diff = core.std.Expr(

[diff, median_diff],

f"x y - {mid} +"

)

candidate = core.std.Expr(

[horizontal_reference, reconstructed_diff],

f"x y + {mid} -"

)

# Explicitly cap the correction at three 8-bit levels.

limited_candidate = core.std.Expr(

[y, candidate],

f"x y x - -{change_limit} max {change_limit} min +"

)

up1 = LD_ShiftUp(y, 1)

down1 = LD_ShiftDown(y, 1)

vertical_flat = core.std.Expr(

[up1, down1],

f"x y - abs {v_thr} <= {max_val} 0 ?"

)

# MaskedMerge expects zero to preserve the source and full scale to

# select the candidate. Reject the line/star cores and non-flat regions.

apply_mask = core.std.Expr(

[protect_mask, vertical_flat],

f"{max_val} x - y * {max_val} /"

)

y_out = core.std.MaskedMerge(

y, limited_candidate, apply_mask

)

return core.std.ShufflePlanes(

[y_out, clp], [0, 1, 2], vs.YUV

)

# ========================================================================

# STAGE 6: FULL-SPECTRUM CHROMA AND LUMA DENOISING

# ========================================================================

def LD_GradeNoiseReduction(clp, protect_mask):

bits = clp.format.bits_per_sample

scale = (1 << (bits - 8)) if bits > 8 else 1

max_val = (1 << bits) - 1

c_lim = CHROMA_SPATIAL_LIMIT * scale

# Pass 1: multi-frame chroma suppression.

# This is the main temporal control for chroma broiling.

chroma_clean = havsfunc.SMDegrain(

clp,

tr=CHROMA_DENOISE_TR,

thSAD=CHROMA_DENOISE_THSAD,

thSADC=CHROMA_DENOISE_THSADC,

prefilter=2,

contrasharp=False,

RefineMotion=True,

plane=3,

chroma=True,

limit=255,

limitc=CHROMA_DENOISE_LIMIT

)

y = core.std.ShufflePlanes(clp, 0, vs.GRAY)

u_t = core.std.ShufflePlanes(chroma_clean, 1, vs.GRAY)

v_t = core.std.ShufflePlanes(chroma_clean, 2, vs.GRAY)

# Bring the luma protection mask to the chroma-plane resolution.

protect_uv = (

core.resize.Bilinear(

protect_mask,

width=u_t.width,

height=u_t.height

)

if (u_t.width != protect_mask.width or

u_t.height != protect_mask.height)

else protect_mask

)

flat_uv_mask = core.std.Expr(

[protect_uv], f"{max_val} x -"

)

# Restored spatial chroma cleanup:

# radius 2 and two passes per axis, on u/V only.

u_spatial = core.std.BoxBlur(

u_t,

hradius=2, hpasses=2,

vradius=2, vpasses=2

)

v_spatial = core.std.BoxBlur(

v_t,

hradius=2, hpasses=2,

vradius=2, vpasses=2

)

u_candidate = core.std.Expr(

[u_t, u_spatial],

f"x y x - -{c_lim} max {c_lim} min +"

)

v_candidate = core.std.Expr(

[v_t, v_spatial],

f"x y x - -{c_lim} max {c_lim} min +"

)

u_out = core.std.MaskedMerge(

u_t, u_candidate, flat_uv_mask

)

v_out = core.std.MaskedMerge(

v_t, v_candidate, flat_uv_mask

)

chroma_fixed = core.std.ShufflePlanes(

[y, u_out, v_out], [0, 0, 0], vs.YUV

)

# Pass 2: conservative motion-compensated luma denoising.

# Its lower limit intentionally prevents the chroma fix from forcing

# a second strong spatial luma smoothing operation.

luma_clean = havsfunc.SMDegrain(

chroma_fixed,

tr=LUMA_DENOISE_TR,

thSAD=LUMA_DENOISE_THSAD,

thSADC=150,

prefilter=2,

contrasharp=False,

RefineMotion=True,

plane=0,

chroma=False,

limit=LUMA_DENOISE_LIMIT,

limitc=255

)

y_denoised = core.std.ShufflePlanes(

luma_clean, 0, vs.GRAY

)

y_protected = core.std.MaskedMerge(

y_denoised, y, protect_mask

)

return core.std.ShufflePlanes(

[y_protected, u_out, v_out], [0, 0, 0], vs.YUV

)

# ========================================================================

# STAGE 7: WHITE-CREDIT DEHALO

# ========================================================================

def LD_WhiteCreditDehalo(clp):

bits = clp.format.bits_per_sample

scale = (1 << (bits - 8)) if bits > 8 else 1

max_val = float((1 << bits) - 1)

y = core.std.ShufflePlanes(clp, 0, vs.GRAY)

u_full = core.resize.Bilinear(

core.std.ShufflePlanes(clp, 1, vs.GRAY),

width=y.width, height=y.height

)

v_full = core.resize.Bilinear(

core.std.ShufflePlanes(clp, 2, vs.GRAY),

width=y.width, height=y.height

)

bright_core = core.std.Expr(

[y, u_full, v_full],

f"x {185 * scale} <= 0 "

f"x {215 * scale} >= {max_val} "

f"x {185 * scale} - {30 * scale} / {max_val} * ? ? "

f"y {128 * scale} - abs "

f"z {128 * scale} - abs max "

f"{20 * scale} <= {max_val} 0 ? min"

)

outer = bright_core

for _ in range(5):

outer = core.std.Maximum(outer)

ring = LD_Blur3(

core.std.Expr([outer, bright_core], "x y - 0 max")

)

dehaloed = havsfunc.FineDehalo(

clp,

rx=TEXT_DEHALO_RX,

ry=TEXT_DEHALO_RY,

darkstr=TEXT_DEHALO_DARKSTR,

brightstr=TEXT_DEHALO_BRIGHTSTR

)

dehaloed_y = core.std.ShufflePlanes(

dehaloed, 0, vs.GRAY

)

y_out = core.std.MaskedMerge(

y, dehaloed_y, ring

)

return core.std.ShufflePlanes(

[y_out, clp], [0, 1, 2], vs.YUV

)

# ========================================================================

# STAGE 8: CHROMA BLEED TIGHTENING

# ========================================================================

def TightenChromaBleed(

clp, depth=4, thresh=140, blur=3, limit_8bit=8

):

bits = clp.format.bits_per_sample

scale = (1 << (bits - 8)) if bits > 8 else 1

lim = limit_8bit * scale

warped = core.warp.AWarpSharp2(

clp,

thresh=thresh,

blur=blur,

type=1,

depth=depth,

chroma=0,

planes=[1, 2]

)

return core.std.Expr(

[clp, warped],

[

"",

f"y x {lim} - max x {lim} + min",

f"y x {lim} - max x {lim} + min"

]

)

# ========================================================================

# STAGE 9: DIRECTIONAL TEXT ECHO SUPPRESSION

# ========================================================================

def LD_TextEchoSuppression(clp):

bits = clp.format.bits_per_sample

scale = (1 << (bits - 8)) if bits > 8 else 1

max_val = (1 << bits) - 1

y = core.std.ShufflePlanes(clp, 0, vs.GRAY)

u = core.std.ShufflePlanes(clp, 1, vs.GRAY)

v = core.std.ShufflePlanes(clp, 2, vs.GRAY)

u_full = (

core.resize.Bilinear(u, width=y.width, height=y.height)

if (u.width != y.width or u.height != y.height)

else u

)

v_full = (

core.resize.Bilinear(v, width=y.width, height=y.height)

if (v.width != y.width or v.height != y.height)

else v

)

text_seed = core.std.Expr(

[y, u_full, v_full],

f"x {TEXT_ECHO_TEXT_MIN * scale} >= "

f"y {128 * scale} - abs "

f"{TEXT_ECHO_NEUTRAL_TOL * scale} <= and "

f"z {128 * scale} - abs "

f"{TEXT_ECHO_NEUTRAL_TOL * scale} <= and "

f"{max_val} 0 ?"

)

trail = text_seed

for _ in range(TEXT_ECHO_REACH):

trail = core.std.Expr(

[trail, LD_ShiftRight(trail, 1)],

"x y max"

)

keepout = text_seed

for _ in range(TEXT_ECHO_KEEP):

keepout = core.std.Expr(

[

keepout,

LD_ShiftRight(keepout, 1),

LD_ShiftLeft(keepout, 1),

LD_ShiftUp(keepout, 1),

LD_ShiftDown(keepout, 1)

],

"x y max z max a max b max"

)

trail = core.std.Expr(

[trail, keepout],

"x y - 0 max"

)

# Estimate echoes from a low-frequency guide. The actual correction

# is applied to the original luma to preserve its fine texture.

y_low = LD_Blur3(y)

ref_radius = max(

1, min(TEXT_ECHO_REFERENCE_RADIUS, 10)

)

right_samples = [

LD_ShiftLeft(y_low, px)

for px in range(1, ref_radius + 1)

]

expr_vars = [

"x", "y", "z", "a", "b",

"c", "d", "e", "f", "g"

]

ref_expr = expr_vars[0]

for token in expr_vars[1:ref_radius]:

ref_expr += f" {token} +"

ref_expr += f" {ref_radius} /"

right_ref = core.std.Expr(

right_samples, ref_expr

)

limit = TEXT_ECHO_MAX_CHANGE * scale

excess = core.std.Expr(

[y_low, right_ref],

f"x y - 0 max {limit} min"

)

candidate = core.std.Expr(

[y, excess],

"x y -"

)

activity = core.std.Expr(

[y_low, right_ref],

f"x y - {TEXT_ECHO_ACTIVITY * scale} >= "

f"{max_val} 0 ?"

)

tone_gate = core.std.Expr(

[y],

f"x {16 * scale} >= x {235 * scale} <= and "

f"{max_val} 0 ?"

)

mask = core.std.Expr(

[trail, activity],

f"x y * {max_val} /"

)

mask = core.std.Expr(

[mask, tone_gate],

f"x y * {max_val} /"

)

mask = core.std.Expr(

[mask],

f"x {TEXT_ECHO_STRENGTH} *"

)

fixed_y = core.std.MaskedMerge(

y, candidate, mask

)

return core.std.ShufflePlanes(

[fixed_y, clp], [0, 1, 2], vs.YUV

)

# ========================================================================

# STAGE 10: OPTIONAL UNIFORM TEXTURE RESTORATION

# ========================================================================

def LD_RestoreUniformTexture(clp, protect_mask):

# Disabled for this render so synthetic grain cannot conceal whether

# the source broiling is genuinely being suppressed.

if UNIFORM_GRAIN_VAR <= 0.0:

return clp

if not hasattr(core, "grain") or not hasattr(core.grain, "Add"):

return clp

bits = clp.format.bits_per_sample

scale = (1 << (bits - 8)) if bits > 8 else 1

max_val = (1 << bits) - 1

y = core.std.ShufflePlanes(clp, 0, vs.GRAY)

grain_candidate = core.grain.Add(

y,

var=UNIFORM_GRAIN_VAR,

uvar=0.0,

hcorr=0.0,

vcorr=0.0,

seed=-1,

constant=False

)

grain_mask = core.std.Expr(

[protect_mask, y],

f"y {20 * scale} <= y {230 * scale} >= or "

f"0 {max_val} x - ?"

)

restored_y = core.std.MaskedMerge(

y, grain_candidate, grain_mask

)

return core.std.ShufflePlanes(

[restored_y, clp], [0, 1, 2], vs.YUV,

prop_src=clp

)

# ========================================================================

# STAGE 11: TOP-SCANLINE FIX

# ========================================================================

def LD_TopScanlineFix(clp):

if clp.height < 4:

return clp

subsampling_h = (

clp.format.subsampling_h

if clp.format.color_family == vs.YUV

else 0

)

vertical_mod = 1 << subsampling_h

if 2 % vertical_mod != 0 or clp.height % vertical_mod != 0:

return clp

body = core.std.Crop(clp, top=2)

if body.height < 2:

return clp

top_strip = core.std.Crop(

body, bottom=body.height - 2

)

if top_strip.height != 2 or top_strip.width != body.width:

return clp

return core.std.StackVertical([top_strip, body])

# ========================================================================

# PIPELINE EXECUTION

# ========================================================================

if clip.format.bits_per_sample != 10:

clip = core.resize.Point(

clip,

format=clip.format.replace(bits_per_sample=10)

)

is_raw_capture = (

clip.width == 760 and clip.height == 488

)

# 1. Film cadence recovery and optional jitter stabilization

if is_raw_capture and clip.fps_num == 30000 and clip.fps_den == 1001:

clip = LD_FilmCadenceRecovery(clip)

clip = LD_StabilizeJitter(clip)

# 2. Single-field RF dropout repair

clip = LD_RepairFieldDropouts(

clip,

diff_thr_8bit=DROPOUT_DIFF_THR,

temp_tol_8bit=DROPOUT_TEMPORAL_TOL

)

# 3. Chroma rainbow/phase cleanup and subpixel shift alignment

clip = LD_RainbowAndPhaseCleanUV(

clip,

th_8bit=RAIN_THRESHOLD,

sft_8bit=RAIN_SOFTEN,

phase_thr_8bit=CHROMA_PHASE_THR

)

clip = FixChromaShift(

clip,

h_shift=CHROMA_SHIFT_H,

v_shift=CHROMA_SHIFT_V

)

# 4. Left capture border defect repair

if is_raw_capture:

clip = LD_LeftEdgeDefectRepair(clip)

# 5. Initial halo reduction

clip = havsfunc.FineDehalo(

clip,

rx=DEHALO_RX,

ry=DEHALO_RY,

darkstr=DEHALO_DARKSTR,

brightstr=DEHALO_BRIGHTSTR

)

# 6. Crop and restore 720x480 geometry for raw captures

if is_raw_capture:

clip = core.std.Crop(

clip,

left=CROP_LEFT,

right=CROP_RIGHT,

top=CROP_TOP,

bottom=CROP_BOTTOM

)

clip = core.resize.Spline36(

clip,

width=720,

height=480

)

# 7. Secondary halo reduction

clip = muvsfunc.YAHRmod(clip)

# 8. Build corrected zero-moat linework/star protection mask

line_star_mask = LD_CleanLineAndStarMask(clip)

# 9. Bounded luma residual correction, not repeated smoothing passes

clip = LD_UniformSurfaceClean(

clip,

line_star_mask

)

# 10. Restore stronger u/V broiling suppression while keeping luma gentle

clip = LD_GradeNoiseReduction(

clip,

line_star_mask

)

# 11. White-credit halo reduction and chroma bleed tightening

clip = LD_WhiteCreditDehalo(clip)

clip = TightenChromaBleed(

clip,

depth=CHROMA_WARP_DEPTH,

thresh=CHROMA_WARP_THRESH,

blur=CHROMA_WARP_BLUR,

limit_8bit=CHROMA_WARP_LIMIT

)

# 12. Mild debanding, without synthetic grain from f3kdb

if hasattr(core, "f3kdb"):

debanded = core.f3kdb.Deband(

clip,

range=DEBAND_RANGE,

y=DEBAND_Y,

cb=DEBAND_CB,

cr=DEBAND_CR,

grainy=0,

grainc=0,

dynamic_grain=False,

output_depth=10

)

y_deband_safe = core.std.MaskedMerge(

core.std.ShufflePlanes(debanded, 0, vs.GRAY),

core.std.ShufflePlanes(clip, 0, vs.GRAY),

line_star_mask

)

clip = core.std.ShufflePlanes(

[y_deband_safe, debanded],

[0, 1, 2],

vs.YUV

)

# 13. Texture-preserving directional text-echo suppression

clip = LD_TextEchoSuppression(clip)

# 14. Synthetic grain is disabled for this comparison render

clip = LD_RestoreUniformTexture(

clip,

line_star_mask

)

# 15. Top-scanline replacement and output frame properties

clip = LD_TopScanlineFix(clip)

clip = core.std.SetFrameProp(

clip, prop="_SARNum", intval=8

)

clip = core.std.SetFrameProp(

clip, prop="_SARDen", intval=9

)

clip = core.std.SetFieldBased(clip, 0)


r/vhsdecode • • Oct 26 '26

First Decode! got my setup up and running

Thumbnail
gallery
40 Upvotes

very proud of myself. i tapped my VCR and built an hsdaoh dualadc. got some successful decodes out of it.

no amp atm but I have ordered one. im still getting excellent results without one though

here's a cap of a raw-ish output with all 525 lines

https://youtu.be/PAupsZSCejc

and here's a slightly post processed capture

https://youtu.be/9WO5qInRdtI?is=ukcqJEem6R8hrdNb