Saturday, March 01, 2008

MPEG4 - H264 comparison

Background
I've been wanting to produce some high quality, H.264 content for my bands' music for some time, but x264 had been broken on my Fedora system. Since I've finally fixed the problem, I can now render a proper H.264 file. Without H.264, I would choose MPEG4 video compression and an AAC audio codec.

MPEG4 file
I use ffmpeg to reduce a DVD sized mpeg down to a file that I could upload to iTunes, like so:
ffmpeg -i ${NAME}.m2t -f mov -vcodec mpeg4 -qscale 7 -s 320x180 -r 29.97 -aspect 16:9 -acodec aac -ac 2 -ab 128 ${NAME}.mov

The variable in this render string is "qscale" (good explanation of which at the bottom of this post) which varies quite a bit depending on the content of your video. The final resolution of the MPEG4 video was 320x180.

H.264 file
I used AVIdemux2 to output the H.264 video. I selected the defaults with a Single Pass - Quality Quantizer (Average) encoding and a similar AAC audio encoding of the MPEG4 of 128K.

The final resolution of the H.264 video was 720x400.

I'll translate the following output into a command line x264 statement at some point, but right now, here were the detailed options to avidemux2:
vui.i_sar_width = 1, vui.i_sar_height = 1, rc.f_qcompress = 0.60, analyse.i_direct_mv_pred = 1, rc.i_qp_min = 10, rc.i_qp_max = 51, rc.i_qp_step = 4, i_frame_reference = 1, i_scenecut_threshold = 40, i_keyint_min = 25, i_keyint_max = 250, i_bframe = 2, i_bframe_bias = 0, b_bframe_pyramid = 0, analyse. b_bidir_me = 0, b_bframe_adaptive = 1, analyse.b_weighted_bipred = 1, b_cabac = 1, analyse.i_trellis = 1, analyse.i_subpel_refine = 5, analyse.b_chroma_me = 1, b_deblocking_filter = 1, i_deblocking_filter_alphac0 = 0, i_deblocking_filter_beta = 0, analyse.i_me_method = 1, analyse.i_me_range = 16, analyse.b_transform_8x8 = 1, analyse.b_mixed_references = 0, analyse.i_noise_reduction = 0, _8x8P is on, _8x8B is on, _8x8I is on, _4x4I is on

Comparing the Output
The MPEG4 file from FFMPEG was 312MB.
The H264 file from AVIdemux2 was 438MB.

Here is how a couple of snips from each file look side by side:







Conclusions
I probably haven't experimented enough with FFMPEG to get the most out of the MPEG4 compression. But the quality and compression rate of H.264 is most impressive. Even though the resolution of the H.264 encoding video was twice that of than the MPEG4, the file size was only 33% greater. That speaks to the efficiency of the H.264 encoding scheme.

I'd say that the H264 output was well worth the extra 120MB, eh?

In case you wish to see the whole hour long shebang in either format, here are the two feeds:
The StormPigs 1/11/2007 jam in MPEG4 format, courtesy of FFMPEG (312MB)
The StormPigs 1/11/2007 jam in H264 format, courtesy of AVIdemux2 (438MB)

And if you are truly insane and wish to subscribe to the StormPigs iTunes feed, here it is:
http://www.stormpigs.com/vodcast.xml

:)
The Mule

2 comments:

lalee said...

What's the command-line?

Cacasodo said...

Avidemux2 is just a graphical front end to programs that run in a terminal window, like the program x264. At the terminal, you type in commands at the command line. It looks like this:
[root@ogre ~]# ls
spDvdFake.png
20050721dvd.mpg
spDvd.png
[mule@ogre ~]# x264
x264 [error]: No input file.
Run x264 --help for a list of options.
[root@ogre ~]#

So, if you wanted to, instead of using Avidemux2 from the GUI, you could directly type in the commands to start and use x264, the program that is actually doing the work of encoding your video.

hope this helps.
the mule