ralfbiedert / openh264-rs

Idiomatic Rust wrappers around OpenH264.
69 stars 35 forks source link

feat: add faster RGB to YUV conversion #40

Closed soheilsalimidev closed 1 year ago

soheilsalimidev commented 1 year ago

use libyuv for rgb to yuv color conversion which is faster than correct implementation and also adding support for argb to yuv

test on i7-11800H

-- Default --
test convert_rgb_to_yuv_1920x1080 ... bench:  10,345,450 ns/iter (+/- 1,524,720)
test convert_rgb_to_yuv_512x512   ... bench:   1,242,450 ns/iter (+/- 47,673)
-- libyuv--
test convert_rgb_to_yuv_1920x1080 ... bench:   4,223,560 ns/iter (+/- 76,388)
test convert_rgb_to_yuv_512x512   ... bench:     534,990 ns/iter (+/- 26,721)
ralfbiedert commented 1 year ago

Thanks for the PR. I'd be willing to (temporarily) link a lightweight 3rd party library for faster YUV - RGB conversion, although it would be nicer to just optimize our code.

However, the crate you propose is another native lib with complex build logic that downloads 3rd party code during compilation.

While compiling the native OpenH264 C lib to this crate was a necessity, I very much want to avoid other native libs, or anything that complicates building this crate any further.

soheilsalimidev commented 1 year ago

I agree this lib is complex and in most scenarios unnecessary but I think it is a good feature to have if someone is willing to pay the cost of having another c lib or at least can be added as an example

PS: I searched for a pure rust alternative to this lib or anything fast enough(I use this for streaming video) for this conversion but I had no luck finding one

anyway if you think it's not necessary then I think you should close it. Thanks for reviewing the PR

ralfbiedert commented 1 year ago

Alright, closing for now. I think it's better for people to link this crate themselves if they have a need for speed. That said, PRs for other format conversions in our lib are welcome.