← Back to Portfolio

VideoToWebMConverter

A lightweight and efficient tool for converting video files to the WebM format with ease. This project provides a simple interface for high-quality video compression, supporting various input formats and customizable conversion settings. Ideal for web developers, content creators, and anyone looking to optimize videos for web delivery.

Python

VideosToWebMConverter

This Python utility scans a directory for supported video files and converts them to WebM format. Converted assets are stored in a WebM_Videos subfolder and encoded with VP9 + Opus via ffmpeg.

Features

  • Batch converts every supported video in a directory.
  • Handles .mp4, .avi, .mov, .mkv, .flv, and .wmv files.
  • Requests the target video bitrate from the user (defaults to 1M if omitted).
  • Prints original and converted file sizes when each conversion completes.

Requirements

  • Python 3.7+ (only standard library modules are used).
  • An ffmpeg installation accessible on your system PATH.
# verify ffmpeg availability
ffmpeg -version

Installation

  1. Clone or download the repository:
    git clone <repo-url>
    cd VideoToWebMConverter
    
  2. (Optional) create and activate a virtual environment.
  3. Make sure ffmpeg is installed.

Usage

Run the script from a terminal:

python VideosToWebMConverter.py

The script prompts you for:

  1. The directory containing the videos you want to convert.
  2. A target video bitrate (press Enter to keep the default 1M).

For each video, progress and file-size information appears in the console. Converted files are saved under WebM_Videos inside the input directory.

Importing the module

You can also call convert_videos_to_webm from another Python module:

from VideosToWebMConverter import convert_videos_to_webm

convert_videos_to_webm(
    directory_path="/path/to/videos",
    video_bitrate="2M",  # optional override
)

How It Works

  1. Creates (or reuses) a WebM_Videos folder inside the source directory.
  2. Checks file extensions and skips unsupported items with a short message.
  3. Executes ffmpeg with the libvpx-vp9 video codec and libopus audio codec.
  4. Reports original and converted sizes in MB once each conversion finishes.

Troubleshooting

  • Error: FFmpeg bulunamadΔ±...: ffmpeg is missing from the PATH. Install it or add the executable path to your environment variables.
  • CalledProcessError: ffmpeg encountered an error. Inspect the console output; you may have an unsupported codec, a corrupted file, or a permissions issue.
  • Conversions for very large files taking too long? Try a lower bitrate such as 800K.

License

No license file has been provided yet. Contact the repository owner to clarify permitted usage.