Base64 to Video Converter

Free online tool to decode Base64 strings and convert them back to video files. Supports MP4, WebM, OGG, AVI, MOV, and other formats. Instant preview and download.

Why Use Base64 to Video Converter?

Instant Preview

Play and preview the decoded video before downloading

Auto Format Detection

Automatically detects video format from Base64 data

Secure & Private

All decoding happens in your browser. No data sent to servers.

One-Click Download

Download the decoded video file with proper file extension

Implementation Examples

Learn how to convert Base64 strings back to video files in your favorite programming language. All examples include complete, working code that you can use in your projects.

How to Convert Base64 to Video with JavaScript

// Convert Base64 to video and play
function base64ToVideo(base64String) {
  // Remove data URL prefix if present
  const base64 = base64String.replace(/^data:video\/[a-z0-9]+;base64,/, '');

  // Decode Base64 to binary
  const binaryString = atob(base64);
  const bytes = new Uint8Array(binaryString.length);

  for (let i = 0; i < binaryString.length; i++) {
    bytes[i] = binaryString.charCodeAt(i);
  }

  // Create blob and video element
  const blob = new Blob([bytes], { type: 'video/mp4' });
  const url = URL.createObjectURL(blob);

  const video = document.createElement('video');
  video.src = url;
  video.controls = true;
  video.play();

  return { video, url };
}

// Download Base64 as video file
function downloadBase64Video(base64String, filename = 'video.mp4') {
  const base64 = base64String.replace(/^data:video\/[a-z0-9]+;base64,/, '');
  const binaryString = atob(base64);
  const bytes = new Uint8Array(binaryString.length);

  for (let i = 0; i < binaryString.length; i++) {
    bytes[i] = binaryString.charCodeAt(i);
  }

  const blob = new Blob([bytes], { type: 'video/mp4' });
  const url = URL.createObjectURL(blob);

  const a = document.createElement('a');
  a.href = url;
  a.download = filename;
  a.click();

  URL.revokeObjectURL(url);
}

How to Convert Base64 to Video with Python

import base64
import cv2

# Convert Base64 to video file
def base64_to_video(base64_string, output_path):
    # Remove data URL prefix if present
    if 'base64,' in base64_string:
        base64_string = base64_string.split('base64,')[1]

    # Decode and save
    video_data = base64.b64decode(base64_string)

    with open(output_path, 'wb') as video_file:
        video_file.write(video_data)

    print(f"Video saved to {output_path}")

# Usage
base64_string = "AAAAIGZ0eXBpc29t..."  # Your Base64 string
base64_to_video(base64_string, "output.mp4")

# From JSON API response
import json
import requests

response = requests.get('https://api.example.com/video')
data = response.json()

base64_video = data['video']
base64_to_video(base64_video, "downloaded_video.mp4")

# Verify video file
cap = cv2.VideoCapture("output.mp4")
fps = cap.get(cv2.CAP_PROP_FPS)
frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
duration = frame_count / fps if fps > 0 else 0
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))

print(f"Duration: {duration} seconds")
print(f"Resolution: {width}x{height}")
cap.release()

How to Convert Base64 to Video with PHP

<?php
// Convert Base64 to video file
function base64ToVideo($base64String, $outputPath) {
    // Remove data URL prefix if present
    if (strpos($base64String, 'base64,') !== false) {
        $base64String = explode('base64,', $base64String)[1];
    }

    // Decode and save
    $videoData = base64_decode($base64String);
    file_put_contents($outputPath, $videoData);

    echo "Video saved to $outputPath\n";
}

// Usage
$base64String = "AAAAIGZ0eXBpc29t..."; // Your Base64 string
base64ToVideo($base64String, "output.mp4");

// From API response
$response = file_get_contents('https://api.example.com/video');
$data = json_decode($response, true);

base64ToVideo($data['video'], "downloaded_video.mp4");

// Stream video to browser
header('Content-Type: video/mp4');
header('Content-Disposition: attachment; filename="video.mp4"');

$base64 = $_POST['base64'];
echo base64_decode($base64);
?>

How to Convert Base64 to Video with Node.js

const fs = require('fs').promises;
const ffmpeg = require('fluent-ffmpeg');

// Convert Base64 to video file
async function base64ToVideo(base64String, outputPath) {
  // Remove data URL prefix if present
  const base64 = base64String.replace(/^data:video\/[a-z0-9]+;base64,/, '');

  // Decode and save
  const buffer = Buffer.from(base64, 'base64');
  await fs.writeFile(outputPath, buffer);

  console.log(`Video saved to ${outputPath}`);
}

// Usage
const base64String = "AAAAIGZ0eXBpc29t..."; // Your Base64 string
await base64ToVideo(base64String, 'output.mp4');

// Express.js API endpoint
const express = require('express');
const app = express();

app.post('/api/video/decode', express.json(), async (req, res) => {
  const { base64, filename = 'video.mp4' } = req.body;

  try {
    const buffer = Buffer.from(base64, 'base64');

    // Send as download
    res.setHeader('Content-Type', 'video/mp4');
    res.setHeader('Content-Disposition', `attachment; filename="${filename}"`);
    res.send(buffer);
  } catch (error) {
    res.status(400).json({ error: 'Invalid Base64 string' });
  }
});

// Stream large video files
const stream = require('stream');

app.get('/api/video/stream/:id', async (req, res) => {
  const base64 = await getVideoBase64(req.params.id);
  const buffer = Buffer.from(base64, 'base64');

  const readStream = stream.Readable.from(buffer);

  res.setHeader('Content-Type', 'video/mp4');
  res.setHeader('Accept-Ranges', 'bytes');
  readStream.pipe(res);
});

Share this tool

Help others discover this free Base64 tool

or