opencode icon indicating copy to clipboard operation
opencode copied to clipboard

feat(opencode): add native video and audio file reading support

Open mugnimaestra opened this issue 8 months ago • 6 comments

🎬 Community requested feature — Issue #10531 has 7 upvotes and 9 comments requesting native video/audio support. This PR implements it.

Issue for this PR

Closes #10531

Type of change

  • [ ] Bug fix
  • [x] New feature
  • [ ] Refactor / code improvement
  • [ ] Documentation

What does this PR do?

Adds native video and audio file reading to the read tool. When a model-capable provider (e.g. Kimi K2.5 via Chutes) asks to read a video or audio file, it's base64-encoded and returned as a file attachment — same pattern as existing PDF/image support.

Three changes:

  1. read.ts — Detect video/* and audio/* MIME types on binary files, return as base64 attachment (20MB cap). Moved the binary file check before MIME detection to prevent .ts files (MIME video/mp2t) from being misdetected.

  2. message-v2.ts — Extended isMedia() to include video/* and audio/* so compaction handles them correctly.

  3. @ai-sdk/openai-compatible patch — The bundled v1.0.32 only handles image/* in its chat converter. This patch adds video_url and input_audio types for OpenAI-compatible providers that support video (like Kimi K2.5).

Related: #16338 (same package fails for PDF — a follow-up patch could cover that too).

20MB file size limit

Files over 20MB are rejected with a clear error message. This is the safe lowest-common-denominator across LLM providers:

Provider Inline Limit
OpenAI 20MB (images), 25MB (audio)
Anthropic 30MB per file, 32MB max request
Gemini (legacy) 20MB inline (now 100MB)

There is currently no built-in tool to compress oversized media — users can rely on the model invoking ffmpeg via the bash tool if installed.

How did you verify your code works?

  • Tested end-to-end with Kimi K2.5 via Chutes (OpenAI-compatible provider)
  • Read a 1.5MB MP4 file through the read tool — model successfully described video content
  • Verified .ts files are still read as text (not misdetected as video)
  • Verified files over 20MB are rejected with clear error message
  • Added 9 new tests (4 for read tool, 5 for isMedia) — all pass
  • Existing test suite passes (39/39 read tests, 24/24 message-v2 tests)
  • bun typecheck passes with zero errors

Screenshots / recordings

Session transcript: https://gist.github.com/mugnimaestra/fd39a67ca38e0551287c0da93aa20bef

Checklist

  • [x] I have tested my changes locally
  • [x] I have not included unrelated changes in this PR

mugnimaestra avatar Mar 17 '26 22:03 mugnimaestra

👋 Hey @kitlangton @adamdotdevin @rekram1-node — this implements a community-requested feature (#10531, 7 upvotes) for native video and audio reading support.

It follows the exact same pattern as existing PDF/image support in the read tool, with a 20MB safety cap and 9 new tests. Would love a review when you get a chance! 🙏

mugnimaestra avatar Mar 18 '26 02:03 mugnimaestra

💡 Workaround for files over 20MB

If your video exceeds the 20MB limit, you can use the video-frames skill as an alternative — it extracts key frames from video files using ffmpeg for LLM analysis, without needing to attach the full video.

Install it with:

npx skills add mugnimaestra/video-frames-skill

This lets you analyze large videos by converting them into representative JPEG frames that fit well within context limits.

mugnimaestra avatar Mar 18 '26 02:03 mugnimaestra

This is a very important feature

fengwk avatar Mar 31 '26 07:03 fengwk

This is a nice feature addition. Is there any ETA?

ayulockin avatar Apr 30 '26 13:04 ayulockin

It's very clear that we all need it. It shouldn't be so hard to implement.

MuziCodes avatar Jun 10 '26 18:06 MuziCodes

+1 on this. Would really like to see this merged.

MoodyMarshmallow avatar Jun 14 '26 16:06 MoodyMarshmallow