Tdarr Scripting Update: Smarter HEVC Decisions and Safer Replacements

Rights and lawful use: Apply these ideas only to media you own or are authorized to process. Keep recoverable originals. Transcoding does not create permission to acquire, copy, distribute, or bypass protection on a work.

Quick Answer

My latest Tdarr script revision makes two separate decisions: whether video needs another encode, and whether a finished candidate deserves to replace its source. Suitable 8-bit and 10-bit HEVC can stay unchanged. Optional HEVC re-encodes require a usable reported video-stream bitrate, then at least 5% whole-file savings before replacement. Video-copy jobs have a separate 2% growth allowance. International TV retains its all-audio and subtitle protections. These are explicit library policies, not proof that a smaller file looks better.

This is a new follow-up to my original Tdarr reference-design article, not a replacement for it. The original covers the broader server, worker, storage, and recovery design. This update explains the December 3 flow changes and the reasoning behind them. It is not a newly approved download of the older automation bundle.

Editorial illustration of a compact GPU workstation, two-bay storage, a separate backup drive, and headphones
Generated editorial illustration of a media-processing workspace; not a photograph of this installation or evidence of a hardware test.

What Changed, and What Did Not

The goal is not to make every file look identical in a codec report. It is to stop doing unnecessary work while keeping a clear boundary around original-file replacement.

Area Revised behavior Why it matters
Existing HEVC video Suitable 8-bit and 10-bit inputs can take the video-copy path A bit-depth label alone is not a reason for another lossy encode
Oversized-HEVC decision Use the probed video stream's bitrate, not the container's total rate Preserved audio should not make the video look wasteful
Optional video re-encode Replace only when the candidate is no more than 95% of the source size, after the other checks A trivial size reduction is not enough to justify replacing an original
Video-copy candidate Allow up to 102% of the source size, after the other checks A necessary remux can change container overhead without re-encoding video
Not worth replacing Keep the original and end that path without replacement or a downstream refresh A policy skip is different from a failed validation
International TV Request all-track copying; reject specified audio and subtitle signature changes Original-language audio and accessibility tracks remain part of the preservation requirement
Quick health checks Schedule a separate overnight CPU worker Header inspection should have an explicit resource window, not be confused with GPU transcoding

The active revisions are the TV-efficient V3 flow, International TV V2, and movie-HQ V3. The movie revision serves three movie-library roles. The earlier revisions remain the rollback choices; the disabled test library is not a reason to start production processing.

The revision keeps the existing high dynamic range (HDR) and Dolby Vision review gate. It does not claim a new quality-optimized encoder preset, a fix for GPU memory contention, or a cure for historical network-attached storage (NAS) replacement errors.

First Separate Encoding From Replacing

An encode decodes and compresses the video again. That can change its visual characteristics and consume substantial processing time.

A remux changes the container or stream arrangement. With FFmpeg's stream copy, selected compressed streams pass through without another decode-and-encode cycle. The container can change even when a copied video's compressed payload does not. FFmpeg documents this distinction in its stream-copy explanation.

Replacement is a third operation: writing the accepted candidate into the library's original-file position. A successful FFmpeg exit is not permission to perform that operation. The candidate must pass the relevant format, duration, stream-preservation, and size checks first.

That separation also explains an apparent contradiction. A job can finish its processing step successfully and still end with the original kept. That is often exactly the intended outcome.

Why Good 8-Bit HEVC Stays 8-Bit

HEVC, also called H.265, is a video compression format. Bit depth describes the precision available for representing image samples; it is not an overall quality score.

Re-encoding an existing 8-bit file into a 10-bit format cannot reconstruct image detail already discarded by its source. A Main10 output may be an intentional target for newly encoded material, but that does not make every existing 8-bit HEVC file defective.

The revised flow removes the automatic 8-bit-to-10-bit detour for otherwise suitable HEVC. A compatible 8-bit source can remain 8-bit on the copy path. Newly encoded candidates still have to satisfy the configured HEVC Main10 check.

Those two statements are not contradictory: keep a suitable existing representation; enforce the chosen target when an encode is actually required. A Main10 label still does not establish good visual quality, supported client playback, or correct HDR handling.

This change is not a universal codec bypass. Non-HEVC inputs follow the broader flow's other decisions. HDR or Dolby Vision material still goes through its separate review boundary rather than being treated as an ordinary standard dynamic range (SDR) conversion.

