Question

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!

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top