Skip to content

fix(mediasample): stop the credits tail pass failing on files with damaged non-keyframes - #5604

Open
Rhainland wants to merge 4 commits into
Silo-Server:mainfrom
Rhainland:fix/5558-credits-tail-error-rate
Open

Rhainland wants to merge 4 commits into
Silo-Server:mainfrom
Rhainland:fix/5558-credits-tail-error-rate

Conversation

@Rhainland

@Rhainland Rhainland commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #5558
Related issue: N/A
Validation tasks: none passed that this reaches; it touches credits detection, which #1148 C1 tests (open, failed on #4275)

Other clients: N/A (no client-visible change)

On FFmpeg 8.1 and later, which the release image ships, the credits tail pass fails with exit 69 on episodes whose non-keyframe video packets are damaged near the end. The tail and the credits fingerprint are stored as failed, the season stays partial, and Silo decodes the tail again every week without ever getting credits markers for those episodes. This change lets the pass keep the keyframes, silences and fingerprint it decoded.

Approach

FFmpeg 8.1 started enforcing -max_error_rate (default 2/3): a decoder whose failed packets exceed two thirds of failed packets plus returned frames stops the run. A frame that -skip_frame nokey skips counts as neither, so a keyframes-only read of a window with a few hundred damaged non-keyframes reports a rate near 0.9, while a full decode of the same window stays far under the limit.

Every software attempt of a sampling read that passes -skip_frame:v (keyframes-only windows, Samples lists, Sheets) now also passes -max_error_rate 1, which turns the check off. The result is the behaviour Silo had with FFmpeg 7.1, where the check never fired. Hardware attempts keep the limit: the credits tail and trickplay run software only after a hardware attempt fails, so a GPU that fails decode frame after frame must still fail its attempt. A damaged file on a hardware host fails the hardware attempt with exit 69 and then succeeds in software. Rows that already failed pick this up on their next scheduled retry; no analysis version bump is needed.

The option is global, so it also stops audio decode errors from failing the run. A tail window whose audio is entirely undecodable (file 10260 in the issue) now succeeds with video statistics and an empty fingerprint, which the analyzer stores as having no audio, instead of being retried every week. A window with partly damaged audio gives a shorter fingerprint, as it already did below the 2/3 limit. The other options the issue lists (classifying exit 69, keeping partial output of a failed run, or splitting audio and video into separate reads) need more changes and a second decode, so I left them out.

Validation

  • Focused tests for internal/mediasample and its dependents (intromarkers, trickplay, chapterthumbs, transcodenode, proxy, subsync, taskmanager/tasks): pass with the host FFmpeg 8.0.1 and with the release image's jellyfin-ffmpeg 8.1.3.
  • New real-FFmpeg test (a keyframes-only window over an H.264 clip whose non-key packets have a broken NAL length): fails with exit 69 on 8.1.3 before the change, passes after. It passes trivially on FFmpeg older than 8.1 and skips without FFmpeg.
  • TestKeyframeReadsLiftErrorLimitOnlyInSoftware builds the window, Samples, Sheets-list and Sheets-window arguments for software and hardware attempts and checks that only software attempts lift the limit. It fails on a2f37cf, before the hardware split.
  • Maintainer review: on an isolated sandbox with the release jellyfin-ffmpeg 8.1.3 (software decode), a damaged episode's credits tail and fingerprint failed with exit 69 on the merge base; rebuilt from 807b4a8 with the same database, both complete and the episode gets a credits marker. Under 8.1.3 the real-FFmpeg test fails on the base and passes on this branch.
  • go build ./..., gofmt, go mod tidy -diff, go vet ./..., make lint-changed (0 issues), verify-local-paths, verify-size-ratchet, verify-bidi, verify-case-collisions: pass.
  • Not run: the full make test-go with a test database (no DB code changed), and the Web half (no web change).
  • Local server with jellyfin-ffmpeg 8.1.3: before and after below.

Evidence

Local build with the release image's jellyfin-ffmpeg 8.1.3. A series library with three synthetic 600 s H.264/AAC MP4 episodes; in S01E01 (file 2) the NAL length prefix of the last 300 non-key video packets is overwritten, as in the issue's recipe. POST /api/v2/admin/tasks/detect_intro_markers/run, then a second run after moving the season's analyzed_at back 8 days and the failed rows' retry_after into the past (the weekly revisit).

