News for hackers. Stuff that matters.
Re:Netflix is now doing per-shot encoding for UHD content by crazygringo on Friday August 28, 2020 @08:36PM (#24312122)
> It's really too bad that they haven't rolled this out for 1080p too

Maybe they will? But it matters most for 4K performance, so that's where they started?

> encoders (x264, x265, etc) already have their own rate control algorithms

But they simply operate on a stream without taking future frames into account. This does a first entire pass on the film holistically to determine where keyframes should go and settings per-shot. It can't be backported to codecs because they work linearly.

> And even with that, depending on how sensitive you are to artifacts, some of the "optimized ladder" encodes still look worse.

The artifacts look worse only because it's zoomed in so crazy far. On a cinema screen, the additional sharpness will be clear, the artifacts not so much.

Re:Netflix is now doing per-shot encoding for UHD content by bscphil on Friday August 28, 2020 @08:44PM (#24312178)
> This does a first entire pass on the film holistically to determine where keyframes should go and settings per-shot. It can't be backported to codecs because they work linearly.

Given that x264 already has a 2 pass mode, I don't see why that is necessarily the case. Even CRF mode uses mbtree by default, which is a pretty complicated rate control algorithm. x264 also has pretty intelligent keyframe determination, I almost always see I frames on scene transitions.

> On a cinema screen, the additional sharpness will be clear, the artifacts not so much.

I think it's probably the other way around. The closer you are to a screen, the more likely you are to notice increased resolution. But if there are large patches of the image full of artifacts, you'll be likely to see that even far away.

Re:Netflix is now doing per-shot encoding for UHD content by zbobet2012 on Friday August 28, 2020 @09:19PM (#24312397)
> Given that x264 already has a 2 pass mode, I don't see why that is necessarily the case. Even CRF mode uses mbtree by default, which is a pretty complicated rate control algorithm. x264 also has pretty intelligent keyframe determination, I almost always see I frames on scene transitions.

x264 will not align keyframes across resolutions and encodes. In addition the pershot encodes optimize more than just idr frame placement. They also optimize other encoder parameters such as aq.

> I think it's probably the other way around. The closer you are to a screen, the more likely you are to notice increased resolution. But if there are large patches of the image full of artifacts, you'll be likely to see that even far away.

That isn't how this works. It's not a strict tradeoff between more artifacts and less sharpness by changing resolution. Downscaling -> Upscaling is simply another form of lossy compression. It may look better or worse than using those bits in another spot.

Re:Netflix is now doing per-shot encoding for UHD content by bscphil on Friday August 28, 2020 @09:27PM (#24312448)
> x264 will not align keyframes across resolutions and encodes. In addition the pershot encodes optimize more than just idr frame placement. They also optimize other encoder parameters such as aq.

Sure, that's true. (Though I don't know why it matters that keyframes aren't aligned.) But at the end of the day the point is that Netflix has a better rate control algorithm, and this could be built into x264, even if it might require a significant amount of work. (Which I'm sure the x264 developers would be willing to do for a substantial quality improvement.)

> That isn't how this works. It's not a strict tradeoff between more artifacts and less sharpness by changing resolution.

Of course it's not a strict tradeoff. It's a loose one. And yes, it may look better or worse. That's really my only point in that section of the comment: that bumping up the resolution earlier in the ladder as they're doing is not a pure win, and it may look worse to some people depending on their viewing conditions.

Re:Netflix is now doing per-shot encoding for UHD content by zbobet2012 on Friday August 28, 2020 @09:54PM (#24312608)
> Sure, that's true. (Though I don't know why it matters that keyframes aren't aligned.) But at the end of the day the point is that Netflix has a better rate control algorithm, and this could be built into x264, even if it might require a significant amount of work. (Which I'm sure the x264 developers would be willing to do for a substantial quality improvement.)

You can't ABR adapt without aligned GOP boundaries.

> Of course it's not a strict tradeoff. It's a loose one. And yes, it may look better or worse. That's really my only point in that section of the comment: that bumping up the resolution earlier in the ladder as they're doing is not a pure win, and it may look worse to some people depending on their viewing conditions.

Of course not, that's why the perform an analysis of both options and select the better one. That's what the algorithm does...

Re:Netflix is now doing per-shot encoding for UHD content by bscphil on Friday August 28, 2020 @10:13PM (#24312721)
> You can't ABR adapt without aligned GOP boundaries.

Yes, that's true of course, but not really relevant to whether you could port Netflix's work on scene-adaptive rate control to x264. Maybe you'd lose aligned GOPs... but for a lot of purposes (offline?) that doesn't matter.

> Of course not, that's why the perform an analysis of both options and select the better one. That's what the algorithm does...

The only point I've ever tried to make on this subject is that in some cases this approach fails. "Perform an analysis" is such a high level description that it misses the fact that this is being done according to some objective metric that may disagree with an individual viewer's personal preferences or viewing environment. In fact, just because an objective metric says 4k > 1080p doesn't mean the difference will be noticeable at the viewing distance the viewer is at, whereas the additional artifacts introduced by moving from 1080 -> 4k without a significant bitrate increase may very well be visible!

Re:Netflix is now doing per-shot encoding for UHD content by out0fpaper on Friday August 28, 2020 @08:46PM (#24312186)
Existing encoders have suported this for ages using multipass. In the first pass of multipass encoding, the input data from the source clip is analyzed and stored in a log file. In the second pass, the collected data from the first pass is used to achieve the best encoding quality. In video encoding, two-pass encoding is usually controlled by the average bitrate setting or by the bitrate range setting (minimal and maximal allowed bitrate) or by the target video file size setting.

The best way to understand why this is used is to think of a movie — when there are shots that are totally, absolutely black, like scene changes, normal 1-pass CBR encoding uses the exact same amount of data to that part as it uses for complex action scene. But by using VBR and multipass, encoder “knows” that this piece is OK with lower bitrate and that bitrate can be then used for more complex scenes, thus creating better quality for those scenes that require more bitrate.

Re:Netflix is now doing per-shot encoding for UHD content by bscphil on Friday August 28, 2020 @08:53PM (#24312227)
My point is that if Netflix thinks they can do better, it would be great to see their code contributed to the public, since they're using an open source program to do all their encodes.

Also, you're making a slight mistake. About a decade ago (?), x264 was changed so that even 2-pass mode is really just using CRF under the hood. It's not "achieving the best quality", it's just figuring out what quantizers you need to hit your average bitrate target exactly. Some more information about that here: https://trac.ffmpeg.org/wiki/Encode/H.264

> normal 1-pass CBR encoding

You may be confusing constant bitrate (which no one should ever use) with CRF (constant rate factor), which varies the bitrate from frame to frame and scene to scene, without having to do a 2 pass encode.

Re:Netflix is now doing per-shot encoding for UHD content by dmurray on Friday August 28, 2020 @09:26PM (#24312441)
> My point is that if Netflix thinks they can do better, it would be great to see their code contributed to the public, since they're using an open source program to do all their encodes.

This really is their core business and somewhere they can have a competitive edge, though. Even if you think it's unethical or that it might make business sense to contribute back to the upstream projects, you can see why they might want to keep some of that secret sauce in-house.

Re:Netflix is now doing per-shot encoding for UHD content by bscphil on Friday August 28, 2020 @09:29PM (#24312463)
Fair enough, I'm not arguing that they're obligated to or anything, I just think it would be nice. I do suspect that catalogue matters much more at this point than any tiny competitive advantage they get through better encoding. And they've certainly been willing to share advances (like VMAF) in the past - that's why this tech blog exists, after all!
Re:Netflix is now doing per-shot encoding for UHD content by ponker on Friday August 28, 2020 @10:43PM (#24312900)
Bandwidth is a huge cost for these services and if they share encoding techniques then their competitors can cut prices at the margins.
Re:Netflix is now doing per-shot encoding for UHD content by ksec on Sunday August 30, 2020 @01:59AM (#24321661)
>since they're using an open source program to do all their encodes.

Is that still the case? They switched from x265 to beamr for HEVC. Not sure if they are still on x264 on recent encodes.