Video to Base64 Converter

Free online tool to convert video files (MP4, WebM, OGG, AVI, MOV) to Base64 format. Perfect for embedding videos in JSON, HTML, or CSS. Fast, secure, and works entirely in your browser.

Why Use Video to Base64 Converter?

Multiple Format Support

Supports MP4, WebM, OGG, AVI, MOV, and other popular video formats

Instant Preview

Play and preview your video before and after conversion

Secure & Private

All processing happens in your browser. No files uploaded to servers.

Large File Support

Convert video files up to 100MB in size

Implementation Examples

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

How to Convert Video to Base64 with JavaScript

// Convert video file to Base64
function videoToBase64(file) {
  return new Promise((resolve, reject) => {
    const reader = new FileReader();
    reader.onload = () => {
      const base64 = reader.result; // Includes data URL prefix
      resolve(base64);
    };
    reader.onerror = reject;
    reader.readAsDataURL(file);
  });
}

// Usage with file input
document.querySelector('input[type="file"]').addEventListener('change', async (e) => {
  const file = e.target.files[0];
  const base64 = await videoToBase64(file);
  console.log(base64); // data:video/mp4;base64,AAAAIGZ0eXBpc29t...

  // Get only Base64 string (without prefix)
  const base64Only = base64.split(',')[1];
});

// Get video duration and dimensions
function getVideoMetadata(file) {
  return new Promise((resolve) => {
    const video = document.createElement('video');
    video.preload = 'metadata';
    video.src = URL.createObjectURL(file);
    video.onloadedmetadata = () => {
      resolve({
        duration: video.duration,
        width: video.videoWidth,
        height: video.videoHeight
      });
      URL.revokeObjectURL(video.src);
    };
  });
}

How to Convert Video to Base64 with Python

import base64
import cv2

# Convert video file to Base64
def video_to_base64(video_path):
    with open(video_path, "rb") as video_file:
        encoded = base64.b64encode(video_file.read())
        return encoded.decode('utf-8')

# Usage
base64_string = video_to_base64("movie.mp4")
print(f"data:video/mp4;base64,{base64_string}")

# Get video info with OpenCV
def get_video_info(video_path):
    cap = cv2.VideoCapture(video_path)

    fps = cap.get(cv2.CAP_PROP_FPS)
    frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
    width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
    height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
    duration = frame_count / fps if fps > 0 else 0

    cap.release()

    return {
        'duration': duration,
        'width': width,
        'height': height,
        'fps': fps,
        'frame_count': frame_count
    }

info = get_video_info("movie.mp4")
print(f"Duration: {info['duration']} seconds")
print(f"Resolution: {info['width']}x{info['height']}")

How to Convert Video to Base64 with PHP

<?php
// Convert video file to Base64
function videoToBase64($videoPath) {
    $videoData = file_get_contents($videoPath);
    $base64 = base64_encode($videoData);

    // Get MIME type
    $finfo = finfo_open(FILEINFO_MIME_TYPE);
    $mimeType = finfo_file($finfo, $videoPath);
    finfo_close($finfo);

    return "data:$mimeType;base64,$base64";
}

// Usage
$dataUrl = videoToBase64("movie.mp4");
echo $dataUrl;

// Get file size
$fileSize = filesize("movie.mp4");
echo "File size: " . ($fileSize / 1024 / 1024) . " MB";

// For API response
header('Content-Type: application/json');
echo json_encode([
    'video' => base64_encode(file_get_contents("movie.mp4")),
    'mimeType' => mime_content_type("movie.mp4"),
    'size' => filesize("movie.mp4")
]);
?>

How to Convert Video to Base64 with Node.js

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

// Convert video to Base64
async function videoToBase64(filePath) {
  const buffer = await fs.readFile(filePath);
  return buffer.toString('base64');
}

// Get video metadata
function getVideoMetadata(filePath) {
  return new Promise((resolve, reject) => {
    ffmpeg.ffprobe(filePath, (err, metadata) => {
      if (err) reject(err);

      const videoStream = metadata.streams.find(s => s.codec_type === 'video');

      resolve({
        duration: metadata.format.duration,
        size: metadata.format.size,
        bitrate: metadata.format.bit_rate,
        width: videoStream?.width,
        height: videoStream?.height,
        fps: eval(videoStream?.r_frame_rate || '0'),
        codec: videoStream?.codec_name
      });
    });
  });
}

// Usage
(async () => {
  const base64 = await videoToBase64('movie.mp4');
  const metadata = await getVideoMetadata('movie.mp4');

  console.log('Base64:', base64.substring(0, 50) + '...');
  console.log('Duration:', metadata.duration, 'seconds');
  console.log('Resolution:', `${metadata.width}x${metadata.height}`);
})();

// Express.js API endpoint
app.post('/api/video/encode', async (req, res) => {
  const base64 = await videoToBase64(req.file.path);
  res.json({
    base64,
    mimeType: req.file.mimetype,
    size: req.file.size
  });
});

Share this tool

Help others discover this free Base64 tool

or