我正在尝试编写一个自定义软件(在python中)来从帧抓取卡中抓取帧(Hauppauge WinTV-HVR-1900),我无法让它工作。捆绑的WinTV软件运行完美,我可以从USB网络摄像头抓取帧,所以我知道硬件工作。我设法捕获了一些东西,因为我的屏幕完全是黑色但是改变了正确的大小和分辨率,所以我的预感是它是某种解码问题。
有人可以帮我提供指示或提供从这些硬件中提取帧的代码示例吗?我应该写一个完整的自定义驱动程序或者也许使用VLC python bindings(因为VLC确实成功读取了视频流)?
基本上,我的问题归结为:我的图像采集卡与网络摄像头有什么不同,因为集成的硬件编码器产生MPEG-2流?不应该像我的网络摄像头那样表现?
我的尝试的逻辑文件(在Windows 7上使用pyQt4的pyQt4的QT框架):
#-*- coding: utf-8 -*-
import sys
from VideoCapture import Device
#import Gui files and classes
import FloGui
import deviceDialog
# PyQT4 imports
from PyQt4 import QtGui, QtCore
class devicedialog(QtGui.QDialog, deviceDialog.Ui_streamDialog):
#the logic of the streaming device choice dialog
def __init__(self,parent=None):
super(devicedialog,self).__init__(parent)
self.setupUi(self)
self.retranslateUi(self)
self.index = None
i=0
self.camlist=list()
while True:
try:
cam = Device(i,0)
name = cam.getDisplayName()
dev = [name,i]
self.camlist.append(dev)
i+=1
del cam
except:
break
for j in xrange(len(self.camlist)):
item = QtGui.QListWidgetItem(self.camlist[j][0])
self.deviceListBox.addItem(item)
self.exec_()
def accept(self):
selected = self.deviceListBox.currentItem().text()
for k in xrange(len(self.camlist)):
if self.camlist[k][0]==selected:
self.index = k
QtGui.QDialog.accept(self)
class Flolog(QtGui.QMainWindow,FloGui.Ui_MainWindow):
"""
Flolog is inherited from both QtGui.QDialog and FloGui.Ui_MainWindow
"""
def __init__(self, parent=None):
"""
Initialization of the class. Call the __init__ for the super classes
"""
super(Flolog,self).__init__(parent)
self.setupUi(self)
self.retranslateUi(self)
self.connectActions()
def streamchoice(self):
streamdialog = devicedialog()
self.VideoWidget.stop()
self.VideoWidget.path = streamdialog.index
self.VideoWidget.load()
self.playButton.setEnabled(True)
def menuloadfile(self):
filename = QtGui.QFileDialog.getOpenFileName(self, 'Open File', '.')
self.VideoWidget.stop()
self.VideoWidget.path = str(filename)
self.VideoWidget.load()
self.playButton.setEnabled(True)
def playbutton(self):
self.VideoWidget.play()
self.playButton.setEnabled(False)
def main(self):
self.show()
def quit_(self):
sys.exit(0)
def connectActions(self):
"""
Connect the user interface controls to the logic
"""
self.actionFile.triggered.connect(self.menuloadfile)
self.actionStream.triggered.connect(self.streamchoice)
self.actionQuit.triggered.connect(self.quit_)
self.playButton.clicked.connect(self.playbutton)
self.stopButton.clicked.connect(self.VideoWidget.stop)
if __name__=='__main__':
app = QtGui.QApplication(sys.argv)
Flologob = Flolog()
Flologob.main()
sys.exit(app.exec_())
答案 0 :(得分:1)
我实际上终于解决了这个问题。问题源于这样一个事实:首先应该手动或在代码中指定图形驱动程序应该使用哪个视频设备。我通过v4l2图形驱动程序切换设备,在Linux Ubuntu上解决了这个问题。我知道在Windows上有一个等效的操作。