A Large File Does Not Necessarily Mean Wasteful Video

Imagine a file with video at 6 Mb/s and several audio tracks totaling roughly another 8 Mb/s. Those are illustrative values, not a measurement of a library item. A container-level rate around 14 Mb/s would tell you very little about whether the 6 Mb/s video needs another encode.

Three measurements have different jobs:

  • Whole-file bytes describe storage occupied and later help decide whether replacement is worthwhile.
  • Container bitrate combines the streams and container overhead. It is not the video's bitrate.
  • Video-stream bitrate describes the selected video's reported rate. This is the input used for the optional oversized-HEVC decision.

The new video policy reads ffProbeData.streams[].bit_rate from the first video stream that is not an attached cover image. It deliberately does not substitute the container's format.bit_rate or a muxer's BPS tag when that stream field is unavailable.

A stored bitrate tag can be stale after an earlier operation. Treating it as a freshly measured stream rate would give the policy more confidence than the evidence supports. FFprobe can report both format and stream fields, but their availability depends on the input and probing; a missing value is not a reason to guess. See the FFprobe documentation.

The policy also rejects an optional bitrate-based encode when usable numbers are missing or inconsistent. When a positive total rate is available, a video rate above 105% of that total fails the consistency check. That 5% tolerance is a local sanity rule, not an FFmpeg standard. If the total rate is absent, this comparison cannot corroborate the stream rate.

A present stream field can also be inaccurate or stale. The policy uses better-scoped evidence than a container total, but it does not independently count video packets to prove that rate is correct.

Missing evidence means no optional size-based HEVC encode. It does not prove the source is optimal, and it does not waive the rest of the flow's checks. Inspect repeated “bitrate unavailable” decisions before deciding whether a different, carefully measured probe strategy is worth adding.

The Actual TV and Movie Thresholds

These are the captured active-flow settings, not the defaults written into the plugin. Values are video-only kilobits per second; 1,000 kb/s equals 1 Mb/s here.

Probed video height bucket TV and International TV: base / trigger Movies: base / trigger
Up to 480 1,800 / above 1,980 kb/s 3,000 / above 3,300 kb/s
Up to 720 3,500 / above 3,850 kb/s 5,500 / above 6,050 kb/s
Up to 1080 6,500 / above 7,150 kb/s 10,500 / above 11,550 kb/s
Up to 1440 11,000 / above 12,100 kb/s 16,000 / above 17,600 kb/s
Up to 2160 22,000 / above 24,200 kb/s 30,000 / above 33,000 kb/s

Every bucket has 10% headroom. The comparison is strictly “greater than,” so a valid 1080p TV rate exactly at 7,150 kb/s does not trigger this policy. A rate above that threshold may qualify only when the other inputs are valid.

TV and International TV also require a whole-file size of at least 0.5 GiB for this optional encode. Movies require at least 1 GiB. The size test is inclusive: a file exactly at the minimum can qualify. GiB is a binary unit; one GiB is 1,073,741,824 bytes.

The script chooses the first height bucket that contains the probed height. It is not a frame-rate-, grain-, motion-, or perceptual-quality model. Heights beyond the listed range fall back to the largest configured bucket; that is not an independently qualified 8K policy. Unknown or invalid heights do not qualify through the normal valid-number gate.

These thresholds express my library's policy. They are not universal recommended bitrates for every movie, animated program, sports feed, or client. Raising or lowering one changes which files are considered, not whether a candidate will look acceptable.

Try the two policy decisions

Use the captured library settings to explore eligibility and size acceptance. This is an explanatory model, not a Tdarr connection or a file validator.

1. Optional HEVC re-encode

2. Candidate size acceptance

A 95% candidate is 5% smaller. A 102% candidate is 2% larger. The original and candidate must be different files with readable sizes.

Scope matters: the first model assumes an otherwise eligible HEVC source and the earlier HDR review boundary. The second assumes required format, duration, and stream checks have passed. Neither result authorizes replacement or establishes quality, payload identity, playback, or recoverability.

Replacement Has Three Outcomes, Not Just Pass or Fail

The replacement plugin recognizes three results:

