How Much H.264 In Each Encoder?

Thanks to my recent experiments with code coverage tools, I have a powerful new — admittedly somewhat specious — method of comparing programs. For example, I am certain that I have read on more than one occasion that Apple’s H.264 encoder sucks compared to x264 due, at least in part, to the Apple encoder’s alleged inability to exercise all of H.264’s features. I wonder how to test that claim?

Experiment
Use code coverage tools to determine which H.264 encoder uses the most features.

Assumptions

  • Movie trailers hosted by Apple will all be encoded with the same settings using Apple’s encoder.
  • Similarly, Yahoo’s movie trailers will be encoded with consistent settings using an unknown encoder.
  • Encoding a video using FFmpeg’s libx264-slow setting will necessarily throw a bunch of H.264’s features into the mix (I really don’t think this assumption holds much water, but I also don’t know what “standard” x264 settings are).

Methodology

  • Grab a random Apple-hosted 1080p movie trailer and random Yahoo-hosted 1080p movie trailer from Dave’s Trailer Page.
  • Use libx264/FFmpeg with the ‘slow’ preset to encode Big Buck Bunny 1080p from raw PNG files.
  • Build FFmpeg with code coverage enabled.
  • Decode each file to raw YUV, ignore audio decoding, generate code coverage statistics using gcovr, reset stats after each run by deleting *.gcda files.

Results

  • x264 1080p video: 9968 / 134203 lines
  • Apple 1080p trailer: 9968 / 134203 lines
  • Yahoo 1080p trailer: 9914 / 134203 lines

I also ran this old x264-encoded file (ImperishableNightStage6Low.mp4) through the same test. It demonstrated the most code coverage with 10671 / 134203 lines.

Conclusions
Conclusions? Ha! Go ahead and jump all over this test. I’m already fairly confident that it’s impossible (or maybe just very difficult) to build a single H.264-encoded video that exercises every feature that FFmpeg’s decoder supports. For example, is it possible for a file to use both CABAC and CAVLC entropy methods? If it’s possible, does any current encoder do that?

2 thoughts on “How Much H.264 In Each Encoder?

  1. Reimar

    Since you can concatenate arbitrary (raw!) H.264 streams and they are still a valid H.264 stream yes, you sure can make one that exercises all.
    Putting that kind of thing into a mov/mp4/mkv/… would be more difficult though, but it might be possibly by making the frames refer to different SPS/PPS IDs. I have no idea if/how/when you are allowed to do that in a single stream.
    But what would be the point of using both CABAC and CAVLC? There should be very, very few cases (I could imagine using CABAC for non-ref frames, so non-CABAC capable players could just skip them, however I have no idea if you can switch on such a fine granularity, I doubt it).

  2. Pengvado

    An only-somewhat-crazy usecase for CABAC+CAVLC is in rate-distortion-complexity optimization: If your peak bitrate is limited by decoder speed rather than transport bandwidth, and the limit that implies for CABAC is lower quality than you’d like for the most complex parts of the video, then you can sacrifice some bits to save some cycles in just those parts, without increasing total filesize as much as switching the whole video to CAVLC. I dunno how often it would be optimal to pick CABAC rather than some other feature(s) to adaptively disable, but I can’t rule it out.

Comments are closed.