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?
QtWS25 Last Chance

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.
  • P Offline
    P Offline
    pauledd
    wrote on 14 Jul 2016, 08:26 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
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 14 Jul 2016, 21:42 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

      J 1 Reply Last reply 15 Jul 2016, 04:35
      0
      • S SGaist
        14 Jul 2016, 21:42

        Hi,

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

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 15 Jul 2016, 04:35 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
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 15 Jul 2016, 06:55 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

          P 1 Reply Last reply 15 Jul 2016, 07:14
          1
          • P Offline
            P Offline
            pauledd
            wrote on 15 Jul 2016, 07:05 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
            • S SGaist
              15 Jul 2016, 06:55

              @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.

              P Offline
              P Offline
              pauledd
              wrote on 15 Jul 2016, 07:14 last edited by
              #6

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

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 15 Jul 2016, 07:17 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
                • P Offline
                  P Offline
                  pauledd
                  wrote on 15 Jul 2016, 08:24 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
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 15 Jul 2016, 20:46 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
                    • P Offline
                      P Offline
                      pauledd
                      wrote on 16 Jul 2016, 06:53 last edited by
                      #10

                      thanks a lot :)

                      D 1 Reply Last reply 16 Jul 2016, 11:35
                      0
                      • P pauledd
                        16 Jul 2016, 06:53

                        thanks a lot :)

                        D Offline
                        D Offline
                        Devopia53
                        wrote on 16 Jul 2016, 11:35 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
                        • P Offline
                          P Offline
                          pauledd
                          wrote on 17 Jul 2016, 08:46 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

                          1/12

                          14 Jul 2016, 08:26

                          • Login

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