How to Transcode Video with FFmpeg MPEG-4 Encoder

This article provides a straightforward guide on how to transcode video files using the native MPEG-4 (mpeg4) video encoder inside FFmpeg. You will learn the basic command-line syntax, how to control video quality and bitrate, and how to manage audio streams during the conversion process.

Basic MPEG-4 Transcoding Command

To convert any input video to the MPEG-4 format using FFmpeg, you need to specify the native MPEG-4 encoder using the -c:v mpeg4 (or -vcodec mpeg4) flag.

The most basic command structure is:

ffmpeg -i input.mp4 -c:v mpeg4 output.mp4

In this command: * -i input.mp4 specifies the source video file. * -c:v mpeg4 tells FFmpeg to use the MPEG-4 Part 2 video encoder. * output.mp4 is the destination file.

Controlling Video Quality

By default, FFmpeg may apply a target bitrate that does not match your quality expectations. You can control the output quality using either a constant quality scale or a specific target bitrate.

Method 1: Using Constant Quality (-q:v)

The recommended way to control quality for the mpeg4 encoder is using the -q:v (or -qscale:v) option. The scale ranges from 1 to 31, where lower values mean better quality and larger file sizes.

Example command for high quality:

ffmpeg -i input.mkv -c:v mpeg4 -q:v 4 output.mp4

Method 2: Setting a Specific Bitrate (-b:v)

If you need to meet a specific file size requirement, you can set a fixed video bitrate using the -b:v flag (e.g., 2M for 2 Mbps).

ffmpeg -i input.mov -c:v mpeg4 -b:v 2M output.mp4

Managing Audio

When transcoding the video, you must also decide what to do with the audio stream.

Copy Audio Without Re-encoding

If the source audio is already compatible with your target container (like AAC audio in an MP4 container), you can copy it directly to save time and preserve original quality using -c:a copy:

ffmpeg -i input.mp4 -c:v mpeg4 -q:v 4 -c:a copy output.mp4

Re-encode Audio to AAC

If you need to transcode the audio to a widely compatible format like AAC, use the -c:a aac flag:

ffmpeg -i input.avi -c:v mpeg4 -q:v 5 -c:a aac -b:a 128k output.mp4