Outcome Meaning Next action
Validated candidate This plugin's relevant checks passed Continue to the replacement stage after the earlier flow validators
Review Required evidence is missing, a format/stream check failed, or a suspicious size was found Reset the flow's working-file reference to the original and require review
Keep original There is nothing to replace, or the encoded candidate is not worth retaining End the path without replacement or a Plex/Arr refresh

That reset changes the flow's reference. It is not a command to restore already overwritten content, delete every cache file, or rebuild a backup.

The captured graph has only one incoming edge to the original-file replacement stage: output 1 of the replacement policy. The keep-original path is terminal. That routing is as important as the arithmetic. A correct validator provides little protection if another edge lets a failed candidate bypass it.

For readers adapting the code, the decision is stored under args.variables.user.needsVideoEncode as the string "true" or "false", not a JavaScript boolean. The replacement policy accepts only those two strings. A missing or incorrectly typed flag goes to review. Do not write if (flag) for this contract: JavaScript treats the nonempty string "false" as truthy.

Optional Encodes Must Save at Least 5%

The plugin compares the candidate's actual on-disk byte count with the original's:

output ratio = candidate bytes / original bytes

For the encode branch, a ratio above 0.95 means keep the original. Exactly 95% satisfies the size rule; 95.1% does not. The comparison uses whole-file bytes, even though the earlier video-selection decision uses video-only bitrate.

That distinction is deliberate. The first question is whether the video looks eligible for work. The later question is whether the complete candidate saves enough storage to justify replacement. Large preserved audio tracks can make the second test harder to satisfy.

For illustration, a 10 GB original and a 9.4 GB candidate save 6% and pass this size condition. A 9.6 GB candidate saves 4% and stays out of the library. Those are hypothetical sizes, not measured savings from this update.

The rule prevents a low-value replacement. It does not refund the processing time already spent creating a rejected candidate. Any claim about net GPU-time or electricity savings still needs measurements.

Video-Copy Jobs Get a Different Allowance

A video-copy job can have a legitimate reason to rewrite its container while keeping the video unchanged. Its acceptance ceiling is 1.02, or 102% of the original's byte count. Exactly 102% passes the size condition; anything larger goes to review.

The policy compares the probed video codec, pixel format, width, height, and stream ordering between source and candidate. A different bit depth or resolution cannot silently pass as a video-copy result.

Those format signatures are not cryptographic evidence that the compressed video bytes are identical. Stream-payload comparisons and actual playback remain separate checks.

Very Small Output Is a Warning, Not a Victory

Both branches retain the existing suspicious-size floor: output at or below 8% of the original goes to review. Missing or zero-size files also fail.

This does not establish that every output above 8% is healthy, or that every smaller file is corrupt. It is a conservative stop for a result that deserves closer inspection. A truncated movie can be smaller, correctly labeled, and still be unusable.

International TV Keeps Its Original-Language Tracks

The all-audio policy applies specifically to International TV. The ordinary TV and movie flows retain their separately configured audio policy; this update does not quietly convert every library to all-track preservation.

In the international path, the preservation plugin maps every audio and subtitle stream for copy. It avoids selecting or deleting audio based on language. It also preserves explicit disposition flags, such as which track is default or which subtitle is forced, rather than relying on FFmpeg to choose a new default automatically.

That mapping applies to the entries presented to the preservation step. It cannot recover a subtitle already omitted upstream; the later comparison against the original is still necessary. Fonts, attachments, subtitle timing, and payload contents need their own checks when they matter to the file.

Before replacement, the audio validator compares the original and candidate's ordered tracks: codec, channel count, sample rate, channel layout, language, title, and enabled disposition flags. Missing original probe details or a mismatched signature require review. The international replacement policy also compares subtitle signatures, including language, title, and dispositions.

This protects against a familiar class of mistake: a video job that finishes but leaves behind the wrong language or removes the subtitle needed to understand it. It cannot reconstruct audio that an earlier job already removed. That requires an intact source or backup.

A metadata signature is still not a payload checksum. Two tracks can describe themselves the same way while containing different data. For copied streams, FFmpeg's streamhash muxer provides a separate way to compare selected stream data.

For example, these are read-only inspection commands, not commands executed against library media for this article:

ffmpeg -v error -i "source.mkv" -map 0:a -c copy -f streamhash -hash sha256 -
ffmpeg -v error -i "candidate.mkv" -map 0:a -c copy -f streamhash -hash sha256 -

