Handle damaged originals that kept failing after Retry #8
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/damaged-originals"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Requested by Kees · project thread
states a longer one, so samples land inside the video.
producing an empty lossless reference (EBML 'End of file').
video packets after the copy's end) is kept with a note.
Matroska.
Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_018FuQsp6G2DpZQdmAMJuPU3
Tests: 182 pass (10 new, some with real ffmpeg on a cut-off file) in a clean checkout off the box.
🤖 Generated with Claude Code
https://claude.ai/code/session_018FuQsp6G2DpZQdmAMJuPU3
Title
Handle damaged originals that kept failing after Retry
PR Type
Bug fix, Enhancement
Description
Use video stream duration to fix samples landing outside video in damaged files.
Keep copies of cut-off originals instead of failing them with bad duration errors.
Exclude unknown subtitle codecs and force Matroska container for .ts files.
Retry logic now moves sample starts earlier when encountering empty references.
Diagram Walkthrough
File Walkthrough
1 files
Add stream duration parsing and video packet checking functions2 files
Retry sample cuts when encountering empty lossless referencesPass bad_subs to encoder and handle cut-off original copies2 files
Add comprehensive tests for damaged sources and cut-off filesUpdate worker fallback tests to include video_packets_after mock2 files
Display reason messages for staged and confirmed file statusesDocument fixes for damaged originals and cut-off downloads3 finding(s) as line comments; the review comment lists all of them.
@ -14,0 +22,4 @@if not tag:return Nonetry:h, m, sec = tag.split(":")Integer overflow in duration parsing ·
KK-66b658a0de· lowThe stream_duration function parses the DURATION tag by splitting on ":" and converting parts to int/float. If the DURATION tag contains an invalid format like "999999999999:999999999999:999999999999", the calculation int(h) * 3600 + int(m) * 60 + float(sec) could result in an extremely large number that exceeds Python's integer limits in other languages or causes unexpected behavior. While Python handles large integers, this could lead to incorrect duration values being used for sample positioning.
Reply
not an issue,false positiveorwon't fixto dismiss it; it is then not reported again.@ -14,0 +37,4 @@["nice", "-n", "19", "ionice", "-c", "3", "ffprobe", "-v", "error", "-select_streams", f"v:{video_index}","-show_entries", "packet=pts_time", "-of", "csv=p=0", "-read_intervals", f"{max(0.0, t):.3f}%+{span:g}",path],capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=120)Subprocess timeout risk ·
KK-d4906bdf60· lowThe video_packets_after function calls ffprobe with a hardcoded 120-second timeout. If the file is large or the system is under heavy load, ffprobe may take longer than 120 seconds to complete, causing the subprocess to be killed prematurely. This would return True (assuming more video exists), potentially leading to incorrect duration calculations or unnecessary retries.
Reply
not an issue,false positiveorwon't fixto dismiss it; it is then not reported again.@ -0,0 +76,4 @@with open(cls.cut, "wb") as f:f.write(data[: len(data) // 2])@classmethodTest file cleanup incomplete ·
KK-9ccee64fa5· lowThe RealFiles test class creates temporary files in setUpClass but only removes them in tearDownClass. If the test suite is interrupted or fails between setUpClass and tearDownClass, the temporary directory and its contents will not be cleaned up, potentially causing disk space issues or leaving orphaned files on the system.
Reply
not an issue,false positiveorwon't fixto dismiss it; it is then not reported again.PR Reviewer Guide 🔍
📋 Focus areas: 🔴 3 open · ✅ 0 handled. Every push re-checks them; a handled area moves to Resolved findings at the bottom.
Subprocess timeout risk
The video_packets_after function calls ffprobe with a hardcoded 120-second timeout. If the file is large or the system is under heavy load, ffprobe may take longer than 120 seconds to complete, causing the subprocess to be killed prematurely. This would return True (assuming more video exists), potentially leading to incorrect duration calculations or unnecessary retries.
Integer overflow in duration parsing
The stream_duration function parses the DURATION tag by splitting on ":" and converting parts to int/float. If the DURATION tag contains an invalid format like "999999999999:999999999999:999999999999", the calculation int(h) * 3600 + int(m) * 60 + float(sec) could result in an extremely large number that exceeds Python's integer limits in other languages or causes unexpected behavior. While Python handles large integers, this could lead to incorrect duration values being used for sample positioning.
Test file cleanup incomplete
The RealFiles test class creates temporary files in setUpClass but only removes them in tearDownClass. If the test suite is interrupted or fails between setUpClass and tearDownClass, the temporary directory and its contents will not be cleaned up, potentially causing disk space issues or leaving orphaned files on the system.
🗂️ Finding ids (reply with the id and
not an issue,false positiveorwon't fixto dismiss one; it is then not reported again):KK-d4906bdf60app/rx_media.py:40KK-66b658a0deapp/rx_media.py:25KK-9ccee64fa5tests/test_damaged_sources.py:79