我用python/pyqt videowidget制作了一个非常简单的视频播放器,它只有播放和停止按钮。用户还可以在文件菜单中选择读取视频文件或捕获视频流,自动列出可用设备(来自 windows 下的 directshow)。
我的问题是,虽然我的内置网络摄像头在屏幕上显示得非常好,但我的 USB 视频流编码器 ( Hauppauge WinTV-HVR-1900 ) 并非如此,我只能看到黑屏。虽然有些东西被识别出来,因为显示窗口确实会适应正确的 height 和 width。编码器有一个内置的硬件编码器,似乎可以产生一个MPEG-2 流。VLC 播放器显示流的事实似乎表明编解码器不是问题。有谁知道让我的视频流显示?
编辑:顺便说一句,我试过的 USB 网络摄像头工作得很好,所以我猜我的问题与编码器的输出格式与我的应用程序不兼容有关。
我的应用程序的逻辑:
#-*- 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_())