Compare corresponding tracks and keep the tool version and mapping consistent. Check subtitle payloads separately when present. Matching selected-stream hashes do not prove the full file's timing, HDR behavior, client compatibility, or visual quality.

Health Checks Now Have Their Own Resource Window

The rollout record adds one Quick CPU health-check worker on the primary processing node from 02:00 inclusive to 05:00 exclusive, America/Chicago time. A five-minute scheduler reconciliation applies the window. The GPU worker schedule is separate and was not expanded by this change.

Quick health checks inspect headers; they are not equivalent to decoding an entire movie. A successful quick check should not be described as a full playback test. Tdarr documents the separate worker types and health-check modes.

The scheduled window's first complete run and backlog reduction were not established for this article. Monitor queue progress, NAS activity, and household-service impact during that run. A schedule can reserve an opportunity to work; it cannot prove that the work completed.

What I Verified for This Update

The server's read-only status endpoint reported Tdarr 3.11.00. A read-only configuration capture confirmed the three new flow revisions, their five active library assignments, their actual bitrate settings, and the single guarded route into replacement.

That capture verifies configuration, not matching plugin bytes on every worker. Confirm that each processing node has the intended plugin revision before trusting a multi-node rollout.

I also ran 44 isolated policy tests against snapshotted plugin code. These used synthetic probe objects and disposable byte-size fixtures, not actual movie files. The checks covered both HEVC bit depths, missing or inconsistent rates, active TV/movie thresholds, inclusive minimum sizes, exact 95% and 102% boundaries, the 8% floor, no-op paths, changed video dimensions, and international stream-signature failures.

The tests passed. That is evidence of those decision branches behaving as tested, not a real-media encode, GPU benchmark, sustained NAS replacement test, perceptual-quality score, or successful backup restore. No production file was requeued, encoded, renamed, or replaced to prepare this article.

There is also an important negative result: the test suite demonstrates that a matching audio signature can pass without proving payload identity. The preservation claim must not be stretched beyond what the validator actually checks.

A Safe Way to Adopt the Same Ideas

Start with a reversible flow revision, not a live database edit or a library-wide requeue.

  1. Record and back up the current state. Save the application configuration consistently, export the flow, record library assignments and node settings, and verify that recovery material is accessible away from the processing host.
  2. Clone the flow. Keep the working version available. Make the encode/copy decision explicit and verify every edge into replacement, including error and no-op branches.
  3. Use copied, authorized canaries: disposable sample files. Include suitable 8-bit HEVC, suitable 10-bit HEVC, an input requiring an encode, missing bitrate data, multiple audio languages, subtitles, and material that should stop for HDR review.
  4. Inspect the complete candidate. Check stream metadata, duration, required payloads, relevant image/HDR properties, and playback on the actual clients. Read the reason for a stop instead of repeatedly retrying it.
  5. Exercise replacement and recovery in a disposable target. Include the real local-cache-to-NAS boundary if that is your design. A same-filesystem rename test does not establish cross-filesystem behavior.
  6. Enable a limited production scope only after those checks pass. Watch error types, policy skips, GPU pressure, cache space, NAS activity, and playback impact before expanding.

For rollback, stop assigning new jobs to the revised flow, allow or safely stop existing work, and restore the earlier library-to-flow assignment using the application's supported controls. Restoring an old flow does not restore media that was already overwritten. Restore that content separately from its protected source or backup.

Keep the Tdarr UI and API on trusted management paths, with application authentication and appropriate firewall restrictions. This article's read-only access is not a recommendation to expose an unauthenticated API. Review the current Tdarr authentication documentation for your installed version.

The Next Improvement Must Be Measured

The revised logic is intentionally less eager to change a file. It keeps suitable HEVC, refuses to guess a missing video rate, preserves the international stream policy, and distinguishes a useful replacement from an unnecessary one.

What remains is operational evidence: how often each branch is taken, whether the health-check window clears useful work, how replacement behaves under sustained NAS load, and whether representative encodes justify their quality and processing cost. A larger queue of completed jobs is not enough; the reasons behind those results matter.

Related TechGeeks Reading

References

The policy explanations above come from the source revision and read-only flow capture. Upstream references explain the underlying tools; they do not certify these custom scripts or the suitability of any bitrate threshold.

Leave a Reply

Your email address will not be published. Required fields are marked *