2011-12-14 348 views
0

我正在使用JMF連接到USB連接的攝像頭(Logitech Quickcam Pro 9000)。本相機最高可以傳輸200萬像素的視頻,但我無法將視頻格式設置爲高於320x240的任何視頻格式。打印可用的格式給了我這樣的結果:使用Java設置攝像頭分辨率(JMF)

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 

這告訴我,我應該至少能得到640×480的捕獲,但我甚至不能得到那個工作。我應該如何告訴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(); 

回答

1

仔細檢查你想要的格式字符串。至少在我的機器上,格式字符串都不包含「width = 640,height = 480」。當我循環播放支持的格式時,它們都以「RGB,640x480,長度= ...」或「YUV視頻格式:大小= ...」開頭