Theora vs. h.264

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.
2. Tests were done on Windows XP 32bit because the Ubuntu version of ffmpeg does not bundle AAC for legal reasons. I used a May 2007 version of Ffmpeg (the latest version crashes repeatedly on Windows when libx264 is used on HT Intel machines), and for ffmpeg2theora I used the latest version, 0.20.
3. I used an HDV .m2t file as source file. My first idea was to use the lossless intermediate Huffyuv format, but it would be problematic trying to upload this to the osnews server, because the file size would be huge. So, I went with .m2t, I put two clips side by side on Sony Vegas Pro 8, and then I exported again as .m2t 1080/60i (interlaced). Vegas does not re-encode clips that were not edited, so this is as close to “straight out of the camera” as possible (only a few frames at the beginning and the end of each clip were re-encoded by Vegas). Download the source clip here (unzip it).

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.

QVGA test

FFmpeg command line:
ffmpeg -deinterlace -y -i "orignal.m2t" -threads 2 -f mp4 -title "h.264 QVGA test" -vcodec h264 -level 41 -refs 2 -loop 1 -deblockalpha 0 -deblockbeta 0 -parti4x4 1 -partp8x8 1 -partb8x8 1 -me full -coder ac -subq 6 -brdo 1 -me_range 21 -s 320x180 -r 30000/1001 -b 320k -maxrate 450k -bufsize 5000k -g 300 -acodec aac -ac 2 -ab 128k "qvga.mp4"

Ffmpeg2theora command line:
ffmpeg2theora --optimize --deinterlace --title "Theora QVGA test" -f mpg -v 4.2 -F 30 -x 320 -y 176 -A 128 -c 2 -H 44100 -o "qvga.ogg" "orignal.m2t"

Download the h.264 video version here, Theora video here (right click to save).

Two things of note here: Ffmpeg2theora would not let me use the resolution that keeps the correct aspect ratio when downscaled from 1920×1080 (anamorphic 1.3333). I had to use 320×176 (direct multiple of 8), instead of the correct 320×180. 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.

720p

FFmpeg command line:
ffmpeg -deinterlace -y -i "orignal.m2t" -threads 2 -f mp4 -title "h.264 720p test" -vcodec h264 -level 41 -refs 2 -loop 1 -deblockalpha 0 -deblockbeta 0 -parti4x4 1 -partp8x8 1 -partb8x8 1 -me full -coder ac -subq 6 -brdo 1 -me_range 21 -s 1280x720 -r 30000/1001 -b 5000k -maxrate 6000k -bufsize 15000k -g 300 -acodec aac -ac 2 -ab 128k "720p.mp4"

Ffmpeg2theora command line:
ffmpeg2theora --optimize --deinterlace --title "Theora 720p test" -f mpg -v 4.3 -F 30 -x 1280 -y 720 -A 128 -c 2 -H 44100 -o "720p-theora.ogg" "orignal.m2t"

Download the h.264 cabac video version here, Theora video here (right click to save).

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.

Conclusion

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 OSAlert 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.

