3

我已经工作了几天从声子媒体对象中抓取帧。我的目标是以用户指定的某个间隔捕获帧。我首先尝试为与 Phonon::MediaObject 关联的滴答信号实现一个​​插槽。然而,由于第一次发出滴答信号,有时时差可能会有所不同......并不是说它不是一个可行的解决方案,但我仍然进一步调查并尝试了 seek 和 grabWidget 的组合,但它出现了该搜索需要一些时间才能完成,并且在视频再次正常运行时无法通知应用程序,这会导致类似的代码

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

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

我的问题是我能对这两个想法中的任何一个做些什么来让它们对我更好地工作,还是我在错误的树上大声吠叫而我完全错过了一个更明显的东西?

提前致谢!

4

1 回答 1

2

你在叫错树,应该可以,使用来自 Phonon::VideoWidget 的 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,它为声子 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 的快照功能。所以暂时我会寻找其他方法来创建快照。

于 2012-01-23T19:11:28.083 回答