I am writing an application which will allow the user to scrub through an open video. Developing on Windows 7/8 with Qt 5.3, I have been using QMediaPlayer
and QVideoWidget
following the qvideowidget
example project. The result has been pretty good, except that the QVideoWidget
seems only to update during idle time. Still, it's a good start and it's usable.
However, when I build on Mac OS 10.10 (again with Qt 5.3), scrubbing behaves as though there were only one frame per second in the video. As I drag the "position" slider, the video jumps from one frame to the frame one second later, then one second after that, even though I am calling QMediaPlayer::setPosition
several times with positions between those two frames.
The problem can be reproduced using the videowidget
example that ships with Qt 5.3 here: Qt\Examples\Qt-5.3\multimediawidgets\videowidget
. When the slider is dragged on a Windows machine, the QVideoWidget
moves between frames that are spaced fairly close together. When the slider is dragged on a Mac (at least on mine), the QVideoWidget
jumps between frames spaced about one second apart. No matter how long I wait for an "in between" frame to render, it won't happen unless I hit the "play" button.
I've tried calling QMediaPlayer::play()
and QMediaPlayer::pause()
one after the other to force an update, but this doesn't seem to work--QMediaPlayer
works asynchronously, so the update doesn't have time to take effect.
If I check the value of QMediaPlayer::position
, I find that it actually doesn't change between these jumps. It appears that when I call QMediaPlayer::setPosition
, it is actually rounding the position to one second increments on a Mac and finer increments on a Windows machine.
Ideally, I would like to jump to a particular position in the video and render that frame immediately on the QVideoWidget
. Is there any way to force QMediaPlayer
to set the position accurately and update the associated QVideoWidget
? Is there a better way to implement smooth scrubbing in a video?
Thanks for your help!