secile / UsbCamera

C# source code for using usb camera and web camera in WinForms/WPF. With only single CSharp source code. No external library required.
MIT License
184 stars 57 forks source link

why not working in 4K? #36

Open stweily opened 5 months ago

stweily commented 5 months ago

Why fps = 1 or2 only at 3840 2160 resolution? if 1920 1080 its nomal at 30 fps.

secile commented 5 months ago

I have never tested 4k camera.

The library is based on DirectShow which is legacy technology, so that could be the reason. please refer the article below. https://stackoverflow.com/questions/63393696/4k-mjpeg-camera-video-preview-with-delay-on-windows-10

The other possibility is a lack of transfer rate. I'm not familiar with transfer rate or video codec, forgive me if I tell you wrong information.

What VideoFormat are you using? I assume that you are using YUY2 format with USB2.0 interface.

3840 x 2160 image has 8294400 pixels. Single pixel is consist of RGB 24bit, so single frame is about 23MB with uncompressed.

Video is compressed with YUY2 which compression rate is 66%, single frame is about 15MB.

USB2.0 band width is 480Mbps in spec, but it actually may 240Mbps(=30MB). Frame rate 1-2fps may be reasonable.

stweily commented 5 months ago

我从未测试过 4k 相机。

该库基于 DirectShow,这是传统技术,因此这可能就是原因。 请参考下面的文章。 https://stackoverflow.com/questions/63393696/4k-mjpeg-camera-video-preview-with-delay-on-windows-10

另一种可能性是传输速率不足。 我对传输速率或视频编解码器不熟悉,如果我告诉你错误的信息,请原谅我。

您使用什么视频格式?我假设您使用的是带有USB2.0接口的YUY2格式。

3840 x 2160 图像有 8294400 像素。 单个像素由RGB 24bit组成,因此单帧未压缩时约为23MB。

视频采用YUY2压缩,压缩率为66%,单帧约15MB。

USB2.0的带宽规格上是480Mbps,但实际上可能是240Mbps(=30MB)。 帧速率 1-2fps 可能比较合理。

but use AmCap its can 4K 30fps, use WPFMediaKit.Core (also directshow ) it 4K12 FPS!

secile commented 5 months ago

Oh, really? Could you show me a dump of return value of UsbCamera.GetVideoFormat().

var formats = UsbCamera.GetVideoFormat(cameraIndex);

// select the format you want.
foreach (var item in formats) Console.WriteLine(item);
stweily commented 5 months ago

哦真的吗? 你能给我看一下 UsbCamera.GetVideoFormat() 返回值的转储吗?

var formats = UsbCamera.GetVideoFormat(cameraIndex);

// select the format you want.
foreach (var item in formats) Console.WriteLine(item);

format.txt

secile commented 5 months ago

(1) which VideoFormat are you using? formats[2]? that is [Video], [MJPG], 3840,2160. (2) formats[0] works fine in 30fps?

stweily commented 5 months ago

(1) which VideoFormat are you using? formats[2]? that is [Video], [MJPG], 3840,2160. (2) formats[0] works fine in 30fps?

20240424172346 this is amCAP (1) I will use formats[2] and hope it work, (2) formats[0] works fine in 24- 28 fps, its ok this is our UsbCamera

1713951009575