繁体   English   中英

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

[英]Setting the webcam resolution with Java (JMF)

我正在使用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();

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM