|Theora vs. h.264|
|By Eugenia Loli on 2007-12-12 05:56:52|
|A lot was said lately about the Vorbis/Theora vs h.264/AAC situation on the draft of the HTML5. As some of you know, video is my main hobby these days (I care not about operating systems anymore), so I have gain some experience on the field lately, and at the same time this has made me more demanding about video quality. Read on for a head to head test: OGG Theora/Vorbis vs MP4 h.264/AAC. Yup, with videos. And pictures.
First things first: the disclaimers.
1. This is not a scientific test. Both sides will be arguing about this arcane switch, and the other arcane switch, and "oh, you should have used another encoder", this or that. I don't wanna hear that. I use the most popular and free front-ends for these encoders: ffmpeg with x264/faac and ffmpeg2theora. FFmpeg is a command line front-end to many encoders and itself is used by many GUI front-ends too, so it's one of the best utilities for the job. Ffmpeg2theora on the other hand, is the most popular Theora front-end too. I didn't use Ffmpeg for Theora because that implementation is still buggy. FFmpeg2theora does a better job.
I did two tests: one for a widescreen QVGA format, and one for a 720p HD one. I chose these two sizes on purpose. One format will show us how the codecs perform in low bitrate, which is super-important for web usage, and the other one will show us how well the codecs perform with HD.
FFmpeg command line:
Ffmpeg2theora command line:
Two things of note here: Ffmpeg2theora would not let me use the resolution that keeps the correct aspect ratio when downscaled from 1920x1080 (anamorphic 1.3333). I had to use 320x176 (direct multiple of 8), instead of the correct 320x180. FFmpeg/x264 had no problem with that.
The second thing is something that really made me angry: Ffmpeg2theora will upsample the NTSC frame rate of 29.97 to 30fps. Well, I don't want 30fps, I want 29.97. I am accustomed to view lots of my videos on my TV (usually by using a PS3), so should a Theora2TV device comes out, I want to be able to have smooth frame rate, without adding pulldown and all the problems that brings. No matter what trick I tried to do, Theora would keep adding pulldown to 30fps. Update: You can get to 29.97 only by either not specifying it at all, or via 30000:1001 (instead of 30000/1001 or 29.97).
Now, you probably noticed that I gave a "videoquality" of "4.2" to Theora, while I gave FFmpeg 320kbps video with a 450kbps peak rate (VBR). I did this because Theora would simply NOT do what I asked it to. It would not stay close to the requested 320kbps, and so it would create a 550kb file instead of a 640kb one. So I changed the Theora command line, by trying different VBR quality numbers, until I got an output file size that matched that of h.264's. Remember, the important thing here to remember is THE WEB. Bandwidth matters. So it's important to know what kind of quality you get from each codec, for the same file size (not necessarily the same bitrate).
As you can see from the tests, h.264 whooped Theora pretty bad on this test. Even when I gave the benefit of the doubt to Theora and re-encoded it in 400kbps, h.264 was still visibly much better.
FFmpeg command line:
Ffmpeg2theora command line:
Again, a quality number was used for Theora to match h.264's file size at the requested 5 Mbps (with 6mbps peak rate). I did two ffmpeg passes, one with the CABAC entropy coding, and one with the CAVLC one (just change the "-coder ac" to "-coder vlc" in the ffmpeg code above). CABAC creates better looking video than CAVLC, but it's harder to decode (Quicktime chokes good on it, for example, on my P4 3Ghz). I usually encode my stuff in CAVLC simply because I might find myself sharing my own videos to people with AppleTVs or slower PCs, so I am trying to play nice.
HD is HD, so even if Theora again performs worse than h.264, there is enough resolution that the differences might not as obvious as in the QVGA example. For example, I have an old CRT HDTV, which barely manages well 1080i, so the difference would not be much visible (heck, on my TV I barely see the difference between Comcast's HD channels and progressive DVDs). However, people with big LCDs or Plasmas will be able to see more artifacts -- should a device that playbacks Theora on TVs comes to market.
Another interesting tidbit about the 720p test is the encoding times! H.264 did 1'.15" for CAVLC and 1'.20" for CABAC on my PC. Theora took its sweet time and finished at 3'.14". Granted, I used two threads on the FFmpeg command line, while it was obvious to me by monitoring my Hyperthreaded CPU that FFmpeg2theora was single-threaded. But even if you divide the 3'.14" by 2, you get 1'.37", which is still slower than h.264's encoding times.
Now, a last point, CPU utilization during decoding. Of course, this is implementation-specific, but you know, you gotta test with whatever is popular, no matter if their implementation sucks or not. So I used VLC and a new version of Media Player Classic. VLC used on average 65% of my hyperthraded CPU on CAVLC, 75% on CABAC and 75% on Theora. MPC used 34% on CAVLC, 43% on CABAC and 33% on Theora. These were rough averages during multiple times of running each video.
I prefer h.264. Goodnight everyone.
Ok, ok, not yet goodnight. Truth is, I prefer open standards and open source and Free Software and what not, over proprietary royalty/patent-ridden solutions. But pictures (and videos) don't lie. Theora is simply not at the same league as h.264. Vorbis fairs well compared to the big 3 audio formats, but Theora is visibly worse in comparison. By their own admission in the past, the Theora developers had to use less efficient algorithms to go around patents. This sucks of course, but it all comes down to this: do you want an open FOSS solution, or you want the best solution? Many readers on OSNews will choose the first option, but their teenager brother would probably choose the second.
Some say that Dirac is better, and it's free/open. But until their developers actually do take the time and commit their implementation to ffmpeg (instead of only offering patchsets), it just doesn't exist for me. FFmpeg -- with all its problems... Come on, no automatic letterboxing??-- is used by many GUI front-ends, so if they want market penetration, they gotta add their encoder to ffmpeg. Then, I will give them a whirl too.