Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Video to image transitions
brianmayo last edited by
Hi everyone. I'm trying to make transitions between videos and images using OpacityEffect and PropertyAnimation.
I load an image into a QLabel and the video in a QVideoWidget. I'm using QWidget::stackUnder(QWidget*) to get the image on the top and make a fade out effect to the video on the back. The animation seems very lagged.
Can anyone tell me a better way to approach this transitions?
QVideoWidget *v = new QVideoWidget(ui->centralWidget); QLabel *l = new QLabel(ui->centralWidget); QMediaPlayer *p = new QMediaPlayer(this); p->setVideoOutput(v); p->setMedia(QUrl::fromLocalFile("video.avi")); l->setPixmap(QPixmap("img.jpg").scaled(this->size(), Qt::IgnoreAspectRatio)); v->stackUnder(l); QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect(); l->setGraphicsEffect(effect); QPropertyAnimation *anim = new QPropertyAnimation(effect,"opacity"); anim->setDuration(2000); anim->setStartValue(1.0); anim->setEndValue(0.0); anim->setEasingCurve(QEasingCurve::OutQuad); p->play(); anim->start();
LuGRU last edited by LuGRU
- take screen-shoot of underlying widget
- create new QWidget and place it on top of VideoWidget
- set to top widget image of underlying widgets
- override paint() and draw pixmap
- add new animation and animate opacity of Image (not widget!)
- (optionally) on resize update image of underlying widgets and apply current opacity level (is animation is played).
That way You go away from widget based opacity to image one with should be much faster.
Alternative 2 (with should be even faster then above):
- create QGraphicsScene
- add VideoItem
3a. animate VideoItem opacity from 0 to 1 (background must be set to static image)
3b. or add on top PixmapItem and animate it's opacity from 1 to 0