112 Comments

  1. 2007-12-12 6:34 am
    • 2007-12-12 6:42 am
    • 2007-12-12 7:10 am
      • 2007-12-12 7:11 am
        • 2007-12-17 7:37 am
      • 2007-12-14 11:19 am
  2. 2007-12-12 7:01 am
  3. 2007-12-12 7:27 am
  4. 2007-12-12 7:32 am
  5. 2007-12-12 8:12 am
    • 2007-12-12 8:40 am
    • 2007-12-12 9:01 am
      • 2007-12-12 9:36 am
        • 2007-12-12 9:49 am
    • 2007-12-12 9:14 am
  6. 2007-12-12 8:31 am
    • 2007-12-12 8:36 am
      • 2007-12-12 3:55 pm
      • 2007-12-17 3:45 pm
    • 2007-12-12 2:31 pm
  7. 2007-12-12 8:54 am
    • 2007-12-12 9:40 am
  8. 2007-12-12 8:57 am
    • 2007-12-12 8:58 am
      • 2007-12-12 9:42 am
        • 2007-12-12 9:45 am
        • 2007-12-12 1:43 pm
          • 2007-12-12 11:16 pm
  9. 2007-12-12 9:23 am
    • 2007-12-12 9:25 am
  10. 2007-12-12 9:43 am
  11. 2007-12-12 10:02 am
    • 2007-12-12 10:04 am
    • 2007-12-12 10:08 am
  12. 2007-12-12 10:08 am
    • 2007-12-12 10:11 am
      • 2007-12-12 10:36 am
        • 2007-12-12 10:43 am
          • 2007-12-12 10:49 am
          • 2007-12-12 10:55 am
          • 2007-12-12 11:00 am
          • 2007-12-12 11:06 am
          • 2007-12-12 11:18 am
          • 2007-12-12 11:37 am
          • 2007-12-12 12:07 pm
          • 2007-12-17 9:25 am
          • 2007-12-12 4:29 pm
          • 2007-12-12 5:06 pm
          • 2007-12-12 8:31 pm
          • 2007-12-12 8:50 pm
          • 2007-12-12 9:42 pm
          • 2007-12-12 10:28 pm
          • 2007-12-12 11:33 pm
          • 2007-12-12 11:49 pm
          • 2007-12-13 2:04 pm
      • 2007-12-12 10:43 am
        • 2007-12-12 10:45 am
          • 2007-12-12 10:53 am
          • 2007-12-12 11:10 am
          • 2007-12-12 11:17 am
          • 2007-12-12 11:19 am
          • 2007-12-12 11:22 am
          • 2007-12-12 11:23 am
          • 2007-12-12 11:25 am
          • 2007-12-12 11:41 am
          • 2007-12-12 12:05 pm
          • 2007-12-12 5:01 pm
          • 2007-12-12 5:12 pm
          • 2007-12-17 9:41 am
          • 2007-12-12 12:12 pm
          • 2007-12-12 12:23 pm
          • 2007-12-12 12:34 pm
          • 2007-12-12 3:58 pm
      • 2007-12-12 4:43 pm
      • 2007-12-12 8:07 pm
  13. 2007-12-12 11:38 am
  14. 2007-12-12 1:26 pm
  15. 2007-12-12 1:27 pm
  16. 2007-12-12 1:37 pm
    • 2007-12-12 2:29 pm
      • 2007-12-12 4:51 pm
    • 2007-12-12 3:40 pm
  17. 2007-12-12 1:50 pm
    • 2007-12-17 10:07 am
  18. 2007-12-12 2:10 pm
  19. 2007-12-12 2:18 pm
    • 2007-12-17 10:49 am
  20. 2007-12-12 3:07 pm
    • 2007-12-12 8:50 pm
  21. 2007-12-12 3:08 pm
  22. 2007-12-12 3:26 pm
  23. 2007-12-12 3:58 pm
  24. 2007-12-12 4:18 pm
  25. 2007-12-12 4:42 pm
  26. 2007-12-12 5:17 pm
  27. 2007-12-12 5:29 pm
  28. 2007-12-12 6:07 pm
    • 2007-12-12 6:12 pm
  29. 2007-12-12 7:12 pm
  30. 2007-12-12 7:26 pm
    • 2007-12-13 1:31 am
  31. 2007-12-12 11:53 pm
    • 2007-12-13 11:26 am
      • 2007-12-13 1:36 pm
  32. 2007-12-13 12:17 am
  33. 2007-12-13 1:22 am
  34. 2007-12-13 2:41 am
  35. 2007-12-13 9:13 am
  36. 2007-12-13 1:22 pm
  37. 2007-12-14 11:13 am
  38. 2007-12-16 3:21 pm
  39. 2007-12-17 8:03 am