-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: B-adapt 1 should use B-frames 16 #774
Conversation
Waiting input. |
Since you have B-frames set to 3, and average video-content with hands-off approach sometimes goes to 3-7 chains in x264, I think that clear gain is ~1.5-2%. Since x264 would use B-frames in place of forced by options P-frames previously. Especially gain would be seen for videos with a static video content. Like: https://getjupiter.com/. So podcasts, live cams where camera not moving, non-gaming live streams, conferences, presentations, discussions, debates and so on, where the is less need for frequent P frames. There gain can be 2-4%. |
Also lets from the beginning distinguish the difference in ref frames option and B-frames. Ref frames increase the complexity of interlinks in the frames (between frames) and so in the chain. Primarily it impacts complexity of P-frames, and in lesser extend B-frames. And so ref option impacts encoding/decoding complexity significantly. Raising ref frames steeply increase the encoding computation requirements, MPEG4 Levels refer to ref frames option. Because option raises a requirements to the decoding complexity (somewhat) and primarily frame buffer requirements - DPB (Decoded Picture Buffer). And H.264 decoding hardware has frame buffers implemented in hardware. And hardware buffer has it's physical size, so that is why they have strict requirement/support of Levels. If P-frame refers to the frames that does not got in the buffer - P-frame gets dropped/partly decoded, and so it impacts B-frames that rely to it. That is about ref frames. ==== B-frames are not ref frames option. There is no limit on length of chain of B-frames in the standards, the length of B-frame chains does not affect decoding much. Permitting longer B-frames chains offsets it's tiny increase in decoding complexity by eliminating P-frames complexity (P-frames have the peak major complexity during decoding), so usage of B-frames sometimes even can decrease decoding complexity overall. The longer B-frames chain x264 detects - the better bit-compression we get. If in the shot - picture is still or moves gradually, naturally - we don't need frequent P-frames, B-frames would flow referring to their neighbors. |
c56cd52
to
d2c72ca
Compare
Thanks @Anton-Latukha! That was very informative, to say the least. Could you edit you PR so that is passes the linting test? Also, it would be nice if you could come to our IRC channel. We have some interesting discussions about encoding there 🙂 |
Ok, I am new to TypeScript. I would pass lint test. Then if there is instructions - I can deduct and write some asserts, if - else. But if there is more - you can run with it. |
Because I did not found your IRC channel - I got into Jupiter Broadcasting telegram channel, there guys contributing Ops/DevOps to the studio infrastructure (https://getjupiter.com), and also created a community instance (https://peertube.linuxrocks.online). I ran some tests there and would report back, as soon as would ask and receive logs. |
So at first we must solve this issue: #779 |
And then the issue of that I can not find IRC of PeerTube 8] |
IRC chan is #peertube on Freenode, and #peertube:matrix.org on Matrix. |
Matrix! Nice. Somehow I searched and not found peertube on matrix first time, still they have strange interface Also I had dramatic entrance on Matrix, and was accused of dumping a CV, while I just talked about my beneficial strengths, and at first glance to chatroom shared all info I thought useful to post in first message. So now first IRC impression - I am sad 8[ But you encouraged me there, which normalized my experience there. |
I want to wait on when Jupiter Broadcasting shares me their source footage, so I can test both on in and on: https://media.xiph.org/ footage - to get and show the real facts in real numbers. I would go into compression testing in a bulk, so I would test tweaks on different content. I switch to other tasks, I would resume, when I would receive sample of production content from JB, and would go into gathering bulk video encoding stats/tests. Or if someone wants - can run away with tests himself, obviously. |
It may be cool to create a thread on |
So the remaining linting issues:
|
@rezonant @Anton-Latukha otherwise I can just integrate the changes myself. I already have a PR related to encoding, so I can add your options with mine: e0e2bed. |
Ok. Real results: InputI ran fast-assembled encoding test on classic test - Big Buck Bunny raw source footage. It is an animation test.
ResultsThe difference is so massive and obvious, that I do not need other tests.
We already can see, that B chain (
B-frame chainsWe can see
Also we see that P-frames usage changed to B-frames usage change:
Encoding timeSo we see the time of encoding reduced mainly because it encodes much less P frames (it used to floor B-frames to 3, so x264 was forced to encode P, and they have more encoding/decoding complexity). I-frames number was the same, because algorithm of their detection does not depend on B-frames or P-frames, but on input from the source. The speed-up of encoding we got: CompressionIn stream metricWe got In filesize metric
Decoding benchmark
So, lets sum-up:
As you know - most times users have playback problems due to networking. And +4.58% better compression gives much better user expirience bump, then +2.7% of decoding complexity. Like mobile phone users - most of the time users have that 3% of CPU while playing video around, but they often rely on mobile network coverage. And 3%-5% reduction means a smoother/faster loading playback to them. And +9% to encoding speed. So we got what I said in previous messages. Encoding logsB-frames 3
B-frames 16
Now if you would allow me, please I would finish my pull request. At least to learn and understand TypeScript better, maybe I would start committing some simple additions in it, or understand TypeScript processing more. Sorry for some time spent waiting, as I was getting the facts straight, so we all can be sure that this global change is in right direction. |
I forgot to do SSIM/PSNR check. But as we use default |
@Anton-Latukha thanks for the extensive debug! 😮 Of course we can let you correct your PR. If you want to use the linter locally on your machine to have feedback, you can use Basically this is just your way of formatting the comments, à la JSDoc, which is not correct JSDoc formatting. Simple comments without asterisks would not make the linter show errors 🙂 |
d2c72ca
to
e02a0a7
Compare
e02a0a7
to
f000f72
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for the hard work @Anton-Latukha
Thank you for PeerTube. |
This change in the case of streamingOften, changing video-encoding settings leads to handicapping of streaming. I decided also to mention thoughts relating to this, as this is important factor here. Also I see no problems with big B-frame chains for rewinding/streaming. In the middle of stream playback recovers info from I-frame anyway. As I-frame it is the only solid starting point to calculate from. And first x264 determines places of I-frames, and then P&B-frames placing depends on I-frame place. We saw that I-frames does not depend on change we do. Also, if player positions only on I frames - again, they are not touched by this change. And if player permits placing on I&P&B - there is no difference for that player what frame is under the timestamp. And so with data downloaded during rewind/coming in the middle of stream - player always does the same. Searches for I-frame, and calculates video data from it, to position it needs. |
I'm in the progress of introducing hardware acceleration support for PeerTube and came across this. I have a feeling this very commit has caused videos on PeerTube to come across the viewer very blocky (example here). Was any VMAF testing done before and after? It may also be bitrate related? I'm a novice when it comes to ffmpeg, do enlighten me if my contemplation is incorrect. |
Preface
There is huge number of options in x264.
I had some experience, hobby of encoding videos.
And I looked at your settings, and most of that settings don't need tweaking.
I know that most of that x264 options are provided from FFmpeg defaults.
B-adapt 1 and B-frames number is the old trope that I find on and on, and I fight against it for many-many years. Over years I saw that error even in many big video-streaming services, because system around the question has a predisposition to overlook the proper answer.
It is ideal PeerTube is Open Source and you are open for contributions. So as soon I saw that we can make the most important and effective fix for PeerTube encoding - I came to you.
Short history of B-adapt
In the invention of x264, B-frames was introduced.
x264 picked B-frames by the number in the B-frames option, and the pattern on I BBBB P BBBB ... frames.
Despite being primitive it was giving a pretty good results, comparing to MPEG2.
That is how x264 worked for a number of years.
For a long time no one could invent adaptive algorithm to pick B-frames.
In the end it was invented.
https://www.videohelp.com/software/x264-Encoder/version-history
And for long time was in experimental stage.
During that time,
b-adapt 2
was invented.Original thread: https://forum.doom9.org/showthread.php?t=139827
Conclusion
You probably already see the pattern in messages.
The story is:
B-adapt 1 was created in heuristic way with skip-hacks and with a lot of polish on top. B-frames option does affect algorithm but not in the speed/complexity way. In fact in many cases B-frames 16 runs a tiny bit faster while producing a better results. It was also my experience, but it was years ago.
B-adapt 2 does the proper by logic the path of analysis, so the bigger the chain of B-frames allowed - the more it's tree of analysis grows.
From then-on the improvements in B-adapt 2 and B-adapt 1 go toe to toe.
But heuristic/hacked B-adapt 1 turned-out very productive.
Maybe I need to make new tests, but I am sure as dev-logs show the old parity.
For reference:
2.a B-adapt: https://en.wikibooks.org/wiki/MeGUI/x264_Settings#b-adapt
2.b B-frames: https://en.wikibooks.org/wiki/MeGUI/x264_Settings#b-frames
b-adapt
/b-frames
, in two places, one of them was right.