Before, origin/main at 5d0006f, second run:

media_file_id | kind                | status   | last_error                                                                                                                | failure_count
            2 | credits_fingerprint | failed   | sampling the credits tail of file 2: ffmpeg sampling failed (exit) after 2 attempts: exit status 69: Conversion failed! | 2
            2 | credits_tail        | failed   | sampling the credits tail of file 2: ffmpeg sampling failed (exit) after 2 attempts: exit status 69: Conversion failed! | 2
season: status partial, markers_written 0, last_error "2 fingerprint extraction(s) failed"
GET /api/v2/markers/files/2 -> "credits": {}

After, this branch, same database and steps:

media_file_id | kind                | status   | failure_count | point_count
            2 | credits_fingerprint | complete | 0             | 1917
            2 | credits_tail        | complete | 0             | 48
season: status complete, markers_written 3
GET /api/v2/markers/files/2 -> "credits": {"start_seconds":361,"end_seconds":600,"source":"scanner",...}

Files 1 and 3 (undamaged) and every intro fingerprint stay as they were; no "credits tail pass failed" line is logged.

Risks

FFmpeg no longer stops a keyframes-only read on decode errors, so a badly damaged file decodes its whole window instead of stopping early. The window is already bounded by its duration and attempt timeout. Undecodable tail audio is stored as no audio rather than retried. On a host with hardware decoding, a damaged file decodes its window twice: once in the hardware attempt that fails, then in software.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
  • The Evidence section shows every change a user can see, or how I checked a change nobody sees.

Council review

Rounds: 2, last reviewed 807b4a8 (ce88bd9 after it changes only the new test, as round 2 asked)

Member Round 1 (a2f37cf) Round 2 (807b4a8)
Sol (gpt-6.2-sol, medium) 6/10 7/10
Opus (claude-opus-5-5, medium) 7.5/10 8/10
Gemini (gemini-4-neon, medium) 9/10 8.5/10

Fixed: hardware attempts kept the lifted limit and lost their software fallback (807b4a8); the argument test now covers every builder (ce88bd9). Answered: a fully undecodable video window fails with invalid data before and after this change. Left for the maintainers: undecodable audio shifts the credits fingerprint's later points earlier (main already does this below the two-thirds limit; this branch extends it to combined tail runs above it), and trickplay window reads carry the last image across keyframes that fail to decode (also already on main below the limit).

