How to Use Libtheora Encoder in FFmpeg

This guide provides a straightforward tutorial on how to use the libtheora encoder in FFmpeg to transcode videos into the open-source Ogg Theora format. You will learn the essential command-line syntax, how to control video quality and bitrate, and how to pair the video with compatible audio codecs like Vorbis for optimal compatibility.

Verify Libtheora Support

Before starting, ensure that your FFmpeg installation is compiled with libtheora support. Run the following command in your terminal:

ffmpeg -encoders | grep theora

If you see libtheora listed in the output, your FFmpeg installation is ready to encode Theora video.

Basic Transcoding Command

To convert a video (such as an MP4) to the Ogg Theora format using default settings, use the following basic command:

ffmpeg -i input.mp4 -c:v libtheora -c:a libvorbis output.ogv

Controlling Video Quality (VBR)

For the best balance between file size and visual quality, use Variable Bitrate (VBR) encoding. This is controlled using the -q:v (or -qscale:v) option.

The scale ranges from 0 to 10, where 10 is the highest quality (and largest file size) and 5 to 7 is generally the sweet spot for standard use.

ffmpeg -i input.mp4 -c:v libtheora -q:v 6 -c:a libvorbis -q:a 5 output.ogv

Controlling Bitrate (CBR)

If your target platform requires a strict, constant target bitrate rather than variable quality, you can set a specific video and audio bitrate using the -b:v and -b:a flags:

ffmpeg -i input.mp4 -c:v libtheora -b:v 2M -c:a libvorbis -b:a 128k output.ogv

Resizing Video During Transcoding

If you need to change the resolution of your video while transcoding to Ogg Theora, you can apply the scale filter with the -vf flag:

ffmpeg -i input.mp4 -c:v libtheora -q:v 6 -vf scale=1280:720 -c:a libvorbis -q:a 5 output.ogv

This command scales the video to 720p (1280x720) during the conversion process.