Comments (5)
The positions of the numerator and denominator of MF_MT_FRAME_RATE
(https://learn.microsoft.com/en-us/windows/win32/medfound/mf-mt-frame-rate-attribute) seem to be different between SetCurrentMediaType
and GetCurrentMediaType
.
With this ugly byte swap I get the correct frame_rate
let mut bytes: [u8; 8] = unsafe { media_type.GetUINT64(&MF_MT_FRAME_RATE) }
.unwrap()
.to_ne_bytes();
bytes.swap(0, 4);
bytes.swap(1, 5);
bytes.swap(2, 6);
bytes.swap(3, 7);
let frame_rate = u64::from_ne_bytes(bytes);
println!("Frame rate: {}", frame_rate as u32);
from nokhwa.
There is something strange going on, it seems that Windows is trying to correct the endianness of the two u32
(numerator and denominator).
With the "wrong" endianness (the one used by the library):
Bytes IN SetCurrentMediaType: [0, 0, 0, 1, 0, 0, 0, 60]
Bytes OUT GetCurrentMediaType: [1, 0, 0, 0, 60, 0, 0, 0]
With the "correct" endianness:
Bytes IN SetCurrentMediaType: [1, 0, 0, 0, 60, 0, 0, 0]
Bytes OUT GetCurrentMediaType: [1, 0, 0, 0, 60, 0, 0, 0]
from nokhwa.
I also fear that since the framerate is represented as numerator/denominator there could be devices that use framerates like 29.97 that can be represented as 2997/1000 and nokhwa is going to read 2997 as the framerate.
from nokhwa.
I just found out this issue was already reported #110 and #139
from nokhwa.
I think I get what's happening:
nokhwa is using the wrong endianness for the two u32
that represents the numerator and denominator, since
nokhwa/nokhwa-bindings-windows/src/lib.rs
Lines 1027 to 1033 in dbdb42b
it's writing the two
u32
in big-endian inside the u64
:[0, 0, 0, 1, 0, 0, 0, FRAMERATE]
instead of [1, 0, 0, 0, FRAMERATE, 0, 0, 0]
.Then Windows converts it to
[1, 0, 0, 0, FRAMERATE, 0, 0, 0]
(I don't know why, but it's trying to fix this mistake).In the end Windows use the correct endianness when answering to
GetCurrentMediaType
and nokhwa read it wrongly (it reads the denominator instead of the numerator).
The fix required to make it works is to review the way that these number are built and parsed, also beacause currently it can't support more than 255 FPS. This also includes the part of code that build the list of available formats.
Also nokhwa should keep in mind that there might be some framerates that are not X/1 (like 2997/1000), I think here we have 2 solutions that doesn't require to rewrite the frame_rate
handling:
- Return an error when the framerate is not X/1
- "Transform" A/B -> X/1 rounding X (es. 2997/1000 -> 30/1)
from nokhwa.
Related Issues (20)
- Multiple AVFoundation cameras on macOS panics with an NSException
- yuv422 confusions? HOT 2
- Compile issues on v4l2_pix_format in linux kernel 6.2 HOT 3
- Can't compile on archlinux 6.5.5-arch1-1 HOT 1
- Unable to access capture card on windows HOT 1
- Use AVCaptureDeviceTypeExternal on macOS
- what FrameFormat::GRAY is?
- Incorrect pixel format HOT 1
- AVFoundation backend is not passing the frame format HOT 1
- Meta: Current Status, Progress and Future Plans for this Project HOT 12
- Support for macOS continuity camera HOT 3
- Possible unsoundness HOT 1
- Switching devices leads to assertion failure at the device list. HOT 1
- threaded camera deadlock on stop stream HOT 1
- [Windows] Panic when no cams are connected
- [Request] BGR and GBR support HOT 1
- [Web] Update `jscam` example to function correctly in the latest version
- Build fails on multiple versions on Pop_OS! HOT 2
- v4l camera indexing isn't necessarily accurate
- Support AV1 coder
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nokhwa.