Coding Video: Companion Site
Video compression - or video coding - has been at the centre of a revolution in the way video is produced, delivered and consumed. It has made the switch from analogue to digital video possible and has enabled fundamental shifts in the way we now watch video.
New video compression standards, together with adaptive streaming protocols, are used to deliver high-quality video to homes and workplaces around the world. Coding Video provides a practical and comprehensive guide to the new landscape of video coding and video streaming. This book explains the core technologies with a wealth of practical examples and illustrations, covers key standards such as H.265/HEVC and includes an introduction to the new H.266/VVC standard. Coding Video will appeal to engineers, application developers, product designers and digital video professionals, as well as to graduate students and researchers in Engineering, Computer Science and related subjects.
Check back soon for links, resources and updates related to Dr Richardson’s new book.
Getting started with Video Coding
See Chapter 11 Implementation and performance for more information
-
Many different software implementations of video coding standards are available, some in the public domain whereas others require a commercial license. A good starting point is the ffmpeg cross-platform framework for processing, coding and streaming video and audio material. It includes a number of video codecs, including the x264 and x265 software implementations of H.264 and H.265. Ffmpeg is widely used, relatively fast, well documented and frequently updated. It can be used in a file-based mode, for converting video files to or from compressed files, or used as a software library as part of a larger application. The popular processing and playback applications Handbrake and VLC provide a more user-friendly graphical interface to the ffmpeg library. In this section we will be using ffmpeg in file-based mode.
The official ffmpeg site, https://ffmpeg.org/, provides ffmpeg as source code for compilation. Third-party sites provide pre-compiled binaries for installation on platforms such as MacOS, Windows and Linux, https://ffmpeg.org/download.html. MacOS and Linux users can use a package manager such as Brew to install the latest version of Ffmpeg.
Once you have installed ffmpeg using a binary, a package manager or by compiling the source code, open a command prompt or terminal and type ‘ffmpeg -h’ to get basic help options. The syntax for calling ffmpeg from the command line is generally:
ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...
where infile is an input file and outfile is the file that ffmpeg produces. Numerous command line examples are provided below. On a Windows system, replace ffmpeg with ffmpeg.exe.
-
It is possible to experiment with any video material available to you. However, it is possible that readily available video files on your computer or mobile device may have already been compressed using lossy compression. It can be preferable to start with uncompressed source material. Uncompressed video clips at a range of resolutions are available at https://media.xiph.org/video/derf/ and https://ultravideo.fi/#testsequences. These are typically provided in .y4m format or .yuv, in which the video samples are stored in a file as Y, Cr and Cb samples. The .y4m format has a header indicating the resolution and sampling format of the video, e.g. 1920x1080, 4:2:0 sampling. These files are large: a 500-frame, 1080p clip takes up 1.5Gbytes of storage.
-
Ffmpeg can be used to change various aspects of a test clip. You might choose to download a 4K test clip such as Jockey or Old Town Cross and then create versions of the clip at lower resolutions such as 1080p or 720p. Here are a few examples of how to use ffmpeg to manipulate a source clip in .yuv or .y4m format.
Convert a .yuv file to a .y4m file:
ffmpeg -s [resolution, e.g. 1920x1080] -r [framerate] -pix_fmt yuv420p -i [source.yuv] [destination.y4m]
Adjust the resolution of any .y4m file to 1080 pixels vertical resolution:
ffmpeg -i [source.y4m] -vf scale=-1:1080 [destination.y4m]
Convert an input file to a file containing only N frames:
ffmpeg -i [source.y4m] -frames N [destination.y4m]
-
Experimenting with video coding requires the capability to encode/compress, decode/decompress and view or play back video clips.
To encode a y4m file using ffmpeg:
ffmpeg -i [source.y4m] -c:v [encoder library] [encoding parameters] [output.mp4]
Where [encoder library] is a choice of ffmpeg library for encoding using a certain format, such as libx264 for x264 / H.264 encoding or libx265 for x265 / H.265 encoding. The encoding parameters available depend on the chosen library.To encode using x265 with a video encoder QP of 38:
ffmpeg -i [source.y4m] -c:v libx265 -x265-params qp=38 [output_QP38.mp4]
Here, the output is specified as a .mp4 file. This means that the H.265 bitstream is encapsulated in an MP4 container file. No audio has been specified in the command line and so the MP4 file (output_qp38.mp4) will contain no audio. It can be convenient to use a container file format such as MP4, so that other applications such as VLC player can readily open and play the file.
To decode a compressed file into an output, uncompressed y4m file:
ffmpeg -i [output.mp4] [decoded.y4m]
Ffmpeg will attempt to determine the codec format (e.g. H.265) and will apply the appropriate video decoder to produce an uncompressed file.
To play back a coded or uncompressed file, with minimal user controls:
ffplay [filename]
Many applications are available to play compressed video clips and a smaller number of applications can play back uncompressed clips in .y4m or .yuv format. VLC player, which uses the ffmpeg framework, is a useful tool for playing compressed video files and applications such as YUVviewer and Vooya can play back uncompressed clips.
-
Elecard Streameye Studio www.elecard.com/products/video-analysis/streameye-studio
Parabola Research Analyser. parabolaresearch.com/explorer-hevc-analyzer.html
Zond265 Analyser www.solveigmm.com/en/products/zond/
-
Q&A with Dr. Richardson
-
Video coding has moved on considerably in the last 14 years and it continues to be increasingly important.
One change is that we all use video a lot more now. We have more screens in our homes, which have higher resolutions and we’re streaming more video. At the same time, processors have become faster and more capable. If you put all of that together then you have more processing power and more demand for high definition video, transmission, storage and streaming. New video codecs such as HEVC/H.265 and VVC/H.266 can compress high resolution video more efficiently, making use of the faster processors that we now have. All of this means that there are plenty of new developments to explain to the reader.
There’s another reason that I wrote this new book. I spend a lot of my time explaining video coding and I am always looking for new ways to explain the core concepts. I’ve rewritten all my explanations of the key ideas of video coding in what I hope is a fresher, more accessible way, with literally hundreds of new examples and diagrams.
-
In this new book, I explain all the basic concepts of video coding by using lots of diagrams and easy to follow explanations. These explanations will give you a good start, but I think there is no substitute for trying experiments yourself.
My recommendation is to buy the book, take a look, review the explanations and then start thinking, “Right, how do I actually change the quantizer?”, “Just how much better is H.266 compared to H.264 or H.265?”
You find out the answers to these and other questions by experimenting yourself with video codecs. It may be a little bit of a learning curve, but I can guarantee it's not too steep! You don’t need an engineering or a computing degree to get started, anyone can try it and get their hands dirty. I feel that running your own experiments can give you a more intuitive understanding of what it means to have good compression and what it means to have good quality. This is how you really begin to understand the trade off between compression, video quality and the amount of computation that is required. And then if somebody releases a new codec and claims that it’s the best one yet, you can make your own measurements and reach your own conclusions, instead of just taking their word for it.
-
There is no easy answer to that question! H.264 has been around for 20 years now, and it's an absolute workhorse. It is probably still the most widely used video codec. However, if you've got faster processors available, or if you are looking at higher definition video like HD and 4K video, then you might expect better performance out of H.265 or even H.266. Of course, the answer is going to depend on factors such as how much computation you have available, the video content you’re working with and the way in which the codec has been implemented in software or hardware.
The best codec very much depends on the situation. There are codecs and formats available that have different features and are flexible in different ways. The best codec will really depend on what you're coding, what you're using to code it, and what you're coding it for.
-
Is H.265 twice as good as H.264? Is H.266 twice as good as H.265? Is AV1 better or worse than H.265? You'll find publications and articles disagreeing about these questions. Part of the answer is that video codec implementations are not the same. For example, the H.265 standard tells you certain things about a video decoder and it implies certain things about a video encoder. How the actual video encoder is put together is largely up to the designer.
Some codecs are deliberately computationally efficient. This means that they go really fast, but the compression versus quality performance might not be particularly good. Other codecs implementing the same standard might use more sophisticated encoding methods. You might get better compression for the same quality or better quality for the same compression, however it might take a lot more computation.
No two codec implementations are the same and there are so many different factors involved that can make it difficult to reach a single answer about performance.
-
Absolutely! In the 1990s, people would ask me “What are you working on?”. “Video compression” was my answer. More than once I heard the opinion, “oh, we won't need video compression soon. Bandwidth is increasing so much”. Of course, the exact opposite happened. Bandwidth has increased so much since the 1990s but the demand for high-resolution has increased even more. Think of a typical family household nowadays, where everyone might be watching video at the same time, on a different screen. So we actually need video compression now more than we ever did.
So yes, a colleague did offer me that bet of $100. I didn’t take that bet, but I wish I had!
-
The answer to that, is determined by the trade-off between computation, video coding performance and backwards compatibility. For example, the majority of video that is coded, streamed over the internet and stored on devices, is still using the 20 year old H.264 format. Therefore, many devices need to support H.264 to make sure they are still compatible with the video that’s out there.
These days, a lot of electronic devices support H.265, however not all devices can handle it. As the processors improve, and as we generate future generations of processors, we might see H.265 become very widely supported and we might expect to see growing support for H.266, and so eventually H.264 may become obsolete - but we are a long way from that point. This means that you might have the ability now to choose a newer codec, if you have a high performance processor and if the decoder can also support the desired codec. As processing power continues to improve, there’s an opportunity to develop and use increasingly sophisticated video codecs that improve compression at the expense of more processing power.
There are also codecs or formats that are not standardised by International Organisation for Standardisation / International Electrotechnical Commission (ISO/IEC) and the International Telecommunication Union Telecommunication Standardisation Sector (ITU-T) such as VP9 and AV1 and then there are other formats which might have more specialist applications. There are lots of reasons why you know you might want to use different codecs in different scenarios, and nobody's yet agreed on a single codec that covers all the backward compatibility.
Until we get a one-size-fits-all codec, I think we are still going to see this wide range of different codecs and formats.
Get in touch.
Do you have a question for Dr Richardson related to his new book, or the wider video coding and video compression field? Then get in touch!
The most frequently asked questions will be answered and updated here over the coming year.