-
Notifications
You must be signed in to change notification settings - Fork 376
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
Add support for yuv[a]p16 pixel format and refactor video.frame.to/from_ndarray. #1722
Conversation
robinechuca
commented
Jan 20, 2025
- In order to handle yuv-to-rgb conversions yourself, it may be useful to convert frames to yuv444p16le before processing them in numpy. As described in a discussion.
- The to_ndarray and from_ndarray functions now use hash tables rather than a test tree. Complexity is therefore reduced from O(n) to O(1).
- More flexibility on the presence of a third channel for gray images.
- The automatic convertion between rgb and gbr is now optional
|
timeit.timeit(lambda: "yuv420p" in {"yuv420p10le", "yuv420p10be", "rgb24"}, number=10000000) Right now, there are more than 3 elements to compare. We can do a test to get an objective measure in this situation. Assuming I correct the first point and convince you of the second, would you be willing to reconsider this pull request? |
You're actually right for normal python (set is faster even for 1 element), but it might be a wash for Cython.
I guess using sets is okay for this PR |
Excellent idea to use frozenset instead of dynamic set! It is 11pm at home, I'll see it tomorrow. |
That would be slower? Here's my full test code: from timeit import timeit
import dis
def tuple_test():
return 7 in (3, 6, 9)
def set_test():
return 7 in {3, 6, 9}
def frozenset_test():
return 7 in frozenset({3, 6, 9})
def main():
tupt = timeit(tuple_test, number=10000000)
sett = timeit(set_test, number=10000000)
sett2 = timeit(frozenset_test, number=10000000)
print("tuple", tupt)
print("set", sett)
print("frozen set", sett2)
print(f"difference: {round((tupt - sett) / sett, 4) * 100}%")
print(dis.dis(tuple_test))
print(dis.dis(set_test))
print(dis.dis(frozenset_test))
if __name__ == "__main__":
main()
|