AI Disclosure

  • Harness: Claude Code (via T3 Code); Codex CLI for code review
  • Tool(s): Bash, Read, Edit, git, GitHub CLI (read-only), Docker (local Postgres and Redis), ffmpeg and ffprobe (host 8.0.1 and the release image's jellyfin-ffmpeg 8.1.3), Codex CLI
  • Model(s): claude-opus-5-5; gpt-6.2-sol (code review)
  • Involvement: Fully AI-generated, human verified
  • Maintainer review: Claude Code (claude-opus-5-5) through /silo review pushed 807b4a8 and ce88bd9; council of gpt-6.2-sol, claude-opus-5-5 and gemini-4-neon, see Council review.
  • Adversarial review: dual-code-review of the full branch diff (Correctness, Standards, Spec) by gpt-6.2-sol through Codex CLI and a separate claude-opus-5-5 reviewer, reconciled. Both raised the audio tradeoff: the global option also accepts windows with partly or wholly undecodable audio, which gives a shorter fingerprint or an empty one stored as no audio. Kept, because it restores the pre-8.1 behaviour and ends the weekly retries, and it is stated above. Fixed: the docs and code comment now limit the rule to sampling reads (the capability probes do not pass it) and note the pre-8.1 behaviour, and the test asserts the exact keyframe count. Dismissed: that the test passes on FFmpeg older than 8.1 (that FFmpeg never fails this read) and that it damages every non-keyframe instead of a tail stretch (the run exercises the same error-rate path).

Note

Fix keyframes-only media sampling failing on damaged non-keyframes

  • Keyframes-only reads could fail on files with damaged non-keyframe packets. Software decoding attempts now prepend FFmpeg's decode-error-limit override before the skip-frame option; hardware attempts keep the skip-frame option alone.
  • Applies the change across all four keyframe-read paths: window, Samples, Sheets-list, and Sheets-window, via a shared skipFrameArgs helper in concat.go.
  • Adds an integration test that damages non-keyframe packets and verifies a keyframes-only window run succeeds, plus an argument test covering all four paths. Documents the FFmpeg 8.1 behavior in media-sampling.md.
  • Behavioral Change: only software attempts include the decode-error-limit override; audio decode errors in the same run are also affected by the raised limit.

Macroscope summarized ce88bd9.

…on-keyframes

FFmpeg 8.1 and later stop a run with exit 69 when a decoder's errors
exceed two thirds of its errors and returned frames together. A frame
that -skip_frame skips counts as neither, so a keyframes-only read of a
window whose non-keyframes are damaged failed although every keyframe
decoded. The credits tail pass then failed on such files and was retried
every week.

Every read that passes -skip_frame:v now also passes -max_error_rate 1.

Closes Silo-Server#5558
@silo-triage silo-triage Bot added the size/M 50–199 added + deleted lines (all files); change volume, not priority. label Nov 29, 2026
@silo-kody

silo-kody Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Keyframe-only media sampling now adds -max_error_rate 1 alongside -skip_frame:v. The change routes sampling argument paths through a shared helper, documents FFmpeg’s decoder-error threshold, and adds an integration test that corrupts non-keyframe packets and checks the sampled window.

Changes: Keyframe sampling error tolerance

Layer / File(s) Summary
Shared skip-frame arguments
internal/mediasample/concat.go, internal/mediasample/args.go, internal/mediasample/request.go
A shared helper adds -max_error_rate 1 before the skip-frame option. Keyframe-only argument paths now use the helper.
Damaged-packet validation and documentation
internal/mediasample/ffmpeg_test.go, docs/architecture/media-sampling.md
An integration test corrupts non-keyframe packets and checks that a keyframe-only window returns six frames. The documentation describes the FFmpeg error threshold and the effect of the option.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: quick104

Merge Risk: Minimal · up to a2f37

Keyframe-only media sampling now tolerates damaged non-keyframes instead of exiting with FFmpeg's error 69, so credits-tail rows should stop failing and being retried weekly. The change is small, adds a regression test, and is easy to revert. One docs sentence slightly overstates that every skip-frame read receives the option, which is a minor wording point and does not block the merge.

Security architecture risk: Minimal · up to a2f37

Keyframe sampling can keep usable output from damaged media instead of failing the whole run. The change does not expand what media the sampler can access, but callers should not interpret a successful run as proof that every stream decoded.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • observed — The changed option affects how existing FFmpeg sampling invocations report decode failures. Its value is fixed, and the changed window and list argument construction still uses the existing request input and demuxer selection.

Trust Boundaries and Controls

  • observed — The new error-rate option is separate from the unchanged concat protocol and format restrictions and the per-entry relay options. It changes whether decoding errors fail the process, not which concat sources FFmpeg is configured to open.
Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the fix (credits tail pass failing on files with damaged non-keyframes) and the package (mediasample). The changeset adds -max_error_rate 1 to every sampling read that passes -skip_fra…
Linked Issues check Passed [#5558] The issue asks that file-caused FFmpeg exit 69 in the credits tail pass not leave rows failed, and that usable frames, silence data, and fingerprints not be discarded because FFmpeg exits nonz…
Out of Scope Changes check Passed All changes sit in the credits and sampling path tied to #5558. concat.go, args.go, and request.go add the shared skipFrameArgs helper. ffmpeg_test.go adds the real-FFmpeg regression test. `…
Description check Passed The description states the problem (FFmpeg 8.1 exit 69 on credits tail passes with damaged non-keyframe packets), the approach (adding -max_error_rate 1 to software sampling reads that use -skip_frame…
Full details: Title check

Explanation

The title names the fix (credits tail pass failing on files with damaged non-keyframes) and the package (mediasample). The changeset adds -max_error_rate 1 to every sampling read that passes -skip_frame:v, which is the mechanism behind this fix. The title is specific, but it describes the symptom rather than the -max_error_rate change itself, so it is related to the main change without naming the exact mechanism.

Full details: Linked Issues check

Explanation

[#5558] The issue asks that file-caused FFmpeg exit 69 in the credits tail pass not leave rows failed, and that usable frames, silence data, and fingerprints not be discarded because FFmpeg exits nonzero. The issue's own test evidence ties the failure to the error-rate limit: 52 files produced enough keyframes when the limit was bypassed. The change adds -max_error_rate 1 through skipFrameArgs in internal/mediasample/concat.go. listInputArgs (Samples lists), Request.keyframeInputArgs (request.go), and the keyframe-only window path (args.go) now use this helper, so every keyframes-only sampling read gets the lifted limit. The PR's before/after run on jellyfin-ffmpeg 8.1.3 shows file 2 moving from failed (exit 69) to complete, with credits markers written. A real-FFmpeg test (TestRunKeyframesOnlyWindowToleratesDamagedNonKeyframes) covers the keyframes-only case. The issue's third bullet (cases with no keyframes or fully unreadable audio) does not require credits data, and the PR documents how those cases now resolve. Remaining uncertainty: the real-FFmpeg test passes trivially on FFmpeg older than 8.1, and the author did not run the full make test-go suite. Neither gap contradicts the requirements.

Full details: Out of Scope Changes check

Explanation

All changes sit in the credits and sampling path tied to #5558. concat.go, args.go, and request.go add the shared skipFrameArgs helper. ffmpeg_test.go adds the real-FFmpeg regression test. docs/architecture/media-sampling.md documents the new option. The global effect on audio decode errors is a direct consequence of the same flag, and the PR states it openly. The PR also explicitly leaves out the broader options from the issue (exit 69 classification, partial-output retention, split audio and video reads), so it adds no unrelated work. No change lacks a connection to the linked issue.

Full details: Description check

Explanation

The description states the problem (FFmpeg 8.1 exit 69 on credits tail passes with damaged non-keyframe packets), the approach (adding -max_error_rate 1 to software sampling reads that use -skip_frame:v, not hardware), the tests, and the risks. It matches the changeset in internal/mediasample, the new test, and the docs in media-sampling.md, so it is related and specific.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 141fe913-b402-401e-b015-420f3177f0de
Commits

Reviewing files that changed from the base of the PR and between 5d0006f and a2f37cf.

Files selected for processing: 5

  • docs/architecture/media-sampling.md
  • internal/mediasample/args.go
  • internal/mediasample/concat.go
  • internal/mediasample/ffmpeg_test.go
  • internal/mediasample/request.go

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

Comment thread internal/mediasample/concat.go Resolved
@silo-triage silo-triage Bot added bug Something isn't working go Pull requests that update go code priority: P2 Limited scope, workaround exists, or polish labels Nov 29, 2026
A hardware attempt falls back to software only when it fails. With the
limit lifted, a GPU that fails decode frame after frame on FFmpeg 8.1 or
later would exit 0 with few or no frames, and the credits tail would store
that as a sparse tail until the file changes. Lift the limit only on
software attempts, so the hardware attempt still fails over; a damaged
file reaches the software attempt the same way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@Quick104 Quick104 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of a2f37cf. The fix holds: with the release image's jellyfin-ffmpeg 8.1.3, the new real-FFmpeg test fails on the merge base with exit 69 and passes on this branch, and a sandbox built from the base reproduced the credits-tail failure on a damaged episode. One finding below, which I'm fixing in a commit on this branch, so there's no need to change it yourself.

🤖 Claude Code (claude-opus-5-5)

Comment thread internal/mediasample/concat.go Resolved
@silo-kody

silo-kody Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

Build the Sheets list and window arguments through buildSheetsArgs, so a
call site that passes the wrong attempt fails the test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
if attempt.Hardware {
return []string{skipFrameOption, skip}
}
return []string{"-max_error_rate", "1", skipFrameOption, skip}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Bug high

Damaged keyframes are silently accepted as successful video samples

Damaged keyframes can produce incomplete frame statistics while the sample is reported as successful. Distinguish required keyframe decoding failures from errors in skipped non-keyframes before accepting the result.

Prompt for LLM
File internal/mediasample/concat.go, line 72:

Damaged keyframes are silently accepted as successful video samples

The software attempt also accepts decoding failures in keyframes, so a file with some damaged keyframes returns incomplete frame statistics as a successful sample instead of taking the existing failure path. Distinguish failures of required keyframes from errors in skipped non-keyframes before accepting the result.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

​

​

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FFmpeg's error-rate check can't separate the two cases: it counts every decode error a decoder reports, keyframe or not, against every frame it returns. So before 8.1 enforced it, and on main today whenever errors stay under two thirds, a window with some damaged keyframes already returns its surviving frames as a success. The callers have their own guards for thin results, and those don't depend on the exit status. The credits tail stores a window with fewer than one keyframe per 30 s as sparse (tailUnusableAfterSampling). Sheets fail with ReasonEmpty when nothing decoded or too many cells had to be filled (sheetAssembler.finish). A window whose keyframes all fail still exits non-zero with invalid data. A per-keyframe check would need a different signal than this limit, so I'm leaving it out of this PR.

🤖 Claude Code (claude-opus-5-5)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That explanation addresses my concern. The error-rate limit cannot distinguish damaged keyframes from damaged skipped frames, and the existing caller guards reduce the risk of accepting unusably sparse results. I agree that a per-keyframe check would require a different signal and can be considered separately.

The remaining tradeoff is that partially damaged keyframe output can now be accepted in cases where FFmpeg 8.1 would previously have stopped the run. Given the documented behavior and guards, I would not block this PR on that concern.

@Quick104

Copy link
Copy Markdown
Contributor

Review summary

Reviewed head: ce88bd9

Evidence: https://evidence.siloserver.org/r/silo-server/pr-5604/

Fit: 9/10 · Readiness: 8/10 — conditional (assuming CI is green)

The fix holds. On an isolated sandbox with the release jellyfin-ffmpeg 8.1.3, a damaged episode's credits tail and credits fingerprint failed with exit 69 on the merge base, and the season stayed partial. Rebuilt from this branch with the same database, both complete, the season completes, and the episode gets a credits marker. The new real-FFmpeg test fails on the base with exit 69 and passes here under 8.1.3.

Addressed

  • Hardware attempts kept the lifted limit, so a GPU that fails decode frame after frame would no longer fall back to software, and the credits tail would store the result as sparse. Fixed in 807b4a8: only software attempts pass -max_error_rate 1. A damaged file on a hardware host fails the hardware attempt with exit 69 and succeeds in software, at the cost of a second decode of that window.
  • The Samples and Sheets paths had no test. ce88bd9 adds an argument test for the window, Samples, Sheets-list and Sheets-window builders under both attempt kinds. It fails on a2f37cf.

Left for the maintainers

  • Maintainer decision: undecodable tail audio above the two-thirds limit. The Chromaprint output receives only decoded samples, so the fingerprint points after a gap sit early, and a match there could put credits too early. Main already does this when less than two thirds of the audio fails. This branch extends it to combined tail runs where more than two thirds fails, which 8.1 used to reject and retry weekly. The options are to accept that (my recommendation, given how much audio has to fail), or to have the tail pass drop a fingerprint that comes out much shorter than its window. Filling audio gaps with silence would fix both cases, but it changes fingerprinting for every file and belongs in its own change.
  • Rows that earlier runs classified as permanent invalid_data stay unusable until the file changes. The issue's rows, and the base run here, were stored as retryable failed, so they pick up the fix on their next retry.
  • Trickplay window reads (read-through files such as AVI) carry the last image across keyframes that fail to decode and count those cells as decoded. That already happens on main below the limit; this branch also lets it through above it.

Checks

  • Validated features: no passed case on the v1.0 board reaches this change. Credits detection is Markers / skip intro & credits — Server #1148 C1, which is open and failing, so the PR body's Validation tasks: line stands.
  • User manual: unaffected. The markers page doesn't describe failure or retry handling, and no setting or default changes.
  • Other clients: N/A (server-side analysis only). jellycompat serves the same stored markers, so it needs no change.

Council

Member Round 1 (a2f37cf) Round 2 (807b4a8)
Sol (gpt-6.2-sol, medium) 6/10 7/10
Opus (claude-opus-5-5, medium) 7.5/10 8/10
Gemini (gemini-4-neon, medium) 9/10 8.5/10

ce88bd9 changes only the new test, as round 2 asked.

Fit is 9 because this repairs a core 1.0 analysis path at the boundary where FFmpeg's behavior changed, without new settings or surface. Readiness is 8 because the audio decision above is still open. With it accepted, nothing else blocks.

🤖 Claude Code (claude-opus-5-5)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update go code priority: P2 Limited scope, workaround exists, or polish size/M 50–199 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Credits tail pass fails every week with ffmpeg exit 69 on files whose last seconds are damaged

2 participants