Skip to main content

Introduction

The towebm package includes a set of Python 3 scripts for transcoding audio or video files using FFmpeg. Arguments are available for basic edit operations – crop, scale, cut, deinterlace – and more. Arbitrary ffmpeg video and audio filters can also be specified. Most outputs also support multiple audio tracks, e.g., surround sound and stereo. The included scripts are as follows:

towebm

Transcodes video files to VP9 video and Opus audio in a WebM or Matroska container.

toav1

Transcodes video files to AV1 video and Opus audio in a Matroska or MP4 container.

toopus

Transcodes audio or video files to Opus audio in an Ogg container.

tovorbis

Transcodes audio or video files to Vorbis audio in an Ogg container.

toflac

Transcodes audio or video files to FLAC audio in the native or Ogg container.

tomp3

Transcodes audio or video files to VBR MP3 audio in the native container.

ffcat

Concatenates multiple files of the same resolution and codec to a single file. Most usefeul when towebm or toav1 have produced multiple output files as edits of a single source file.

Usage

Transcode a source MP2 video with no edits and default quality settings:

towebm Great*.mpg

Transcode a source 1920x1080 MP4 video, which is cropped to 4:3 ratio (1440x1080), then scaled to 720 vertical resolution (960x720), and converted to grayscale. Video quality is set to 25:

towebm -q 25 -s crop43 -s scale23 -s gray Three*.mp4

Transcode a source MP4 video with a 140 and 144 crop from the top and bottom, respectively:

towebm -y 140 144 Music*.mp4

Transcode a source MKV video with a crop to all sides and an aspect-correct scale to 706 horizontal resolution:

towebm -x 260 260 -y 16 4 -vf "scale=h=706:w=-1" Calif*.mkv

Transcode two minutes of a video, starting ten seconds from the start, using three different available options:

towebm --start 10 --duration 2:00 Calif*.mkv
towebm --start 0:10 --duration 2:10 Calif*.mkv
towebm --segment 0:10 2:10 Calif*.mkv

Transcode multiple segments of a video, with one output per segment:

towebm input.mp4 \
    --segment 00:00:30.300 00:07:04.900 \
    --segment 00:09:44.366 00:14:30.133 \
    --segment 20:42:49.300 29:20:01.400

Same as the previous example, but using multiple executions (especially useful if different filters need to be applied to the different segments):

towebm input.mp4 -# --segment 00:00:30.300 00:07:04.900 --fade-in 0.5
towebm input.mp4 -# --segment 00:09:44.366 00:14:30.133
towebm input.mp4 -# --segment 20:42:49.300 29:20:01.400 --fade-out 0.5

Join the output of the previous example into a single file:

ffcat input_*.webm final.webm

Transcode a source MKV video with three audio tracks, the first of which is a 5.1(side) surround-sound track:

towebm input.mkv --fix-channel-layout 5.1:0:0 -b 256:128:128

Same as the previous example, but excluding the first audio track from the output:

towebm input.mkv b 0:128:128

Transcode a segment of a video to Opus audio, with a one second fade-in and a half-second fade-out:

toopus input.mp4 --start 1:00 --end 2:00 --fade-in 1 --fade-out 0.5

Transcode a portion of a FLAC audio file to vorbis, quality 4:

tovorbis -q 4 --start 1:00 --end 2:00 input.flac

Transcode the second audio track of a source video file to FLAC, compression level 6:

toflac input.avi -c 0:6

Transcode a video file, scaled to 960x720 and aspect ratio forced to 4:3. Useful if the input video has an incorrect aspect ratio. See the FFmpeg filters documentation for more information:

towebm input.mkv -vf "scale=w=960:h=720,setdar=4/3"

Installation

FFmpeg

FFmpeg must be installed separately from towebm and located in the system search path for the scripts to work properly. For operating systems with system-level package management, look for FFmpeg in the repository. On Windows, one can try Chocolatey, WinGet, or Cygwin.

Warning

Linux and BSD distributions typically manage system-level Python packages through their own repository and distribution system – apt, zypper, yum, ports, portage, etc. While the scripts included here have no dependencies beyond the standard libraries and this time, and are thus unlikely to cause system conflicts, it is still advisable to install them as a user package or in a Python virtual environment. pipx, if available for your system, is the recommended installation method. On Windows, pip is easily available with Python and generally safe.

Installing with pipx

Instructions for installing pipx on popular operating systems are available on the pipx website, otherwise consult your operating system documentation. By default, pipx will install the scripts into a virtual environment. You may need to add a path to your search path to run the scripts without specifying a path. Use the following to install the package from PyPI:

$ pipx install towebm

Installing with pip

By default, pip will install towebm as a system package, which may require administrative priveleges. Use the following to install the package from PyPI:

# pip install towebm

If you do not have access to install system packages, or do not wish to install in the system location, it can be installed in a user folder:

$ pip install --user towebm

Installing from source

Either download a release tarball from the Downloads page, and unpack:

$ tar zxvf towebm-1.1.0.tar.gz

Or get the latest source from the git repository:

$ git clone https://github.com/dgasaway/towebm.git

Use one of the following in the project directory, after reading about pip and pipx above:

$ pipx install .
$ pip install --user .
$ pip install .

A script can be run directly from source without installation, though this is not convenient. For example, while in the src directory:

$ PYTHONPATH=towebm python -m tovorbis

Metadata

Release files for towebm 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for towebm 2.0.0
File Size Uploaded Provenance Actions
towebm-2.0.0.tar.gz 23.9 kB Without provenance Details for towebm-2.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for towebm 2.0.0
File Interpreter ABI Platform Actions
towebm-2.0.0-py3-none-any.whl Python 3 none any Details for towebm-2.0.0-py3-none-any.whl

Total release size: 55.6 kB

Release files / towebm-2.0.0.tar.gz

Download URL towebm-2.0.0.tar.gz
Size 23.9 kB
Tags Source
SHA-256 checksum
How to use checksums
33e26bfcf5ae3f738d6c7076534c6e7f10b3c35f3be637c283e0b76132726776
BLAKE2b-256 checksum
How to use checksums
0a8d75933d1b951676f274019350ea6a59d97ba1501f3bb6489315ec66556f44
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.28.1

Release files / towebm-2.0.0-py3-none-any.whl

Download URL towebm-2.0.0-py3-none-any.whl
Size 31.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b07b2b334a8b8a8d3de9fb9d272e05277dacad5d12d64e4acffac5d79d6f5fad
BLAKE2b-256 checksum
How to use checksums
a4a921abd82f2e3b34b8ab09ee5a8e0c7b7b74def38595efb9d2d62c18cafe37
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.28.1

Security for towebm 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page