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

18
我有一个宠物项目,其中包含一个视频播放器,具有显示字幕的功能。直到现在,我一直在处理项目的其他部分,但现在我必须以最佳方式实现字幕渲染部分。
我没有找到任何有用的东西来实现这个目的,除了this
但是当我使用这段代码时,我得到了一个错误的视频图像。颜色被修改:红色→蓝色,蓝色→红色等。
有人能帮我解决这个问题吗?或者向我展示另一种在视频上方呈现字幕的解决方案?
PS:我在Arch和Ubuntu Linux上测试过PySide 1.0.0、1.0.6。

编辑:解决方法

感谢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_())

8
有一个关于这个问题的错误报告:https://bugreports.qt.nokia.com//browse/QTBUG-8737 - alexisdm
请接受“这是一个错误,请查看链接”的答案。这个问题一直出现在未回答的问题中。 - Chris Wesseling
2个回答

2

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

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


0
一些操作系统、框架、文件格式等将颜色存储为RGB,而另一些则存储为BGR(后者在Windows中更为常见)。因此,如果您从其中一个传递颜色到另一个,则常见的是红/蓝色交换。仔细查看您的颜色结构,确保您正在使用适合您所使用技术的正确结构。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接