333 points · by tosh · 2y ago · 205 comments
For their use case Meta is gradually getting to a baseline of VP9 and AV1 streams for their video streaming: https://www.streamingmedia.com/Producer/Articles/Editorial/F...
And AV1 for video calls: https://engineering.fb.com/2024/03/20/video-engineering/mobi...
Microsoft is starting to use AV1 in Teams. AV1 has video coding tools that are particularly useful for screen sharing: https://techcommunity.microsoft.com/t5/microsoft-teams-blog/...
Most of the video I see on YouTube these days is in VP9 or AV1. Occasionally some video is still H.264.
H.264 will still be around for quite some time, but AV1 looks set to become the new baseline for internet video.
YouTube does H.264, VP9, and AV1 video encodes with AAC and Opus audio encodes.
This video for example has encodes of all those options: https://www.youtube.com/watch?v=ArmDp-zijuc
You can watch it in multiple resolutions and formats from 4K in AV1 down to 144p in H.264.
Also, OBS handles AV1 nicely, but you can’t stream to a site like Twitch because they only support H264 outside of specific experiments.
That said, Arc GPUs are nice, I have an A580 and while the drivers aren’t as mature as Nvidia or AMD, I got it for a pretty good price and they’re gradually patching things out.
AV1 is bloody awful to encode in software.
I was recording videos of lectures (a slowly moving person against a whiteboard with thin sharp lines on it, in a questionably well-lit room) and needed to encode them to smallish 720p files to be posted somewhere (ended up uploading them to the Internet Archive). This is not something that x264’s default encoding profiles do well on, but with a day or two of fiddling with the settings I had something I could run on my 2014-era iGPU-only laptop the night after the lecture and have the result up the next day.
By contrast, libaom promised me something like a week of rendering time for the three hours of video. Perhaps this could be brought down (my x264 fiddling got me veryslow-comparable results several times faster), but the defaults were so bad I couldn’t afford to experiment. (This was some four years ago. Things have probably gotten better since then, but I don’t expect miracles.)
My command:
ffmpeg.exe -i file.mp4 -r 23.976 -vf scale=1280:720 -c:v libsvtav1 -pix_fmt yuv420p10le -crf 30 -preset 10 -g 600 -c:a libopus -b:a 96k -ac 2 -c:s copy -map 0 out.mp4
Try it.
That would do it.
The reference AOM was never a practically useful encoder even 4 years ago.
> I couldn’t afford to experiment
Pity as you'd discover a better encoder...
The real problem with AV1 is how darn computationally intensive it is to compress.
H.264 gets enough of a compression boost from 10-bit math that you should be using it anyway.
I don't know if this affects H.265
> The real problem with AV1 is how darn computationally intensive it is to compress.
How are you measuring that?
It's true that SVT-AV1 is slower than x264 at preset 6 or below. And it's slower than x265 at preset 3 or below. But those aren't the presets you use if you want to be fast.
SVT-AV1 can match the quality of x264 veryslow while running at the speed of x264 veryfast.
It can match the quality of x265 veryslow while running at the speed of x265 medium.
It can match the quality of x265 medium while running at the speed of x265 ultrafast.
https://engineering.fb.com/wp-content/uploads/2023/02/AV1-Co...
which i think is fine, as most decompression is on user side, but compression is on server side (and mostly only ever done once!).
This is 100% use case dependent.
For Netflix, compression is only done once and decompression happens a ridiculous amount of times.
For YouTube, popular channels are similar to Netflix; but they suffer from a very very long tail of videos which only get watched a handful of times.
For chat applications, videos may get watched only once by the recipient.
For video conferencing, videos get compressed once (on the client's machine even, so ideally using hardware encoding), then decompressed once per recipient. This use-case also has the issue that every client needs to decode every other client's video stream, so you better send video in a format which every client can quickly decode (ideally using hardware decoding).
Notice how "slow compression is fine because decompressing happens much more frequently" is only true for the Netflix use-case and the popular YouTube channels use-case. For everything else, slow compression is a problem.
(Luckily, at least according to others here, AV1 isn't necessarily slow to encode, it's just the reference implementation that's slow and there are software implementations which match the speed of x264. I haven't verified this though)
It is true that for many purposes we can offload encoding onto servers. However, as someone that frequently deals with live video streaming, AV1 is still out of reach on most hardware I am on and VP9 has only been viable for less than a decade. Yes, VP9 and AV1 are superior in terms of quality, but it is truly remarkable that H.264 runs as well as it does and I wish we had a similar unencumbered lightweight/portable codec (VP8 in my experience is about as heavy as VP9 and offers about the same quality as H.264).
At least for audio we now have Opus and Flac (plus MP3 having had its vile patents expire), so hopefully video is the last frontier and VP9 and AV1 will become the standard over this decade.
can't shake the feeling that most videos at 720p took a hard hit to quality within the last years (or my eyes are getting better)
any deep dives on the topic appreciated
My gut feeling is that implementations of hardware acceleration are just simply not as good as software implementations, the cause perhaps relating to localised resource constraints in hardware when recursing deeper or somesuch.
The algorithms are the same, the chip versions are more resource constrained as the stack goes deeper if you will.
Hardware compressors are much much faster, no doubt, by an order of magnitude and more .. but software compressors left to run slow, with two passes, just produce a much better result.
Standard hardware compressor settings tend to leave moire patterns when the camera pans outside a chain link fence onto a player inside a court (for example), or leaves a blocky halo around the significant figure point of interest moving in an otherwise stillish scene - it's subltle small things that grate when you see them.
The root cause of perceived downgrade in quality is bulk pushing of high quality originals through hardware accelerated compression in order to save time and reduce cost when generating lower bitrate versions to stream.
Hardware encoders are much more restrictive. They will target a maximum resolution and frame rate, realtime encoding a possibly low latency as requirement.
The standards define the bitstream, but is lots of scope for cheating to allow for simpler hardware implementation. You could skip motion prediction and use simple quantisation, it would just contribute to the residual entropy that needs to be encoded. Then, you can use inefficient implementations of the entropy encoders. The end result is something that can be interpreted as a valid bitstream but threw out all the algorithmic tricks to give you high quality compressed video.
I think specifically in terms of YouTube, it’s not a hardware encoding issue but it’s a purposeful optimisation for storage and bandwidth.
Poking more, there's an AV1 version that's a little less bad at about the same bitrate, but it's still significantly worse than the old encode. There's also a new version of H.264 that's 2/3 the size of the old one. It's about as bad as the VP9 version but the artifacts focus on different parts of the image.
You'd think after 15 years of storage prices dropping, bandwidth prices cratering, and screens getting bigger, youtube might decide to maintain bitrates and let new codecs increase the quality of videos. Or split the difference between quality and savings. But nah, worse.
I don't have a comparison for decode speed, but software encoding of AV1 is able to match the performance of x264 veryfast while looking vastly better.
H.264 is Magic (2016) - https://news.ycombinator.com/item?id=30710574 - March 2022 (219 comments)
H.264 is magic (2016) - https://news.ycombinator.com/item?id=19997813 - May 2019 (180 comments)
H.264 is Magic – a technical walkthrough - https://news.ycombinator.com/item?id=17101627 - May 2018 (1 comment)
H.264 is Magic - https://news.ycombinator.com/item?id=12871403 - Nov 2016 (219 comments)
https://meta.wikimedia.org/wiki/Have_the_patents_for_H.264_M...
This is not surprising, given that the first version of the H.264 standard was published in 2003 and patents are usually valid for 20 years.
Its predecessors, H.263 and MPEG-4 ASP, have already patent-expired and are in public domain.
FWIW, as someone who is a complete layman on this topic but has spent much of the past 6 months converting age-old videos to h265...
i have a pi5 where i queue up old videos into a RAM disk, it converts them to h265, and moves them back to the machine which uploaded them. It can take up to 2 days to compress any given video (depending mostly on the input format - old AVIs tend to compress in a few hours), but the space savings is _much_ higher than what you're reporting. The average size of my h265-encodes is anywhere from 1/3rd to 1/2 of the original, and 1/4th of the original is not terribly uncommon. That said: the input formats vary wildly, with possibly only a minority fraction being h264.
i've tried the same thing using a pi4 but it needs roughly 4-5x as long as the pi5. An 8-core intel-based laptop can do it in some 25% of the time of the pi5 but pulls a lot more electricity while doing so. So my otherwise idle pi5 gets the assignment.
My Firefly collection (14 tv episodes plus the movie) dropped from 8gb to 2.1gb. My Bob Ross collection (141 videos) went from 38gb to 7.4gb. 128 Futurama episodes/movies was cut from roughly 50gb to 21gb.
i was once asked why i didn't choose AV1 and the answer is simple: when i googled along the lines of "how to get the best video compression with ffmpeg" the most common answer was h265. Whether that's correct or not, i can't say, but it works for me and i've freed up the better part of a terabyte of space with it.
I do most of my encoding on an i9-13900k. I've also noticed that h.265 seems to be quite a bit more likely to trigger the smt related crashes in ffmpeg, which makes it a pain when I've queued up a lot of things to encode over night.
I’ve started reading this article which list the various H.26x proposals - https://en.m.wikipedia.org/wiki/Video_Coding_Experts_Group
Seems like the group that comes with these is eventually part of the UN ? https://en.m.wikipedia.org/wiki/International_Telecommunicat...
Is it because they come with the codecs “jointly” with the MPEG organization, which is for profit? If the group is part of a standards organization that’s part of the UN, I feel like they should come up with non-patent-encumbered “recommendations”.
There are multiple patent pools for H.265 wanting to be paid licensing fees (MPEG LA, HEVC Advance, Velos Media). HEVC Advance and Velos Media even want content distribution licensing fees.
And there are patent holders not in any pool who also want to be paid (Technicolor, Motorola, Nokia, etc.).
It's a mess.
It's really like H.264 all over again where everyone claims the patent pools make a big difference but only on the periphery.
While some cameras do support it, it's much more common to use ProRes, DNxHD/DNxHR or h264 in all-intra mode (as e.g. in XAVC-I and XAVC-S-I).
h265, or long-GOP codecs in general, are only really used for long talking head shots or lectures.
Also I haven't seen charts of decode difficulty, but as far as encoding goes, codecs a generation more advanced can crush H.264 at any particular level of effort. The even newer codecs can probably get there too with more encoder work. https://engineering.fb.com/wp-content/uploads/2023/02/AV1-Co...
I’m not sure I’d trust x265 to preserve film grain better than x264 —tune film unless I gave x265 much, much more time as well as pretty similar bitrate.
Somewhat unfortunate that never became anything.
I had some old, gigantic, video footage (in a variety of old, inefficient, formats at a super high quality).
So I did some testing and, well, ended up re-encoding/transcoding everything to H.265. It makes for much smaller files than H.264. The standard is also ten years younger than H.264 (2013 for H.265 vs 2003 for H.264).
Ended up having a long conversation with the husband (the engineer) and he hinted many times that they were working currently on something even better. Years later now of course we have H265. Everytime I play something in H264 or H265 I think of that moment and how much work that guy and his colleagues must have put into coding such a widely used codec (and how proud his wife was!)
I deal with a lot of video and HEVC is by and far the most used codec that I see.
I am not sure why AV1 vs VVC will go any differently.
Just like HEVC was about a generation better than VP9, VVC is about a generation better than AV1.
I guess it depends on what streaming companies choose. Since they all chose HEVC, all the cheap player chips in TVs and boxes and sticks all have HEVC hardware decode. Even though YouTube chose VP9, it didn't really seem to make a difference in the grand scheme of things.
YouTube chose AV1 of course, but if all the streaming companies go VVC, well then I think it will proliferate similarly to HEVC.
But it is currently being used in India and China already. So its usage is much bigger than a lot of people would imagine.
HEVC is patent encumbered. Users who use old hardware don't have hardware decoder. So both requires more time to be adopted.
It sure gets the file size down though.
There appears to be some lossy compression on that string of "H"s.
At that time, I was obsessed with mplayer and would download and build the latest releases on a regular basis. The first time I got an h264 file, mplayer wouldn’t read it so I had to get the dev version and build it.
It worked, and I realized two things : the quality was incredible, and my athlon 1800+ couldn’t cope with it. Subsequent mplayer versions ( or libavcodec ?) vastly improved performance, but I still remember that day.
I used to work for a company that was developing some video based products. And this other company in Vegas sold our bosses a "revolutionary video codec" and a player. We had to sign NDAs to use it.
I used it and observed that it worked like mplayer. Too much like it. 5 more minutes of investigation and the jig was up. Our execs who paid a lot of money to the Vegas company had an egg on their face.
It is shockingly easy to scam non-tech decisions makers in the tech field. They are too worried about being left behind. Smart ones will pull in a "good" engineer for evaluation. Dunning Kruger subjects will line up with their wallets out.
Back in 1999, I was leaving a startup that had been acquired, but I didn't want to stick around. I had been doing in mpeg encoding; this is relevant later.
One of the companies I interviewed with had come up with a new video compression scheme. They were very tight lipped but after signing NDA paperwork, they showed me some short clips they had encoded/decoded via a non-realtime software codec. I was interviewing to create an ASIC version of the algorithm. Even seeing just a minute or two of their codec output, I guessed what they were doing. I suggested that their examples were playing to the strengths of their algorithm and suggested some scenarios that would be more challenging. I also described what I thought they were doing. They neither confirmed nor denied, but they had me come back for a second round.
In the second round I talked with the founders, a husband/wife CEO/CTO (IIRC) team. That is when I learned their plan wasn't to sell ASICs, but they wanted to keep their codec secret and instead create DSL-based cable network using the ASICs for video distribution. I said something like, it sounds like you have invented a better carburetor and instead of selling carburetors you are planning on building a car factory to compete with GM. It was cheeky, and they didn't take it well.
Getting to the point of how this story relates to H.264, their claim was: conventional compression has reached the limit, and so their codec would allow them to do something nobody else can do: send high-def video over DSL lines. I replied: I think compressors will continue to get better, and even if not, higher speed internet service will eventually come to houses and remove the particular threshhold they think only they can cross. Oh, no, they replied, physics dictates the speed bits can be sent on a wire and we are at that limit.
I didn't get (and didn't want) a job offer. The company did get some VC money but folded a few years later, much more efficient codecs were developed by others, and 2 Mbps internet connections were not a limit. I'm sure the actual algorithm (which I describe later at a high level) had a lot of clever math and algorithmic muscle to make it work -- they weren't stupid technically, just stupid from a business sense.
This retelling makes me sound like a smug know-it-all, but it is one of two times in my life where I looked at something and in seconds figured out their secret sauce. There are far more examples where I am an idiot.
What was their algorithm? They never confirmed it, but based on silhouette artifacts, it seemed pretty clear what they were doing. MPEG (like jpeg) works by compressing images in small blocks (8x8, 16x16, and a few others). That limits how much spatial redundancy can be used to compress the image, but it also limits the computational costs of finding that redundancy. Their codec was similar to what Microsoft had proposed for their Talisman graphics architecture in the late 90s.
From what I could tell, they would analyze a sequence of frames and rather than segmenting the image into fixed blocks like mpeg, they would find regions with semi-arbitrary boundaries that were structurally coherent -- eg, if the scene was a tennis match, they could tell that the background was pretty "rigid" -- if a pixel appeared to move (the camera panned) then the nearby pixels were highly likely to make the same spatial transformation. Although each player changed frame to frame, that blob had some kind of correlation in lighting and position. Once identified, they would isolate a given region and compress that image using whatever (probably similar to jpeg). In subsequent frames they'd analyze the affine (or perhaps more general) transformation from a region from one frame to the next, then encode that transformation via a few parameters. That would be the basis of the next frame prediction, and if done well, not many bits need to be sent to fix up the misprediction errors.
https://www.zdnet.com/article/high-hopes-for-video-compressi...
It says they raised $32M from VCs, came out of stealth mode in 2002. I was unable to find what happened after that.
> ...that hope to deliver broadcast quality programming over the Internet--the holy grail for nascent video-on-demand (VOD) services
What year did we all suddenly stop using the term "video-on-demand" and start saying "streaming"? I don't remember it happening, but obviously it did.
Well at least "broadcast quality" still means the same thing. An ancient antenna on my roof can still kick Youtube's ass when it comes to clarity and resolution.
"VOD" is still used pretty frequently in some contexts to distinguish between live and prerecorded video. It's common parlance on Twitch, for example.
> An ancient antenna on my roof can still kick Youtube's ass when it comes to clarity and resolution.
How so? ATSC is MPEG-2 at an absolute maximum of ~18 Mbps - and most broadcasters cut it down much lower than that to add subchannels. It doesn't support 1080p60 video at all, only 1080p30 or 720p60. Youtube routinely uses higher resolutions and bitrates, as well as newer codecs (H.264 at the oldest).
I wouldn’t call them “stupid technically”, but assuming that there was a hard limit to codec efficiency and to internet bandwidth would at least make them technically naive in my opinion.
It is a cool article, just, wowzers, what a phrase.
userbinator points at https://meta.m.wikimedia.org/wiki/Have_the_patents_for_H.264..., but most of the patents there have a precedence date after the h.264 standard was finalized, and therefore can't be necessary to implement h.264 itself (unless the argument is that, at the time it was standardized, it was not known to be implementable, a rather implausible argument)
what's surprising is that the last 20 years have produced a few things that are arguably a little better, but nothing that's much better, at least according to my tests of the implementations in ffmpeg
it seems likely that its guaranteed patent-free status will entrench it as the standard codec for the foreseeable future, for better or worse. av1 has slightly better visual quality at the same bandwidth, but is much slower (possibly this is fixable by a darktangent), but it's vulnerable to patents filed by criminals as late as 02018
Ah, if we get through year 2038 we get latent free AV1!
Also, he uses that (and no capital letters) as a "bozo filter" - anyone who replies about that rather than the substance of the comment, he defines as someone he doesn't want to talk to anyway.
Personally, I think it's rather an obnoxious move. He's deliberately derailing discussion about the content, and he has decent content. But he insists on playing this game instead of just talking about the substance.
(i recommend you knock it off)
but yeah, the main benefit is that it gets people to read about the long now foundation
That was 2016. Today, it's because Youtube knows you're on Firefox.
The core of any lossy visual compressor is approximately the same theme. Those I-frames are essentially jpegs.
1015 kB: https://sidbala.com/content/images/2016/11/outputFrame.png
In PNG, you look for an image with 100 - 200 colors (so that colors repeat more often) and losslessly encode it with DEFLATE.
In JPG, you look for an image with with a reduced description through DCT, and losslessly encode it with Huffmann trees.
If color quantization using a specific algorithm was part of PNG you could say its lossy compression, its not, PNG is not lossy compression by any definition. Your specific image processing pipeline might be lossy, based on various tools you ran the image through or equipment used to capture, PNG is not.
Disclosure: I'm an investor.
Oh no, not again....
1015 kB: https://sidbala.com/content/images/2016/11/outputFrame.png
PNG loss no information from the image being fed to it, the loss was done before creating a simpler image.
The actual point of that example isn't even about lossy vs lossless anyway, it's about how 300 frames can take up nearly the space as one frame (interframe compression).