Skip to content

Add video file validation before transcoding to detect corrupt files early#386

Merged
ShaneIsrael merged 4 commits intodevelopfrom
copilot/fix-transcoding-corrupt-file-issue
Jan 17, 2026
Merged

Add video file validation before transcoding to detect corrupt files early#386
ShaneIsrael merged 4 commits intodevelopfrom
copilot/fix-transcoding-corrupt-file-issue

Conversation

Copy link
Contributor

Copilot AI commented Jan 17, 2026

Corrupt video files cause all encoder fallbacks (AV1 NVENC → H.264 NVENC → AV1 CPU → H.264 CPU) to fail sequentially with decode errors like "No sequence header" or "Corrupt frame detected". This wastes time and resources attempting encoders that will never succeed.

Changes

  • New validate_video_file() function — Performs quick validation before transcoding:

    • Uses ffprobe to verify stream metadata is readable
    • Decodes first 2 seconds to catch corruption early
    • Returns (is_valid, error_message) tuple
  • Module-level VIDEO_CORRUPTION_INDICATORS — Known ffmpeg error patterns indicating file corruption

  • Integration in transcode_video_quality() — Validates source before attempting any encoder; returns False immediately for corrupt files with clear error logging

Example behavior

Before:

Trying AV1 NVENC...
✗ AV1 NVENC failed with exit code 69
Trying H.264 NVENC...
✗ H.264 NVENC failed with exit code 69
Trying AV1 CPU...
✗ AV1 CPU failed with exit code 69
Trying H.264 CPU...
✗ H.264 CPU failed with exit code 69
ERROR: No working GPU encoder found

After:

ERROR: Source video validation failed: Video file appears to be corrupt: No sequence header
WARNING: Skipping transcoding for this video due to file corruption or read errors
Original prompt

Sometimes during transcoding this error gets spit out, and it seems to potentially only happen with some files or right after the app is started. It will transcode other files fine and use GPU AV1. I'm wondering if maybe its a corrupted file issue and if there needs to be some sort of check before it attempts to transcode a file.

[libaom-av1 @ 0x55c188057880] Failed to decode frame: Corrupt frame detected
[libaom-av1 @ 0x55c188057880] Additional information: No sequence header
[vist#0:0/av1 @ 0x55c188109d40] Error submitting packet to decoder: Invalid data found when processing input
[libaom-av1 @ 0x55c188057880] Failed to decode frame: Corrupt frame detected
[libaom-av1 @ 0x55c188057880] Additional information: No sequence header
[vist#0:0/av1 @ 0x55c188109d40] Error submitting packet to decoder: Invalid data found when processing input
Cannot determine format of input stream 0:0 after EOF
Error marking filters as finished
Error while filtering: Invalid data found when processing input
[vist#0:0/av1 @ 0x55c188109d40] Decode error rate 1 exceeds maximum 0.666667
[out#0/mp4 @ 0x55c188055440] Nothing was written into output file, because at least one of its streams received no packets.
2026-01-17 16:45:13,856 WARNING util.transcode_video_quality:503 | ✗ H.264 CPU failed with exit code 69
2026-01-17 16:45:13,857 ERROR util.transcode_video_quality:535 | No working GPU encoder found for video. Tried: AV1 NVENC, H.264 NVENC, AV1 CPU, H.264 CPU
2026-01-17 16:45:13,857 ERROR util.transcode_video_quality:537 | Last error was: Transcode failed with exit code 69
2026-01-17 16:45:13,857 WARNING cli.transcode_videos:576 | Skipping video 034fa386


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Fix transcoding errors for corrupt files Add video file validation before transcoding to detect corrupt files early Jan 17, 2026
Copilot AI requested a review from ShaneIsrael January 17, 2026 23:58
@ShaneIsrael ShaneIsrael marked this pull request as ready for review January 17, 2026 23:59
@ShaneIsrael ShaneIsrael merged commit 1cf3611 into develop Jan 17, 2026
@ShaneIsrael ShaneIsrael deleted the copilot/fix-transcoding-corrupt-file-issue branch January 31, 2026 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants