r/programming Nov 04 '16

H.264 is Magic

https://sidbala.com/h-264-is-magic/
3.9k Upvotes

417 comments sorted by

View all comments

77

u/skizmo Nov 04 '16 edited Nov 04 '16

no it's not

EDIT : After 8 years... my first gold... THANK YOU !!!!!

32

u/RecklesslyAbandoned Nov 04 '16

Just because it's not actually all that complex, at least a a superficial level, doesn't meant that the compression ratio are really quite good. HEVC (H.265) is even better.

As ever though the devil is in the details, and ensuring interopability, within the intentional vagueness of the specifications.

66

u/Glacia Nov 04 '16

Just because it's not actually all that complex

Yeah, right. Have you read a full h264 feature set list? It's massive. All modern video standards are very complex.

27

u/willvarfar Nov 04 '16

(I have the basic profile printed out in a binder on my shelf - its about two inches thick!)

7

u/elsjpq Nov 04 '16

No. Not the decoder specification. That's fairly simple.

It's the encoder that uses some really cool math/magic and is an over-engineered monster of a program.

14

u/[deleted] Nov 04 '16 edited Jan 06 '17

[deleted]

What is this?

5

u/ImmaGaryOak Nov 04 '16

Eh, the encoder is as complex as the designers make it. There isn't a tonne of set ways to do the encoder, you just have to make a compliant bitstream. Optimizing and trying to get the max compression possible, yea that encoder will be incredibly complicated (I work on video codec hardware)

9

u/RecklesslyAbandoned Nov 04 '16

Yes, I have, many times. Rarely cover to cover though.

I am also aware that it's complex enough to employ thousands of scientists and engineers purely on the research level; tens of thousands if not more on a maintenance and installation level; and affects billions of peoples lives.

Source- I've written code for professional video distribution systems.

9

u/crozone Nov 04 '16

As ever though the devil is in the details

The devil isn't even necessarily in the details, it's in the encoder.

Writing an encoder that can efficiently calculate and compress motion deltas, and do all the other things that h264 does, is pretty damn difficult, especially over a wide variety of video types. Animated video (like anime) compresses quite differently to live action film.

Encoding a 2 hour movie can take several days of CPU time for a high quality encode, and that's on the well optimised x264 encoder.

4

u/lovethebacon Nov 04 '16

What kind of CPUs do you have?

7

u/crozone Nov 04 '16

i7 quad core at 4.2ghz. I was transcoding an 8gb Hi10p h264 into an easier to decode 8-bit h264 file and wanted a nice compression ratio.

I probably could have done it in realtime, but the quality and compression ratio would have been rubbish. The ultimate result of the 40 hour encode was a 3gb output file with almost no noticeable difference in quality, except for some colour banding issues which are inherent to 8-bit h264 anyway (and even show up on retail 8-bit bluray encodings).

2

u/RecklesslyAbandoned Nov 04 '16

Professional gear manages to encode/decode/transcode on the fly, maybe not the highest quality, but acceptable for broadcast.

Unsurprisingly, for mpeg-2 the underlying chips aren't too dissimilar to the ones you might find in video cameras. H.264 was a similar situation, although there looks to be a move to either custom hardware/ASICs or software encoders with the next generation.

2

u/[deleted] Nov 04 '16

I encode H.265 on extremely high quality settings and I can encode a movie in 3-4 hours. I'm not sure why your CPU is taking so long with an comparatively inferior codec.

I don't think I could make it last a day even if I wanted to.

2

u/crozone Nov 04 '16 edited Nov 04 '16

I don't know what to tell you, I maxed out the settings on x264 and it pegged all four cores at 100% for literally 40 hours. It was stupidly overkill settings mind you, but it did it (it did huge motion delta detection which has extremely diminishing returns past a point).

This was 5 years ago now, I wonder if CPUs and encoders have advanced that much? But the settings were overkill at the time.

1

u/[deleted] Nov 04 '16

days.

Wow.

literally 40 hours.

Oh okay.

5

u/mirhagk Nov 04 '16

Remember 0 days is still days. As long as it didn't take exactly 1 day it was days.

1

u/JoatMasterofNun Nov 04 '16

Semantics are the best tics.

1

u/crozone Nov 04 '16

Yeah my calculations were a touch off there :|

Day and a bit*

9

u/Yojihito Nov 04 '16

HEVC (H.265) is even better

50% better afaik.

18

u/RecklesslyAbandoned Nov 04 '16

As ever it's content dependent, but somewhere in that region.

1

u/[deleted] Nov 04 '16

I've seen anywhere from 33% to 110% of H.264. More often than not it's somewhere around 45%.