{"record":{"id":"578347e815b3c873","repo":"langchain-ai/deepagents","slug":"video-frame-output-exceeded-the-max-video-emitted","errorCode":null,"errorMessage":"Video frame output exceeded the {MAX_VIDEO_EMITTED_BYTES} byte safety budget before emitting a frame","messagePattern":"Video frame output exceeded the (.+?) byte safety budget before emitting a frame","errorType":"exception","errorClass":"VideoExtractionError","httpStatus":null,"severity":"error","filePath":"libs/deepagents/deepagents/middleware/_video.py","lineNumber":343,"sourceCode":"            if frame_seconds is None:\n                continue\n            if frame_seconds >= end_seconds:\n                break\n            if frame_seconds + 1e-6 < next_emit_seconds:\n                continue\n            if emitted_frames >= MAX_VIDEO_SAMPLED_FRAMES:\n                truncated = True\n                break\n\n            jpeg_bytes = _encode_jpeg(frame)\n            image_base64 = base64.b64encode(jpeg_bytes)\n            ts = _format_timestamp(frame_seconds)\n            text = f\"Frame at t={ts}\"\n            next_block_bytes = len(text.encode()) + len(image_base64)\n            if emitted_bytes + next_block_bytes > MAX_VIDEO_EMITTED_BYTES:\n                if emitted_frames == 0:\n                    msg = f\"Video frame output exceeded the {MAX_VIDEO_EMITTED_BYTES} byte safety budget before emitting a frame\"\n                    raise VideoExtractionError(msg)\n                truncated = True\n                break\n\n            blocks.append({\"type\": \"text\", \"text\": text})\n            blocks.append(\n                {\n                    \"type\": \"image\",\n                    \"base64\": image_base64.decode(\"ascii\"),\n                    \"mime_type\": \"image/jpeg\",\n                }\n            )\n            emitted_frames += 1\n            emitted_bytes += next_block_bytes\n            last_emitted_seconds = frame_seconds\n            emitted_index = math.floor((frame_seconds - offset_seconds) / frame_interval_seconds) + 1\n            next_emit_seconds = max(\n                next_emit_seconds + frame_interval_seconds,\n                offset_seconds + frame_interval_seconds * emitted_index,","sourceCodeStart":325,"sourceCodeEnd":361,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/deepagents/deepagents/middleware/_video.py#L325-L361","documentation":"Extraction enforces a cumulative output budget of `MAX_VIDEO_EMITTED_BYTES`. If the very first frame block (text + base64 JPEG) already exceeds that budget, `_sample_frames_in_window` raises `VideoExtractionError` because emitting zero frames plus a truncation notice would be useless.","triggerScenarios":"Frames so large (high resolution -> big base64 JPEGs) that a single frame's block exceeds the total byte budget.","commonSituations":"8K/4K source video with high JPEG quality; crafted videos meant to blow up context size; very low budget constant combined with huge frames.","solutions":["Lower the source resolution before extraction so each frame's base64 fits the budget","Use a smaller sampling window/rate to reduce frames (does not help if the first frame alone is too big — must shrink the frame itself)","Catch `VideoExtractionError` and handle the video without inline frames"],"exampleFix":"// before\nframes = extract_video_frames(bytes_4k, offset_seconds=0, duration_seconds=10, sampling_rate=1)\n// after\nsmaller = transcode_to_720p(bytes_4k)\nframes = extract_video_frames(smaller, offset_seconds=0, duration_seconds=10, sampling_rate=1)","handlingStrategy":"validation","validationCode":"w, h = probe_dimensions(content)\nestimated_frame_bytes = (w * h * 3) * 4 // 3  # rough base64 JPEG upper bound\nif estimated_frame_bytes > MAX_VIDEO_EMITTED_BYTES:\n    raise ValueError(\"frame too large for output budget; downscale first\")","typeGuard":null,"tryCatchPattern":"try:\n    result = extract_video_frames(content, offset_seconds=0, duration_seconds=10, sampling_rate=1)\nexcept VideoExtractionError as exc:\n    if \"byte safety budget\" in str(exc):\n        result = extract_video_frames(downscale_to_720p(content), offset_seconds=0, duration_seconds=10, sampling_rate=1)","preventionTips":["Transcode high-resolution sources to <=1080p before extraction","Keep per-frame JPEG size well under the emitted-bytes budget","Budget context: fewer, smaller frames beat many large ones"],"tags":["video","resource-limit","payload-size","encoding"],"backgroundTag":"payload-size-exceeded","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}