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 theoraIf 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-i input.mp4: Specifies the input video file.-c:v libtheora: Selects the Libtheora encoder for the video stream.-c:a libvorbis: Selects the Vorbis encoder for the audio stream, which is the standard audio pairing for the Ogg container (.ogv).output.ogv: The name of the resulting transcoded file.
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-q:v 6: Sets the video quality to 6.-q:a 5: Sets the audio quality to 5 (on a scale of 1-10 for Vorbis).
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-b:v 2M: Restricts the video bitrate to 2 Megabits per second.-b:a 128k: Restricts the audio bitrate to 128 Kilobits per second.
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.ogvThis command scales the video to 720p (1280x720) during the conversion process.