我正在尝试编写一个自定义软件(python)来从一个frame grabber卡中抓取帧(Hauppauge WinTV-HVR-1900),但我无法让它工作。捆绑的WinTV软件工作得很好,我可以从usb网络摄像头中抓取画面,所以我知道硬件可以工作。不过,我还是设法捕捉到了一些东西,因为我的屏幕是完全黑色的,但是大小和分辨率都改变了,所以我觉得这是某种解码问题。在
或者,有谁能从这样的硬件框架中提供一个这样的代码提取?我应该编写一个完整的自定义驱动程序吗?或者使用VLC python bindings(因为VLC确实成功地读取了视频流)?在
基本上,我的问题归结为:由于集成硬件编码器生成MPEG-2流,我的帧抓取器与网络摄像头有何不同?不应该像我的网络摄像头那样表现吗?在
我尝试的逻辑文件(在windows 7上使用pyQt4和python2.7的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_())
我终于解决了这个问题。这个问题源于这样一个事实:首先应该指定图形驱动程序应该使用哪个视频设备,要么手动指定,要么在代码中指定。我通过v4l2图形驱动程序切换设备,在Linux Ubuntu上解决了这个问题。我知道在窗户上也有类似的动作。在
相关问题
PyPI热门下载资源包