{"record":{"id":"485945b9bf12a674","repo":"affaan-m/ECC","slug":"decoder-produced-a-truncated-frame","errorCode":null,"errorMessage":"Decoder produced a truncated frame","messagePattern":"Decoder produced a truncated frame","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"skills/taste-application/scripts/tasteforge/media/glitch.py","lineNumber":64,"sourceCode":"        zoomed = np.asarray(z.crop((x0, y0, x0 + width, y0 + height)), dtype=np.float32)\n        decay = 0.90 + 0.06 * p\n        acc = np.maximum(f.astype(np.float32), zoomed * decay)\n        return acc.astype(np.uint8)\n\n    def fx_drift(f, p):\n        # subtle horizontal shift + RGB separation, very light\n        shift = int(rng.integers(2, 18) * p) * (1 if rng.random() < 0.5 else -1)\n        f = f.copy()\n        f[:, :, 0] = np.roll(f[:, :, 0], shift, axis=1)\n        f[:, :, 2] = np.roll(f[:, :, 2], -shift // 2, axis=1)\n        return f\n\n    while True:\n        buf = dec.stdout.read(frame_bytes)\n        if not buf:\n            break\n        if len(buf) != frame_bytes:\n            raise RuntimeError(\"Decoder produced a truncated frame\")\n        f = np.frombuffer(buf, np.uint8).reshape(height, width, 3).copy()\n        total = max(1, int(duration * fps))\n        p = min(1.0, (n + 1) / (total * 0.6))\n\n        if mode == \"pixelsort\":\n            out = fx_pixelsort(f, p)\n        elif mode == \"feedback\":\n            out = fx_feedback(f, p)\n        elif mode == \"drift\":\n            out = fx_drift(f, p)\n        else:\n            # very light mosh\n            out = f\n            y = 0\n            while y < height:\n                bh = int(rng.integers(8, 28))\n                if rng.random() < 0.12 * p:\n                    shift = int(rng.integers(4, 40) * p) * (","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/skills/taste-application/scripts/tasteforge/media/glitch.py#L46-L82","documentation":"transform_stream reads raw RGB frames from the ffmpeg decoder's stdout in exact frame_bytes chunks. If a read returns a partial chunk (neither empty nor a full frame), the frame would be malformed, so it raises RuntimeError('Decoder produced a truncated frame'). This guards against ffmpeg dying mid-frame or a pipe returning short reads.","triggerScenarios":"ffmpeg decoder process exits or is killed between full frames; a partial read from dec.stdout that returns fewer bytes than frame_bytes; corrupted/truncated source media ending mid-frame.","commonSituations":"ffmpeg crashing mid-decode (OOM, bad packet); source file truncated on disk; decoding a file whose advertised size exceeds actual bytes; platform pipe buffering edge cases.","solutions":["Validate the source media integrity first (ffprobe / try a full decode pass: ffmpeg -v error -i src -f null -)","Check ffmpeg's stderr for the real failure (codec errors, OOM kill, signal)","Re-encode/re-mux the input to a well-formed intermediate file before applying the glitch effect","Re-run; transient kills (OOM) may pass on a machine with more free memory or a lower width/height"],"exampleFix":"// before\nrender('truncated.mp4', ...)  # dies mid-frame\n// after\nsubprocess.run(['ffmpeg','-v','error','-y','-i','truncated.mp4','-c','copy','fixed.mp4'])\nrender('fixed.mp4', ...)","handlingStrategy":"validation","validationCode":"import subprocess\nr = subprocess.run(['ffmpeg','-v','error','-i', src,'-f','null','-'], capture_output=True)\nassert r.returncode == 0, r.stderr.decode()","typeGuard":null,"tryCatchPattern":"try:\n    render(src, 0, out)\nexcept RuntimeError as e:\n    if 'truncated frame' in str(e):\n        # re-mux or re-encode source before retrying\n        ...","preventionTips":["Pre-flight full decode of the source (ffmpeg -v error -i src -f null -)","Keep sufficient free memory; large width/height frames can OOM the decoder","Avoid truncated downloads — verify checksums of source media","Reduce output resolution if the machine is memory-constrained"],"tags":["media","ffmpeg","truncated-data"],"backgroundTag":"broken-pipe","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}