It's some kind of video player, so I think you should consider the video file fps, setup a QTimer in order to query frames in regular intervals and send them to display.
Now it looks like you want to play the video as fast as possible, it's definitely not the way to go.
Something like this (a pseudo-code):
void VideoThread::run(){
player.loadVideo("video file path");
//...
if( fps > 0 ){ // video fps
timer.setInterval( 1000.0 / fps ); //
connect(timer, SIGNAL(timeout()), this, SLOT(grabFrame()));
timer.start();
} else{
// some kind of error handling
}
}
void VideoThread::grabFrame(){
QImage img
= player.
getFrame();
emit newFrame(img); // signal connected to some object from the gui thread, with Qt::QueuedConnection
}
//...
void MainGui::frameCallback( const QImage& img ){
qDebug() << "got frame";
displayWidget->setPixmap(p);
}
void VideoThread::run(){
player.loadVideo("video file path");
//...
if( fps > 0 ){ // video fps
timer.setInterval( 1000.0 / fps ); //
connect(timer, SIGNAL(timeout()), this, SLOT(grabFrame()));
timer.start();
} else{
// some kind of error handling
}
}
void VideoThread::grabFrame(){
QImage img = player.getFrame();
emit newFrame(img); // signal connected to some object from the gui thread, with Qt::QueuedConnection
}
//...
void MainGui::frameCallback( const QImage& img ){
qDebug() << "got frame";
QPixmap p = /*img to pixmap*/;
displayWidget->setPixmap(p);
}
To copy to clipboard, switch view to plain text mode
I think you can work on the details yourself.
Bookmarks