使用 Java (JMF) 设置网络摄像头分辨率

发布于 2024-12-21 01:46:07 字数 2039 浏览 1 评论 0原文

我正在使用 JMF 连接到 USB 连接的网络摄像头 (Logitech Quickcam Pro 9000)。该相机能够以最大 2MP 的速度传输视频,但是我在将视频格式设置为高于 320x240 时遇到问题。打印可用格式给我这个结果:

MJPG, 320x240, Length=230400 0 extra bytes
YUV Video Format: Size = java.awt.Dimension[width=160,height=120] MaxDataLength = 38400 DataType = class [B yuvType = 32 StrideY = 320 StrideUV = 320 OffsetY = 0 OffsetU = 1 OffsetV = 3
YUV Video Format: Size = java.awt.Dimension[width=176,height=144] MaxDataLength = 50688 DataType = class [B yuvType = 32 StrideY = 352 StrideUV = 352 OffsetY = 0 OffsetU = 1 OffsetV = 3
YUV Video Format: Size = java.awt.Dimension[width=320,height=240] MaxDataLength = 153600 DataType = class [B yuvType = 32 StrideY = 640 StrideUV = 640 OffsetY = 0 OffsetU = 1 OffsetV = 3
YUV Video Format: Size = java.awt.Dimension[width=352,height=288] MaxDataLength = 202752 DataType = class [B yuvType = 32 StrideY = 704 StrideUV = 704 OffsetY = 0 OffsetU = 1 OffsetV = 3
YUV Video Format: Size = java.awt.Dimension[width=640,height=480] MaxDataLength = 614400 DataType = class [B yuvType = 32 StrideY = 1280 StrideUV = 1280 OffsetY = 0 OffsetU = 1 OffsetV = 3

MJPG, 160x120, Length=57600 0 extra bytes
MJPG, 176x144, Length=76032 0 extra bytes
MJPG, 352x288, Length=304128 0 extra bytes
MJPG, 640x480, Length=921600 0 extra bytes

这告​​诉我,我至少应该能够捕获 640x480 的图像,但我什至无法让它工作。我应该如何告诉 JMF 我想使用什么分辨率?

这是我现在的代码的摘录:

captureDeviceInfo = CaptureDeviceManager.getDevice(DEVICE_NAME);
Format[] formats = captureDeviceInfo.getFormats();
Format selectedFormat = null;
for(Format f : formats) {
    if(f.toString().contains("width=640,height=480")) {
        selectedFormat = f;
        break;
    }
}

try {
    mediaLocator = captureDeviceInfo.getLocator();
    DataSource videoDataSource = Manager.createDataSource(mediaLocator);
    player = Manager.createRealizedPlayer(videoDataSource);

    FormatControl fc = (FormatControl)player.getControl("javax.media.control.FormatControl");
    fc.setFormat(selectedFormat);

    player.start();

I am using JMF to connect to a USB connected webcam (Logitech Quickcam Pro 9000). This camera is capable of delivering video at maximum 2MP, however I'm having trouble setting the video format to anything higher than 320x240. Printing the available formats gives me this result:

MJPG, 320x240, Length=230400 0 extra bytes
YUV Video Format: Size = java.awt.Dimension[width=160,height=120] MaxDataLength = 38400 DataType = class [B yuvType = 32 StrideY = 320 StrideUV = 320 OffsetY = 0 OffsetU = 1 OffsetV = 3
YUV Video Format: Size = java.awt.Dimension[width=176,height=144] MaxDataLength = 50688 DataType = class [B yuvType = 32 StrideY = 352 StrideUV = 352 OffsetY = 0 OffsetU = 1 OffsetV = 3
YUV Video Format: Size = java.awt.Dimension[width=320,height=240] MaxDataLength = 153600 DataType = class [B yuvType = 32 StrideY = 640 StrideUV = 640 OffsetY = 0 OffsetU = 1 OffsetV = 3
YUV Video Format: Size = java.awt.Dimension[width=352,height=288] MaxDataLength = 202752 DataType = class [B yuvType = 32 StrideY = 704 StrideUV = 704 OffsetY = 0 OffsetU = 1 OffsetV = 3
YUV Video Format: Size = java.awt.Dimension[width=640,height=480] MaxDataLength = 614400 DataType = class [B yuvType = 32 StrideY = 1280 StrideUV = 1280 OffsetY = 0 OffsetU = 1 OffsetV = 3

MJPG, 160x120, Length=57600 0 extra bytes
MJPG, 176x144, Length=76032 0 extra bytes
MJPG, 352x288, Length=304128 0 extra bytes
MJPG, 640x480, Length=921600 0 extra bytes

This tells me that I should at least be able to get a capture of 640x480, but I can't even get that to work. How should I tell JMF what resolution I want to use?

This is an excerpt from my code as it is now:

captureDeviceInfo = CaptureDeviceManager.getDevice(DEVICE_NAME);
Format[] formats = captureDeviceInfo.getFormats();
Format selectedFormat = null;
for(Format f : formats) {
    if(f.toString().contains("width=640,height=480")) {
        selectedFormat = f;
        break;
    }
}

try {
    mediaLocator = captureDeviceInfo.getLocator();
    DataSource videoDataSource = Manager.createDataSource(mediaLocator);
    player = Manager.createRealizedPlayer(videoDataSource);

    FormatControl fc = (FormatControl)player.getControl("javax.media.control.FormatControl");
    fc.setFormat(selectedFormat);

    player.start();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

放飞的风筝 2024-12-28 01:46:07

仔细检查您想要的格式字符串。至少在我的机器上,没有任何格式字符串包含“width=640,height=480”。当我循环浏览支持的格式时,它们都以“RGB、640x480、Length=...”或“YUV Video Format: Size=...”开头

Double check the format string you want. At least on my machine none of the format strings contain "width=640,height=480". When I loop through my supported formats they all start with "RGB, 640x480, Length=..." or "YUV Video Format: Size=..."

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文