Qt 声子与QPixmap::GrabWidget

发布于 2024-12-28 06:56:46 字数 478 浏览 6 评论 0原文

我已经花了几天时间从声子媒体对象中抓取帧。我的目标是按照用户指定的某个时间间隔捕获帧。我首先尝试为与 Phonon::MediaObject 关联的刻度信号实现一个​​插槽。然而,因为滴答信号是在第一次机会时发出的,所以有时时间差可能会有一点变化......没有那么多,这不是一个可行的解决方案,但我仍然进一步调查并尝试了seek和grabWidget的组合,但它似乎该查找需要一些时间才能完成,并且在视频再次正常运行时没有任何方式通知应用程序,这会导致代码

obj->seek(i*m_grabInterval);
QPixmap image = QPixmap::grabWidget(m_ui.videoPlayer);

在 90% 的时间内保存黑色图像,但在剩余时间正确抓取帧。

我的问题是,我可以对这两个想法中的任何一个做些什么,让它们对我来说更好,或者我是否在错误的树上大声咆哮,并且有一个更明显的我完全错过了?

提前致谢!

I've been working for a couple of days on grabbing frames from a phonon media object. My aim is to capture frames at some interval specified by the user. I firstly tried to implement a slot for the tick signal associated with Phonon::MediaObject. However because the tick signal is emitted at the first opportunity there can sometimes be a little variety in the time difference... not so much that it's not a workable solution but still I investigated further and tried a combination of seek and grabWidget but it appears that seek takes some time to complete and does not have any way to notify the application when the video is running fine again, this causes code like

obj->seek(i*m_grabInterval);
QPixmap image = QPixmap::grabWidget(m_ui.videoPlayer);

to save out a black image 90% of the time, but correctly grab the frame the remaining times.

My question is is there anything I can do about either of these two ideas that will make them work better for me, or am I barking heavily up the wrong tree and there is a much more obvious I have missed completely?

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嘴硬脾气大 2025-01-04 06:56:46

你找错了树,这个应该可以,创建使用来自 Phonon::VideoWidget

edit

的 snapshot() 函数的 QImage我已经进一步研究了这个问题。连快照功能都没有实现。以下是 phonon src videowidget.cpp 中的实现:

QImage VideoWidget::snapshot() const {
    P_D(const VideoWidget);
    ConstIface<IFACES4> iface(d);
    if(iface) return iface->snapshot();
    return QImage(); // TODO not implemented in VideoInterface
}

IFACES4 指的是 VideoWidgetInterface44,它是为 phonon 4.4 定义的,如下(来自 videowidgetinterface.h):

class VideoWidgetInterface
{

    public:
        virtual ~VideoWidgetInterface() {}
        virtual Phonon::VideoWidget::AspectRatio aspectRatio() const = 0;
        virtual void setAspectRatio(Phonon::VideoWidget::AspectRatio) = 0;
        virtual qreal brightness() const = 0;
        virtual void setBrightness(qreal) = 0;
        virtual Phonon::VideoWidget::ScaleMode scaleMode() const = 0;
        virtual void setScaleMode(Phonon::VideoWidget::ScaleMode) = 0;
        virtual qreal contrast() const = 0;
        virtual void setContrast(qreal) = 0;
        virtual qreal hue() const = 0;
        virtual void setHue(qreal) = 0;
        virtual qreal saturation() const = 0;
        virtual void setSaturation(qreal) = 0;
        virtual QWidget *widget() = 0;
        virtual int overlayCapabilities() const = 0;
        virtual bool createOverlay(QWidget *widget, int type) = 0;
       };

     class VideoWidgetInterface44 : public VideoWidgetInterface
    {
      public:
         virtual QImage snapshot() const = 0;
    };
}

#ifdef PHONON_BACKEND_VERSION_4_4
   namespace Phonon { typedef VideoWidgetInterface44 VideoWidgetInterfaceLatest; }
#else
   namespace Phonon { typedef VideoWidgetInterface VideoWidgetInterfaceLatest; }
#endif

我还查看了 gstreamer 和 vlc 后端的实现。他们还不支持 phonon 4.4 的快照功能。因此,目前我将研究其他创建快照的方法。

You are barking up the wrong tree, this should work, create a QImage using the snapshot() func from the Phonon::VideoWidget

edit

I have investigated this matter further. The snapshot function is not even implemented. Here is the implementation in phonon src videowidget.cpp:

QImage VideoWidget::snapshot() const {
    P_D(const VideoWidget);
    ConstIface<IFACES4> iface(d);
    if(iface) return iface->snapshot();
    return QImage(); // TODO not implemented in VideoInterface
}

The IFACES4 refers to VideoWidgetInterface44 which is defined for phonon 4.4 as follows (from videowidgetinterface.h):

class VideoWidgetInterface
{

    public:
        virtual ~VideoWidgetInterface() {}
        virtual Phonon::VideoWidget::AspectRatio aspectRatio() const = 0;
        virtual void setAspectRatio(Phonon::VideoWidget::AspectRatio) = 0;
        virtual qreal brightness() const = 0;
        virtual void setBrightness(qreal) = 0;
        virtual Phonon::VideoWidget::ScaleMode scaleMode() const = 0;
        virtual void setScaleMode(Phonon::VideoWidget::ScaleMode) = 0;
        virtual qreal contrast() const = 0;
        virtual void setContrast(qreal) = 0;
        virtual qreal hue() const = 0;
        virtual void setHue(qreal) = 0;
        virtual qreal saturation() const = 0;
        virtual void setSaturation(qreal) = 0;
        virtual QWidget *widget() = 0;
        virtual int overlayCapabilities() const = 0;
        virtual bool createOverlay(QWidget *widget, int type) = 0;
       };

     class VideoWidgetInterface44 : public VideoWidgetInterface
    {
      public:
         virtual QImage snapshot() const = 0;
    };
}

#ifdef PHONON_BACKEND_VERSION_4_4
   namespace Phonon { typedef VideoWidgetInterface44 VideoWidgetInterfaceLatest; }
#else
   namespace Phonon { typedef VideoWidgetInterface VideoWidgetInterfaceLatest; }
#endif

I have also looked at implementations of gstreamer and vlc backends. They do not support the snapshot functionality from phonon 4.4 yet. So for the time beeing I will be looking into other ways to create snapshots.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文