python - Phonon 的 VideoWidget 在 QGLWidget(Qt,Python)上显示错误的颜色

标签 python qt opengl video pyside

我有一个宠物项目,其中包含一个具有显示字幕功能的视频播放器。 到目前为止,我一直在处理项目的其他部分,但现在我必须以最好的方式实现字幕渲染部分。

我没有找到任何有用的东西,除了 this .

但是当我使用此代码时,我得到了错误的视频图片。 video frame with red and blue swapped

颜色修改:红→蓝、蓝→红等

有人可以帮我处理这段代码,或者告诉我另一种在视频顶部呈现字幕的解决方案吗?

PS:我在 PySide 1.0.0、1.0.6 以及 Arch 和 Ubuntu linux 上对其进行了测试。


编辑:解决方法

感谢 alexisdm 提供了一个丑陋的 hack .它改变了 paint() 方法来反转颜色。

import sys
from PySide.QtGui import QApplication, QMessageBox
# overlay
from PySide.QtGui import QGraphicsScene, QGraphicsView, QGraphicsProxyWidget, QPainter, QImage
from PySide.QtOpenGL import QGLWidget

from PySide.phonon import Phonon

try:
    from OpenGL import GL
except ImportError:
    app = QApplication(sys.argv)
    QMessageBox.critical(None, "OpenGL 2dpainting",
                            "PyOpenGL must be installed to run this example.",
                            QMessageBox.Ok | QMessageBox.Default,
                            QMessageBox.NoButton)
    sys.exit(1)


#class CustomProxy(QGraphicsProxyWidget):
#    def __init__(self, parent=None):
#        QGraphicsProxyWidget.__init__(self, parent)
#
#
#    def boundingRect(self):
#        return QGraphicsProxyWidget.boundingRect(self).adjusted(0, 0, 0, 0);


class CustomProxy(QGraphicsProxyWidget):
    def __init__(self, parent=None):
        QGraphicsProxyWidget.__init__(self, parent)


    def boundingRect(self):
        return QGraphicsProxyWidget.boundingRect(self).adjusted(0, 0, 0, 0);

# This is the magic:
    def paint(self, painter, option, widget=None):
        painter_inverted = QPainter()
        brect= QGraphicsProxyWidget.boundingRect(self)
        invertedColor = QImage(brect.width(),brect.height(),QImage.Format_RGB32)
        painter_inverted.begin(invertedColor)
        QGraphicsProxyWidget.paint(self,painter_inverted, option, widget)
        painter_inverted.end()
        painter.drawImage(0,0,invertedColor.rgbSwapped())


if __name__ == '__main__':
    app = QApplication(sys.argv)
    app.setApplicationName("tete")

    scene = QGraphicsScene()

    media = Phonon.MediaObject()
    video = Phonon.VideoWidget()
    Phonon.createPath(media, video)

    proxy = CustomProxy()
    proxy.setWidget(video)
    rect = proxy.boundingRect()
    #proxy.setPos(0, 0)
    #proxy.show()
    scene.addItem(proxy)

    media.setCurrentSource("/home/boo/Development/mindmap/test/resources/glvideo.avi")
    media.play()

    titem = scene.addText("Bla-bla-bla")
    titem.setPos(130, 130)
    #titem.setPos(rect.width()/2, rect.height()/2)

    view = QGraphicsView(scene)
    vp = QGLWidget()
    view.setViewport(vp)

    #view.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform)
    view.setViewportUpdateMode(QGraphicsView.BoundingRectViewportUpdate)
    view.setWindowTitle("Eternal fire")

    view.show()
    sys.exit(app.exec_())

最佳答案

正如 alexisdm 所指出的那样在评论中这是 Qt 的一个已知错误。

可以找到#GTBUG-8738有人甚至添加了解决方法。

关于python - Phonon 的 VideoWidget 在 QGLWidget(Qt,Python)上显示错误的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7687864/

相关文章:

Python:没有名为 core.exceptions 的模块

c++ - QT/c++调用父方法的最佳方式

windows - 可以在不同应用程序的窗口上绘制 OpenGL HUD 叠加层(不闪烁)吗?

c++ - OpenGL 纹理不会映射 - 白色方 block ?

python - 在通用 View 上收到意外的关键字参数 'pk'

python - 使用 .groupby() 的 Pandas TimeSeries 的平均值

python - 打开图像? Python

c++ - Qt Serial Port - 一致读取数据

c++ - 如何让 QTextBrowser 始终在末尾插入文本

c++ - 我无法在Visual Studio 2012中使用SDL + OpenGL