Skip to content

feat(send): send an MP4 or MOV file as a video - #238

Open
ertembiyik wants to merge 1 commit into
neoromantic:mainfrom
ertembiyik:ertembiyik/send-video
Open

ertembiyik wants to merge 1 commit into
neoromantic:mainfrom
ertembiyik:ertembiyik/send-video

Conversation

@ertembiyik

@ertembiyik ertembiyik commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What and why

tg send --file clip.mp4 posts a video as a file to download: every non-photo upload sets force_file (d50d90d), so nothing plays in the chat, and there is no way around it, since tg api can't upload. An MP4 or MOV file now goes as a video, the way JPEG, PNG and WebP images go as photos. --force-document sends it as a file, as before.

Before (0.16.0, trimmed)

$ tg send --to me --file ./clip.mp4
"file": { "name": "clip.mp4", "mimeType": "video/mp4", "size": 51278, "sentAs": "document" }
"attachment": { "kind": "document", "duration": null, "width": null, "height": null }

After

$ tg send --to me --file ./clip.mp4
"file": { "name": "clip.mp4", "mimeType": "video/mp4", "size": 51278, "sentAs": "video" }
"attachment": { "kind": "video", "duration": 3, "width": 640, "height": 360 }

How it works

  • src/utils/video-metadata.ts reads the file's moov box: the duration from mvhd, the frame size from the video track's tkhd, swapped when the video is stored sideways (a phone held upright). About 120 lines, no dependency and no ffmpeg.
  • The upload is inputMediaUploadedDocument with documentAttributeVideo and the file name, without force_file. supports_streaming is set only when moov comes before mdat.
  • The file is uploaded as it is. The schema has no quality option for an upload, so there is no flag for one.
  • No thumbnail is uploaded: Telegram makes it.
  • Everything else is unchanged: a file that isn't video/*, has no video track or is cut short goes as a document. WebM and MKV stay documents.

Yours to decide

This changes the default for existing callers: an MP4 that arrived as a file now arrives as a video. I followed the rule photos already have (by type, --force-document to opt out). If you prefer opt-in, say so and I'll put it behind a flag: it is one condition in sendFile.

Independent of #239 (a caption formatted with --html). Both edit the same paragraphs of docs/media.md and docs/cli-commands.md; I will merge main into whichever is left after the first one lands.

How I checked it

  • Unit tests: the reader on made-up MP4 bytes (32- and 64-bit times, sideways, data before the index, no video track, another format, a cut file); the messages.sendMedia request for a video, for --force-document and for a video file that can't be read.

  • The reader against real encoder output, locally: MP4, MOV, a rotated clip, one without faststart, a fragmented one, an audio-only M4A and a WebM, compared with ffprobe.

  • Live, one send to Saved Messages of a 3-second 640×360 test clip: sentAs: "video"; the stored message has the video flag, documentAttributeVideo with duration 3, 640×360 and supports_streaming, and two thumbnails Telegram made.

  • bun run check, bun run test (1346 pass), bun run test:e2e (438 pass).

  • Not covered: the live suite still sends only made-up bytes as a document. A video without sound wasn't tried. A fragmented MP4 is sent with duration 0, since its mvhd has none.

  • Tests pass locally and use made-up data only

  • README, docs and affected demos follow the product content standard

  • Title follows the repo's commit style: Conventional Commits (feat: …, fix: …) unless AGENTS.md says otherwise

🤖 Generated with Claude Code

tg send --file sent every non-photo file with force_file, so a video
arrived as a file to download and never played in the chat. A file whose
video track can be read now goes with documentAttributeVideo: duration and
frame size come from its moov box, supports_streaming is set when the
index precedes the data. The file is uploaded as it is. --force-document
keeps the old result, and a video file that cannot be read stays a
document.

Co-Authored-By: Claude Fable 5.2 <[email protected]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant