Skip to content
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

Modification of the EncodeVideo method - GC optimization #8

Open
o-miko opened this issue Jan 3, 2025 · 2 comments
Open

Modification of the EncodeVideo method - GC optimization #8

o-miko opened this issue Jan 3, 2025 · 2 comments
Labels
enhancement New feature or request

Comments

@o-miko
Copy link

o-miko commented Jan 3, 2025

Dear all,

I would like to ask you, if it would be possible to implement a method for video encoding that would have one extra parameter, that would be of data type byte[] and would be the result of encoding. And the method would be of void return type. The method would not create new byte[] instances as it does now, but overwrite the input byte[] which would be the result. Furthermore, a method to calculate the resulting byte[] size would need to be implemented. This would reduce the resulting amount of byte[] instances and thus reduce the Garbage Collector (‘GC’) overhead resulting in increased application performance.

For better understanding please see my code below:
1

  1. There are constantly new byte[] instances that the GC must remove. And because of real-time video, it produces a large amount of instances.

Why would I like to see the above-mentioned change? So that I can create arrays using ArrayPool and actually just send that given array as a parameter that would be filled with encoded image. This method shouldn't load the GC that much.

Please see the example below to better understand my vision. I would like to achieve something similar to this:
2
3

Where do I see the problem?

Unnecessary GC loading. IVideoEncoder doesn't have any such method that would return the size of the resulting byte[] as a result. And EncodeVideo doesn't have a possibility to override the parameter that would be the output byte[], but it keeps creating new byte[] instances. I use VpxVideoEncoder

Many thanks in advance for your reply. And please accept my apologies if the mistake is on my side or if it is not possible to implement the method this way.

Kind regards,

OM

@sipsorcery
Copy link
Member

Sounds reasonable. Would you be interested in creating a PR for the new method?

@sipsorcery sipsorcery added the enhancement New feature or request label Jan 3, 2025
@o-miko
Copy link
Author

o-miko commented Jan 4, 2025

I can try to do that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants