How to convert MP4 to Base64
- Drop an
.mp4file on the box or pick it with the file picker. - Play it in the preview. If it does not play here, it probably will not play from a data URI in this browser either.
- Keep Output as on Data URI for
<video>tags, or pick Plain Base64 or JSON for APIs. - Copy output, or Save as .txt for big files.
Encoded length per bitrate
MP4 size is roughly bitrate × duration. For a 10-second clip:
| Total bitrate | File size | Base64 length |
|---|---|---|
| 0.5 Mbps | 625,000 bytes | 833,336 chars |
| 1 Mbps | 1,250,000 bytes | 1,666,668 chars |
| 2.5 Mbps | 3,125,000 bytes | 4,166,668 chars |
| 5 Mbps | 6,250,000 bytes | 8,333,336 chars |
Phone recordings often run at 10 Mbps or more, so ten seconds of untouched phone video already produce more than 16 million characters. Re-encode at a lower resolution and bitrate first; Video to Base64 has a tested ffmpeg command for that.
The ftyp brand in the first characters
The first box of an MP4 declares a major brand, which tells players which specification the file follows. It is visible in the Base64:
| Brand | Meaning | Base64 (32-byte ftyp box) |
|---|---|---|
isom | ISO base media file, the generic brand (ffmpeg’s default) | AAAAIGZ0eXBpc29t |
mp42 | MP4 version 2 | AAAAIGZ0eXBtcDQy |
M4V | Apple’s MP4 video variant | AAAAIGZ0eXBNNFYg |
qt | QuickTime movie (.mov) | AAAAIGZ0eXBxdCAg |
The fifth character changes with the box size (G for 24 bytes, H for 28, I for 32), so detection code should look for GZ0eXB after the first five characters. A file with brand qt is really a QuickTime movie with an .mp4 name; it may still play, but label it video/quicktime if the receiver checks.
Embedding and sending
A short muted loop in a self-contained HTML page:
<video autoplay muted loop playsinline src="data:video/mp4;base64,AAAAIGZ0eXBpc29tAAACAGlzb21p..."></video>
Sending a clip in a JSON request from Node.js:
import { readFile } from "node:fs/promises";
const video = await readFile("clip.mp4");
const body = JSON.stringify({
mimeType: "video/mp4",
data: video.toString("base64"),
});
The field names here are placeholders; use the ones from your API’s documentation. More in Base64 in Node.js.
Problems you might hit
- The data URI plays in Safari but not in Chrome or Firefox. The video track is probably HEVC. Re-encode to H.264.
- The page freezes while loading. The browser is parsing a huge string. Data URIs above a few megabytes are better replaced by a file URL or a Blob URL.
- The receiver says the file is corrupt. Compare the decoded length with the original file size in the meter; a truncated string cuts off the end of the file, where many MP4s keep their index. Base64 to MP4 shows whether the decoded clip plays.
FAQ
Why does my MP4 Base64 start with AAAA?
An MP4 opens with the size of its first box, ftyp, as a 4-byte number. The first three bytes are zero for any normal header, and zero bytes encode to A. The ftyp box name and the brand follow, e.g. AAAAIGZ0eXBpc29t for brand isom.
Will my MP4 play from a data URI in every browser?
If it uses H.264 video and AAC audio, yes. MP4 files with HEVC (H.265) play in Safari and only in some other browsers, depending on the system. The container alone does not guarantee playback.
How do I send an MP4 to an API as Base64?
Choose Plain Base64 unless the API documents a data URI, and send video/mp4 as the media type. Check the API’s size limit against the encoded length, which is a third larger than the file.