invoke-ai/InvokeAI · error · ValueError
Decoded only {num_frames} of {expected_frames} requested fra
Error message
Decoded only {num_frames} of {expected_frames} requested frames for range {start}-{end} of {self.video.video_name} (probed {n_frames} frames). The container's metadata may be inaccurate. What it means
Raised after decoding when the number of frames actually written to the output clip is fewer than end - start + 1. The container advertised enough frames during probing but the decoder could not produce them all, so the library refuses to emit a short, silently-trimmed clip and warns that container metadata may be wrong.
Source
Thrown at invokeai/app/invocations/video_frame_extract_range.py:203
tmp_path = Path(tmp.name)
try:
# imageio's iter_index isn't exposed by iio.imiter, so we enumerate and skip.
# Frames stream straight from the decoder into the encoder; see _write_frame_range.
writer = make_mp4_writer(tmp_path, output_fps)
try:
num_frames = _write_frame_range(
iter_video_frames(video_path, is_canceled=context.util.is_canceled),
writer,
start,
end,
is_canceled=context.util.is_canceled,
)
finally:
writer.close()
expected_frames = end - start + 1
if num_frames != expected_frames:
raise ValueError(
f"Decoded only {num_frames} of {expected_frames} requested frames for range {start}-{end} "
f"of {self.video.video_name} "
f"(probed {n_frames} frames). The container's metadata may be inaccurate."
)
out_duration = num_frames / output_fps
context.logger.info(
f"Encoded trimmed MP4: {num_frames} frames @ {output_fps:.2f} fps "
f"({out_duration:.2f}s) at {width}x{height}"
)
video_dto = context.videos.save(
source_path=tmp_path,
width=width,
height=height,
duration=out_duration,
fps=output_fps,
)
context.logger.info(f"Saved trimmed video: {video_dto.video_name}")View on GitHub (pinned to 0b6a024f2f)
Solutions
- Re-encode the video with ffmpeg (e.g. ffmpeg -i in.mp4 -c:v libx264 out.mp4) to rebuild accurate metadata
- Verify the file is complete/re-download it; probe with ffprobe -count_frames to see the true frame count
- Reduce end_frame so the requested range fits within actually decodable frames
- Check available disk space and decode logs for codec errors
Example fix
// before # truncated video, end_frame=-1 requests all 'probed' frames that don't decode // after # repair metadata first # ffmpeg -i broken.mp4 -c copy fixed.mp4 (or full re-encode), then retry
Defensive patterns
Strategy: try-catch
Validate before calling
true_count = int(subprocess.check_output(['ffprobe','-v','error','-count_frames','-select_streams','v:0','-show_entries','stream=nb_read_frames','-of','csv=p=0', video_path]))
if end - start + 1 > true_count:
end = true_count - 1 Type guard
def range_fully_decodable(start: int, end: int, true_frame_count: int) -> bool:
return 0 <= start and end - start + 1 <= true_frame_count Try / catch
try:
clip = invocation.invoke(context)
except ValueError as e:
if "Decoded only" in str(e):
# re-encode to repair metadata, then retry
subprocess.run(['ffmpeg','-y','-i',src,'-c:v','libx264',fixed])
invocation.video = load(fixed)
clip = invocation.invoke(context)
else:
raise Prevention
- Verify downloads are complete (checksums) before extraction
- Run ffprobe -count_frames to detect metadata/actual mismatches early
- Re-encode suspicious videos with ffmpeg before use
- Avoid end_frame=-1 on files from untrusted/partial sources
When it happens
Trigger: invoke() decoding a range whose expected_frames = end - start + 1 exceeds what the decoder actually yields: truncated/corrupt video files, broken keyframe indexes, videos whose header reports more frames than physically exist, or codec failures mid-stream.
Common situations: Downloading partial MP4s (cut off mid-file), screen recordings with corrupted moov metadata, re-encoded videos with inaccurate frame counts in metadata, remote/network-stored videos that failed to fully transfer.
Related errors
- Video has no decodable frame
- Video metadata not found
- Video reports invalid dimensions {width}x{height}
- Video at {video_path} reports an invalid duration {duration}
- Video must use a browser-compatible H.264/AVC codec
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/3e1fa2e80e6b534b.
Report an issue: GitHub.