2018-11-21

A gentle lecture, what a codec is

I recently wrote an offhand post about doing software archaeology at my job into the FFmpeg project, and one of my nephews, who is very smart but his passions go doing a different path than mine responded with: "I have no idea what you're talking about but I'm sure it's great", and thus so, I wrote up a slightly longer lecture/essay as a comment reply. Then my friend Tim Lord responded with: "that description of codecs deserves to be someplace besides only in a comment on a Facebook post -- cogent, unpatronizing, good refresher". And thus so, here it is:

A codec is a software that turns sound or video into a computer file or back again. Every phone call you have ever heard, and every movie you have ever seen, and all the recorded music you have ever heard (except for actual film movies or phonographs or old cassette tapes) has been processed by an enCODer to record it, and another DECoder to play it back to you.
There are many many many different codecs. Early ones were designed around the limits that computers were not very fast or very powerful, so they did not do a very good job of using the fewest number of computer bits for the best possible audio or video. We have codecs today that are very very good at it, because our computers are fast and powerful enough.
There are many old codecs we can't easily stop using because they are built into systems that can't be easily all replaced at once, such as satellite receivers, telephone switches, and handset cellphones.
Some codecs were created to play movies and sound for computer games, and so the codec software was built into that particular game, and used only for one or a few games, and then never used again.
Codecs are very difficult to design well, because they depend on how human brains, human eyes, and human ears work. To save space, a codec does not want to spend computer power saving or playing back the parts of music or video that your brain cannot hear or see. So codec designers have to study human perception, and have to test things out on human volunteers, which is slow and expensive.
Widely used codecs are often "standards". Corporations, governments, and universities will work together to carefully design a codec that then can be used in many places at once, so that lots of systems can all talk to each other.
One of those groups is called the "Motion Picture Experts Group", which is supervised by an organization called the "International Standards Organization", and one of the standard codecs they designed was called "Audio Layer", and they made several versions of Audio Layer until the 3rd version was good enough. Thus "ISO MPEG version 2 AL version 3", or for short "MP3".
FFmpeg is an open source software project that was originally an implementation of one of the MPEG video codecs, but since then has become a project that tries to have an implementation of every possible codec. FFmpeg contains old codecs that are no longer used, old codecs that are still widely used, codecs that were used in old video games and never used again, new codecs that are now used a lot, and also lots of experimental codecs that people wrote to figure out what does and does not work in a codec.
Because FFmpeg has so many codecs in it, people now use it to "translate anything to anything", and they also use it to analyze and process audio and video information. My own employer uses FFmpeg in many places inside our company, to do lots of the things that our customers pay us for.

My nephew then had the question "So JPEG artifacts are because of an outdated codec?", to which I responded:
Every codec has artifacts if driven too hard, if its told "no, compress it even harder, fewer bits". There are newer codecs that are better than JPEG that don't start having visible artifacts so soon, and have artifacts that are less distracting. But we can't change all the image viewing software everywhere, so we will have to live with JPEG for a long time.