# When exporting an H.264 video, why is the resulting file's extension .avi?

I have a client that wants the render in .mp4 format. Using the Blender VSE, I rendered the image sequence into a movie using H.264, which I understand is MPEG-4, but Blender outputs the .avi extension instead. Why is this the case and is there any harm in renaming the extension to .mp4? When I rename the extension to .mp4 it seems to work just fine, but maybe there is some harm in doing this that I don't understand.

## 4 Answers

H.264 is a codec and MP4 is a file format. An H.264 stream can be contained in several different file formats, e.g. AVI, MP4 or MKV, and most file formats can handle several codecs.

Video file formats, such as AVI, MP4 or MKV, can handle multiple streams, and most commonly contain one video stream, one or more audio stream(s) and possibly one or more subtitle stream(s).

Simply renaming an AVI file to MP4 won't make it an MP4 file, though most players will detact the actual format and ignore the filename extension. To convert an AVI to MP4, you'll need to re-multiplex it. Multiplexing is the process of combining the different streams into one file and write the proper metadata. This can be done without re-encoding the streams.

I just had a quick look, and I can't find an option to save as MP4, and unless someone has a solution for that, it looks like you'll need an external program for this. If you need/want a GUI application, Avidemux will do nicely for simple re-multiplexing and even some filtering and re-encoding. If you're OK with commandline programs, I recommend FFmpeg.

• @BrysonJack Note that you may be able to export directly to MP4 instead of using ffmpeg; see my answer. – wchargin Feb 15 '15 at 4:01
• Blender uses ffmpeg internally. It can certainly produce mp4 files. – dr. Sybren Jun 6 '17 at 7:20

SixthOfFour's answer correctly explains the codec/container difference. But I am able to natively export as MP4 (with Blender 2.73 on 64-bit Linux) with the following settings:

• Output panel, file format dropdown: H.264
• Encoding panel, format drop-down: MPEG-4

This produces /tmp/0001-0250.mp4 with the H.264 codec.

• I just tried that, and ffprobe tells me that Stream #0:0(und): Video: mpeg4 (Advanced Simple Profile) (mp4v / 0x7634706D), yuv420p, 1080x1080 [SAR 1:1 DAR 1:1], 3602 kb/s, 25 fps, 25 tbr, 12800 tbn, 25 tbc (default) and the output of ffmpeg -codecs tells me that DEV.L. mpeg4 MPEG-4 part 2 (decoders: mpeg4 mpeg4_vdpau ) (encoders: mpeg4 libxvid ). I find that really strange. The container is really MP4, confirmed by ffprobe, but the codec is wrong. – user7952 Feb 15 '15 at 4:20
• @SixthOfFour: I'm not familiar with that tool, and don't know how to read that output. What's the actual output codec? – wchargin Feb 15 '15 at 6:15
• ffprobe is part of the ffmpeg package. "Video: mpeg4" says that the codec is mpeg4, and "(encoders: mpeg4 libxvid )" suggests that this is simply an alias for XviD. – user7952 Feb 15 '15 at 11:38
• A little clarification. libxvid is the library that ffmpeg (and also mplayer and Avidemox) uses to encode XviD. mpeg4 is a generic that can read several mpeg4 type codecs, XviD being one of them. "(mp4v / 0x7634706D)" gives a little clue, but I'm not entirely sure about this codec (XviD is usually reported as "(xvid / 0x64697678)"), so that's not likely it. But the point is that I've never seen H.264 reported as anything other than "h264 ()" with the profile used is named in the parantheses. – user7952 Feb 15 '15 at 12:05

I believe blender can't export video using the MP4 container. If you export using the H.264 codec option under the Encoding panel, it gets wrapped with the AVI container.

The simplest solution I've found is to export using the Quicktime container and the H.264 codec. Then convert it to the MP4 container using ffmpeg.

ffmpeg -i INPUT.mov -vcodec copy -acodec copy OUTPUT.mp4

On OS X, you can check a video's container, regardless of its file extension in its "Get Info" dialog in Finder. Note the "Kind" and "Codecs" fields.

As of Blender 2.77 you can save directly as a correctly muxed .mp4 file, in the Render Panel, by selecting Output as "H.264" and just below at Encoding, Format: MPEG-4 and Codec: H.264. This generates the correct container and encoding AFAIK. You will not see the Codec part until you select MPEG-4, it is not there for other Format settings. This is a pretty awful UI setup, redundant and opaque, why they don't just have a single setting for Container and a second for Codec, like virtually all video editors and utilities, is beyond me. Or at least rename "Format" to "Container" and keep the "Codec" there for all settings even if it is greyed out if not applicable.