【问题标题】:Phonon's VideoWidget show wrong colors on a QGLWidget (Qt, Python)Phonon 的 VideoWidget 在 QGLWidget(Qt,Python)上显示错误的颜色
【发布时间】:2011-12-03 00:35:14
【问题描述】:

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

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

但是当我使用此代码时,我得到了错误的视频图片。

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

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

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


编辑:解决方法

感谢alexisdm,提供了一个丑陋的黑客。它改变了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_())

【问题讨论】:

标签: python qt opengl video pyside


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多