How to Set AVI FourCC Code Using FFmpeg

This article explains how to change or set the FourCC (Four Character Code) of a video stream within an AVI container using the FFmpeg command-line tool. You will learn the specific command-line options required to modify identifiers like XVID or DIVX, allowing you to resolve media player compatibility issues quickly.

Understanding the FourCC Tag in FFmpeg

A FourCC is a sequence of four characters used to identify the data format inside media containers like AVI. Sometimes, media players refuse to play a video because they do not recognize the container’s FourCC, even if they support the underlying video codec.

To set or force a specific FourCC in FFmpeg, you use the -vtag option followed by the desired four-character code.

Setting the FourCC Code While Encoding

If you are converting a video to MPEG-4 and want to force the player to recognize it as an XVID or DIVX video, you can specify the codec and the tag simultaneously.

To encode a video to MPEG-4 and set the FourCC tag to XVID:

ffmpeg -i input.mp4 -c:v mpeg4 -vtag XVID output.avi

To encode a video to MPEG-4 and set the FourCC tag to DIVX:

ffmpeg -i input.mp4 -c:v mpeg4 -vtag DIVX output.avi

Changing the FourCC Code Without Re-encoding

If your video stream is already compatible (for example, it is already encoded in MPEG-4) and you only need to change the FourCC tag to make it compatible with a hardware player, you can copy the video stream without re-encoding. This process is nearly instantaneous and preserves original quality.

To change the FourCC tag to XVID without re-encoding:

ffmpeg -i input.avi -c:v copy -vtag XVID output.avi

Explanation of the Parameters: