Base64 to Video
Decode Base64 strings to video files (MP4, WebM, OGG) and play them instantly in your browser. Also supports MP3, WAV, and audio files.
What Is Base64 Video Encoding?
Base64 is a binary-to-text encoding scheme that represents binary data — such as a video file — as a string of ASCII characters. Each group of 3 bytes from the original binary is encoded as 4 Base64 characters, using the alphabet A–Z, a–z, 0–9, +, and /. This makes it safe to transmit binary data through text-based channels like JSON payloads, HTML attributes, and email.
A Base64-encoded video is roughly 33% larger than the original binary file. For a 1 MB MP4, the Base64 string will be approximately 1.37 MB. This is a known trade-off when embedding media in text-based formats.
When Is Base64 Video Used?
- API responses — Machine learning vision APIs (Google Cloud Video Intelligence, AWS Rekognition) often return video clips or frame data as Base64 strings inside JSON responses.
- JSON payloads — When building REST APIs that need to transport binary media without a separate file upload endpoint, embedding as Base64 is a quick solution.
- Data URIs in HTML/CSS — Small video clips can be embedded directly in HTML using
data:video/mp4;base64,...as thesrcof a<video>element, eliminating an HTTP request. - WebRTC and real-time messaging — Some WebRTC implementations use Base64 to serialize video frames or thumbnails transmitted over data channels.
- Email and document attachments — MIME email attachments use Base64 to embed binary files inside plain-text email bodies.
- Document scanners and OCR tools — Many document processing pipelines store scanned pages as Base64-encoded video or image streams.
Supported Formats: MP4, WebM, OGG, MOV, MP3, WAV
This tool supports decoding Base64 strings for all major browser-playable media formats:
- MP4 (video/mp4) — The most universally compatible video format. Uses H.264 video and AAC audio. Supported by all modern browsers and devices including iOS Safari.
- WebM (video/webm) — Google's open container format using VP8/VP9 video and Vorbis/Opus audio. Excellent compression for web delivery. Supported in Chrome and Firefox natively.
- OGG (video/ogg) — Open-source format using Theora video and Vorbis audio. Less common today but fully supported in Firefox and Chrome.
- MOV (video/quicktime) — Apple's QuickTime container. Plays natively in Safari and macOS browsers.
- MP3 (audio/mpeg) — The most common audio format. This tool also decodes Base64 audio, not just video.
- WAV (audio/wav) — Uncompressed PCM audio. Large file sizes but lossless quality.
How to Decode Base64 to Video in JavaScript
Here is the correct, memory-safe approach using atob(), Blob, and URL.createObjectURL():
// Strip data URI prefix if present
const b64 = base64String.replace(/^data:[^;]+;base64,/, '');
// Decode Base64 to binary
const binary = atob(b64);
const bytes = new Uint8Array(binary.length);
for (let i = 0; i < binary.length; i++) {
bytes[i] = binary.charCodeAt(i);
}
// Create a Blob and a playable URL
const blob = new Blob([bytes], { type: 'video/mp4' });
const url = URL.createObjectURL(blob);
// Attach to a video element
const video = document.createElement('video');
video.src = url;
video.controls = true;
document.body.appendChild(video);
// Clean up when done
video.addEventListener('loadeddata', () => {
// Video is ready to play
});
// Later, free memory:
// URL.revokeObjectURL(url); Using a Blob URL is always preferable to embedding the Base64 string directly as a data URI in the src attribute, because it avoids re-encoding the data and is far more memory-efficient for large files.
How to Decode Base64 to Video in Python
Python's built-in base64 module makes this straightforward:
import base64
# If you have a raw Base64 string:
base64_str = "AAAAIGZ0eXBpc29tAA..."
# Decode and write to file
video_data = base64.b64decode(base64_str)
with open("output.mp4", "wb") as f:
f.write(video_data)
# If your string has a data URI prefix (data:video/mp4;base64,...):
if "," in base64_str:
base64_str = base64_str.split(",", 1)[1]
video_data = base64.b64decode(base64_str) For large files, consider using base64.b64decode(base64_str, validate=True) to catch invalid characters before writing.
Base64 Video in API Responses
Base64-encoded video is especially common in responses from machine learning and computer vision APIs. Google Cloud's Video Intelligence API can return video segment data as Base64 strings. AWS Rekognition Video, document scanner SDKs, and mobile OCR libraries frequently serialize video frames or short clips as Base64 for transmission in JSON. When debugging these integrations, paste the Base64 value from the API response directly into this tool to instantly preview the video without writing any code.
Need to go the other direction? Use our Base64 to Audio tool for audio-only files, our Base64 Decoder for text data, or our Base64 Encoder to encode files to Base64.
Frequently Asked Questions
How do I play a Base64 video in HTML without a server?
Paste your Base64 string into this tool and click Decode & Play. The tool creates a Blob URL entirely in your browser — no server needed. You can also embed it directly in HTML using a data URI as the src attribute of a video element. Note that large data URIs can slow down page loads; Blob URLs are more efficient for larger files.
How do I convert Base64 to MP4 in Python?
Use Python's built-in base64 module: import base64; data = base64.b64decode(your_base64_string); open('output.mp4', 'wb').write(data). If your string starts with a data URI prefix like 'data:video/mp4;base64,', strip it first: your_base64_string = your_base64_string.split(',', 1)[1].
How do I decode Base64 video in JavaScript?
Use atob() to decode the Base64 string to binary, then create a Uint8Array, a Blob with the correct MIME type, and a Blob URL with URL.createObjectURL(). Assign the Blob URL to a video element's src attribute. Always revoke the Blob URL with URL.revokeObjectURL() when done to free memory.
What MIME type should I use for Base64 video?
Use video/mp4 for MP4 files (most browser-compatible), video/webm for WebM, video/ogg for OGG Theora, and video/quicktime for MOV files. For audio, use audio/mpeg for MP3 and audio/wav for WAV. If you are unsure, use the Auto-detect option — this tool will read the data URI prefix automatically.
Why is my Base64 video not playing in the browser?
Common causes: (1) Wrong MIME type — the browser needs to know the codec. Try switching from MP4 to WebM or vice versa. (2) The Base64 string is corrupted or has extra whitespace — the tool trims whitespace automatically. (3) The codec is not supported by your browser — Chrome and Firefox support H.264/MP4 and VP8/WebM; Safari needs H.264/MP4. (4) The original video was not properly encoded to Base64 — re-encode it using our Video to Base64 tool.
What is the maximum file size for Base64 video data URIs?
Browsers typically handle Blob URLs up to several hundred MB depending on available RAM, but data URIs embedded directly in HTML are limited to a few MB in most browsers before performance degrades. This tool uses Blob URLs rather than data URIs for playback, which is more memory-efficient. For very large video files, use a direct file path or CDN URL instead.
How do I get a Base64 string from a video file?
Use our Video to Base64 tool at visualdevtools.com/en/tools/video-to-base64 to convert any MP4, WebM, or MOV file to a Base64 string directly in your browser. In Python: import base64; print(base64.b64encode(open('video.mp4','rb').read()).decode()). In JavaScript: use a FileReader with readAsDataURL().
What is the difference between base64 to mp4 and base64 to webm?
The Base64 encoding process is identical — the difference is only in the MIME type and the original video codec. MP4 (video/mp4) uses H.264 video and AAC audio, which is universally supported across all browsers and devices. WebM (video/webm) uses VP8 or VP9 video with Vorbis or Opus audio and is an open-source format preferred for web delivery. Use MP4 for maximum compatibility; use WebM for smaller file sizes and open-source workflows.
Comments
No comments yet. Be the first!