Python Mac上的PyQt5视频播放器正在放大
我在PyQt5中有一个视频播放器,当我在Windows机器上运行它时,它会正确地将视频格式化到帧中,但当我在Mac上运行相同的程序时,它会使帧放大以尝试适应视频的分辨率?我想。有没有办法解决这个问题 视频加载前的外观 在Mac上加载视频后的外观 窗口的代码:Python Mac上的PyQt5视频播放器正在放大,python,pyqt5,Python,Pyqt5,我在PyQt5中有一个视频播放器,当我在Windows机器上运行它时,它会正确地将视频格式化到帧中,但当我在Mac上运行相同的程序时,它会使帧放大以尝试适应视频的分辨率?我想。有没有办法解决这个问题 视频加载前的外观 在Mac上加载视频后的外观 窗口的代码: class VideoWindow(QMainWindow): def __init__(self, parent=None): super(VideoWindow, self).__init__(parent
class VideoWindow(QMainWindow):
def __init__(self, parent=None):
super(VideoWindow, self).__init__(parent)
self.setWindowTitle("PyQt Video Player")
self.mediaPlayer = QMediaPlayer(None, QMediaPlayer.VideoSurface)
videoWidget = QVideoWidget()
self.playButton = QPushButton()
self.playButton.setEnabled(False)
self.playButton.setIcon(self.style().standardIcon(QStyle.SP_MediaPlay))
self.errorLabel = QLabel()
self.errorLabel.setSizePolicy(QSizePolicy.Preferred,
QSizePolicy.Maximum)
# Create new action
openAction = QAction(QIcon('stream.png'), '&Stream', self)
openAction.setShortcut('Ctrl+O')
openAction.setStatusTip('Start a Stream')
openAction.triggered.connect(self.openFile)
# Create new action
connectAction = QAction(QIcon('connect.png'), '&Connect', self)
connectAction.setShortcut('Ctrl+C')
connectAction.setStatusTip('Connect to a Stream')
connectAction.triggered.connect(self.openConnectionList)
# Create exit action
exitAction = QAction(QIcon('exit.png'), '&Exit', self)
exitAction.setShortcut('Ctrl+Q')
exitAction.setStatusTip('Exit application')
exitAction.triggered.connect(self.exitCall)
# Create menu bar and add action
menuBar = self.menuBar()
menuBar.setNativeMenuBar(False)
fileMenu = menuBar.addMenu('&File')
fileMenu.addAction(openAction)
fileMenu.addAction(connectAction)
fileMenu.addAction(exitAction)
# Create a widget for window contents
wid = QWidget(self)
self.setCentralWidget(wid)
layout = QVBoxLayout()
layout.addWidget(videoWidget)
layout.addWidget(self.errorLabel)
# Set widget to contain window contents
wid.setLayout(layout)
self.mediaPlayer.setVideoOutput(videoWidget)
self.mediaPlayer.error.connect(self.handleError)
def openFile(self):
fileName, _ = QFileDialog.getOpenFileName(self, "Stream",
QDir.homePath())
if fileName != '':
self.mediaPlayer.setMedia(
QMediaContent(QUrl.fromLocalFile(fileName)))
self.mediaPlayer.play()
def openConnectionList(self):
self.window = QtWidgets.QMainWindow()
self.ui = connectionList()
self.ui.setupUi(self.window)
self.window.show()
def exitCall(self):
sys.exit(app.exec_())
def handleError(self):
self.errorLabel.setText("Error: " + self.mediaPlayer.errorString())
if __name__ == '__main__':
app = QApplication(sys.argv)
videoPlayer = QtWidgets.QMainWindow()
player = VideoWindow()
player.resize(640, 480)
player.show()
sys.exit(app.exec_())
编辑:::
Youtube视频显示发生的错误创建应用程序时,请尝试启用高DPI缩放:
if __name__ == '__main__':
if hasattr(QtCore.Qt, 'AA_EnableHighDpiScaling'):
PyQt5.QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True)
if hasattr(QtCore.Qt, 'AA_UseHighDpiPixmaps'):
PyQt5.QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps, True)
app = QApplication(sys.argv)
app.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
videoPlayer = QtWidgets.QMainWindow()
player = VideoWindow()
player.resize(640, 480)
player.show()
sys.exit(app.exec_())
很抱歉反应太晚,我们整天都在做DB项目。我加上了,同样的事情也发生了。嗨,对不起。我已尝试了你的代码,但无法重现该问题。您使用的是最新版本的PyQt吗?根据我的机器,我使用的是PyQt5版本5.11.3,我只能在Mac上复制此错误,它在windows和linux机器上都可以正常扩展。这只会在加载视频后发生。我在youtube视频中添加了一个链接,说明OP出现了错误。对不起,伙计,我在mac上尝试了你的代码,它工作正常(显示为全高清),你确定我的问题中的高dpi设置不能解决问题吗?