Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. display image in qvideowidget qmediaplayer possible?

display image in qvideowidget qmediaplayer possible?

Scheduled Pinned Locked Moved Solved General and Desktop
qmediaplayerqvideowidgetimage displayqwidgetqt5.6.1
12 Posts 4 Posters 11.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • pauleddP Offline
    pauleddP Offline
    pauledd
    wrote on last edited by
    #1

    Hi there,
    I have a QWidget that contains just a QMediaPlayer and a QVideoWidget to play some video.
    Is it possible to initially show an image in the QVideoWidget until I start the player video?

    ...
    QVideoWidget* vw = new QVideoWidget();
    QMediaPlayer* mplayer = new QMediaPlayer;
    mplayer->setMedia(QUrl::fromLocalFile("/home/paul/store/bilder/smilie.png"));
    mplayer->setVideoOutput(vw);
    vw->show();
    mplayer->play(); 
    ...
    

    I just get a "Error: "No valid frames decoded before end of stream""

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Aren't you trying to show an image rather than a video ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      jsulmJ 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Aren't you trying to show an image rather than a video ?

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @SGaist Yes, he wants to show a picture before a video file is played

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @jsulm Oo, I've managed to miss that phrase…

          I'd rather use a QStackedLayout with a QLabel to show the image and when you want to start the video, switch to the QVideoWidget.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          pauleddP 1 Reply Last reply
          1
          • pauleddP Offline
            pauleddP Offline
            pauledd
            wrote on last edited by
            #5

            This might be totaly wrong way to do it but I just found another approach. I created a QWidget with a stylesheet background image and when I press "video start" I call the camera part but with the QCameraViewfinder parented to the QWidget. I had to add setGeometry to get proper display of the video.

            void AlignmentDialog::on_pushButton_video_start_clicked()
            {
            	vf = new QCameraViewfinder(ui->widget_video);
            	cam->setViewfinder(vf);
            	vf->setGeometry(0,0,390,275);
            	vf->show();
            	cam->start();
            }
            

            works.

            1 Reply Last reply
            0
            • SGaistS SGaist

              @jsulm Oo, I've managed to miss that phrase…

              I'd rather use a QStackedLayout with a QLabel to show the image and when you want to start the video, switch to the QVideoWidget.

              pauleddP Offline
              pauleddP Offline
              pauledd
              wrote on last edited by
              #6

              @SGaist your suggestions seems more proper to me, thank you

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                In your version you have two problems:

                1. You're leaking a QCameraViewFinder each time you click on the button
                2. Your view finder won't adapt if you change the size of your widget

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                1
                • pauleddP Offline
                  pauleddP Offline
                  pauledd
                  wrote on last edited by pauledd
                  #8
                  1. what do you mean with leaking? Memory leak? (Sry, I am very new to coding)
                  2. The viewfinder should not change in size, I will make it static sized.

                  EDIT: you mean I should check if a viewfinder is already launched?

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9
                    1. Each time you call that function you create a new view finder. It has a parent so it will be destroyed at the end but still, you're filling up memory with unused instances. Either check it has already been created or just create it in the constructor of your widget.

                    2. You can also use setFixedSize for that.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • pauleddP Offline
                      pauleddP Offline
                      pauledd
                      wrote on last edited by
                      #10

                      thanks a lot :)

                      D 1 Reply Last reply
                      0
                      • pauleddP pauledd

                        thanks a lot :)

                        D Offline
                        D Offline
                        Devopia53
                        wrote on last edited by Devopia53
                        #11

                        @pauledd
                        Hi.

                        If QMediaPlayer a fixed size then you can solve in a simple way as follows.

                        like this:

                        auto mplayer = new QMediaPlayer;
                        auto vw = new QVideoWidget();
                        auto pal = vw->palette();
                        
                        // Sets the brush pixmap to pixmap. The style is set to Qt::TexturePattern.
                        pal.setBrush(QPalette::Window, QBrush(QPixmap(":/yourImage.jpg")));
                        vw->setAutoFillBackground(true);
                        vw->setPalette(pal);
                        
                        mplayer->setMedia(QUrl::fromLocalFile("yourVideo.mp4"));
                        mplayer->setVideoOutput(vw);
                        connect(mplayer, &QMediaPlayer::stateChanged, [vw](QMediaPlayer::State state){
                                            if (state == QMediaPlayer::StoppedState)
                                                vw->update(); });
                        vw->show();
                        //mplayer->play();
                        

                        If resizing is enabled will cause a very interesting one. :)

                        1 Reply Last reply
                        0
                        • pauleddP Offline
                          pauleddP Offline
                          pauledd
                          wrote on last edited by
                          #12

                          thank you for the tip, I will try this in another project since I currently have a lot of problems getting qmediaplayer or qcamera working on the RaspberryPi. I wrote my code on amd64 on which everything worked fine but on the actual device (RPi) a LOT of problems came in (qt-gstreamer-v4l2-bcm2835-v4l2,MMAL, w.t.h.) but thats worth another thread.

                          1 Reply Last reply
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved