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. Showing a mp4 in my app
QtWS25 Last Chance

Showing a mp4 in my app

Scheduled Pinned Locked Moved Unsolved General and Desktop
44 Posts 5 Posters 10.3k 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.
  • M Offline
    M Offline
    MichRX7
    wrote on 10 Feb 2020, 20:11 last edited by
    #1

    Help! I'm trying to simply show a mp4 video in my app and am struggling.

    I have a pushbotton, and when clicked I want it to play a video from my file system inside the app.

    When I input this code and click on the button it seems to actually open a whole new app, but the new app doesn't play the video.

        QWidget *widget = new QWidget;
        widget->resize(400, 300);
        QMediaPlayer *player = new QMediaPlayer;
        QVideoWidget *vw = new QVideoWidget;
        player->setVideoOutput(vw);
        player->setMedia(QUrl::fromLocalFile("/home/pi/Videos/tomtiph.mp4"));
        player->setVolume(50);
        player->play();
        widget->show();
        qDebug() << "mediaStatus: " << player->mediaStatus() << "error: " << player->error();
    

    Obviously, in the end, I'd like to have the QVideoWidget on the mainwindow and play there, but for now I'd just be happy to see a video playing.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 10 Feb 2020, 20:12 last edited by
      #2

      Hi

      You forgot to call show on 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

      1 Reply Last reply
      2
      • M Offline
        M Offline
        MichRX7
        wrote on 10 Feb 2020, 20:33 last edited by
        #3

        Ok, so I added vw->show(); below widget->show(); which opens another window, but still I don't see the video. I also tried moving the line player->play(); below vw->show(); but no video. Am I calling the setMedia properly?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 10 Feb 2020, 20:43 last edited by
          #4

          You should connect the error signal to see if something wrong is happening.

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

          M 1 Reply Last reply 10 Feb 2020, 21:07
          2
          • S SGaist
            10 Feb 2020, 20:43

            You should connect the error signal to see if something wrong is happening.

            M Offline
            M Offline
            MichRX7
            wrote on 10 Feb 2020, 21:07 last edited by
            #5

            @SGaist said in Showing a mp4 in my app:

            You should connect the error signal to see if something wrong is happening.

            Well, I do the qDebug and the debugger is showing the following:
            mediaStatus: QMediaPlayer::LoadingMedia error: QMediaPlayer::NoError

            That's why I was wondering if I'm doing this line wrong:
            player->setMedia(QUrl::fromLocalFile("/home/pi/Videos/tomtiph.mp4"));

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 10 Feb 2020, 21:11 last edited by
              #6

              If there is no error, then the signal is not emitted. When exactly are you using that qDebug ?

              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
              • M Offline
                M Offline
                MichRX7
                wrote on 10 Feb 2020, 21:27 last edited by
                #7

                When the button is pushed this is the block of code that runs:

                    QWidget *widget = new QWidget;
                    widget->resize(400, 300);
                    QMediaPlayer *player = new QMediaPlayer;
                    QVideoWidget *vw = new QVideoWidget;
                    player->setVideoOutput(vw);
                    player->setMedia(QUrl::fromLocalFile("/home/pi/Videos/tomtiph.mp4"));
                    player->setVolume(50);
                    widget->show();
                    vw->show();
                    player->play();
                    qDebug() << "mediaStatus: " << player->mediaStatus() << "error: " << player->error();
                

                If there is a better way to do this, please enlighten me. I know we've talked privately about using qstackedwidget so I can show/hide the video widget and was going to play with that right after I actually get a video to play, lol...

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 10 Feb 2020, 21:38 last edited by
                  #8

                  As I wrote, connect the error signal (the name is confusing since the accessor has the same name but a different signature, there's work in progress to make that cleaner).

                  Calling the getter right after play won't help because your file is not even loaded.

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

                  M 1 Reply Last reply 11 Feb 2020, 14:05
                  3
                  • S SGaist
                    10 Feb 2020, 21:38

                    As I wrote, connect the error signal (the name is confusing since the accessor has the same name but a different signature, there's work in progress to make that cleaner).

                    Calling the getter right after play won't help because your file is not even loaded.

                    M Offline
                    M Offline
                    MichRX7
                    wrote on 11 Feb 2020, 14:05 last edited by
                    #9

                    Ok, so now I'm frustrated and confused.

                    I simply want to show a video from my local file system in my app. Is this really that difficult? Does anyone have a block of code they would be willing to share that does this? I don't need player controls or anything, just play a video and stop.

                    J 1 Reply Last reply 11 Feb 2020, 14:13
                    0
                    • M MichRX7
                      11 Feb 2020, 14:05

                      Ok, so now I'm frustrated and confused.

                      I simply want to show a video from my local file system in my app. Is this really that difficult? Does anyone have a block of code they would be willing to share that does this? I don't need player controls or anything, just play a video and stop.

                      J Offline
                      J Offline
                      J.Hilk
                      Moderators
                      wrote on 11 Feb 2020, 14:13 last edited by
                      #10

                      @MichRX7 said in Showing a mp4 in my app:

                      Ok, so now I'm frustrated and confused.

                      I simply want to show a video from my local file system in my app. Is this really that difficult? Does anyone have a block of code they would be willing to share that does this? I don't need player controls or anything, just play a video and stop.

                      The official example ?
                      https://doc.qt.io/qt-5/qtmultimedia-multimediawidgets-videowidget-example.html
                      🤷‍♂️


                      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                      Q: What's that?
                      A: It's blue light.
                      Q: What does it do?
                      A: It turns blue.

                      M 1 Reply Last reply 11 Feb 2020, 14:32
                      0
                      • J J.Hilk
                        11 Feb 2020, 14:13

                        @MichRX7 said in Showing a mp4 in my app:

                        Ok, so now I'm frustrated and confused.

                        I simply want to show a video from my local file system in my app. Is this really that difficult? Does anyone have a block of code they would be willing to share that does this? I don't need player controls or anything, just play a video and stop.

                        The official example ?
                        https://doc.qt.io/qt-5/qtmultimedia-multimediawidgets-videowidget-example.html
                        🤷‍♂️

                        M Offline
                        M Offline
                        MichRX7
                        wrote on 11 Feb 2020, 14:32 last edited by
                        #11

                        @J-Hilk Thank you, will try that during my lunch break. For some reason none of the examples are showing up for me in QT Creator. I'll bring that code down and go through it. I tried bringing down the media player with play list example, and it didn't play anything when I hit play.

                        1 Reply Last reply
                        0
                        • M Offline
                          M Offline
                          MichRX7
                          wrote on 11 Feb 2020, 21:33 last edited by
                          #12

                          @J-Hilk

                          Thank you for pointing me at the official example. I downloaded the files and open the project in QT Creator, hit F5 and wait, the app pops up, I click the Open button, select my mp4 and click the play button and... nothing. I have tried multiple videos and can play those videos with VLC.

                          1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on 11 Feb 2020, 22:01 last edited by
                            #13

                            Are they all mp4 ?

                            Did you try a different format ?

                            The fact that they play in VLC is a good sign that they are not corrupted however it does not mean that your system has all the required codecs.

                            On a side note, you can also make use of VLC in your Qt application if you want.

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

                            M 1 Reply Last reply 11 Feb 2020, 22:32
                            0
                            • S SGaist
                              11 Feb 2020, 22:01

                              Are they all mp4 ?

                              Did you try a different format ?

                              The fact that they play in VLC is a good sign that they are not corrupted however it does not mean that your system has all the required codecs.

                              On a side note, you can also make use of VLC in your Qt application if you want.

                              M Offline
                              M Offline
                              MichRX7
                              wrote on 11 Feb 2020, 22:32 last edited by
                              #14

                              @SGaist said in Showing a mp4 in my app:

                              On a side note, you can also make use of VLC in your Qt application if you want.

                              And this is where my non-linux kicks in. I cloned the VLC-QT git directory, but now I don't know what to do from there. I believe I have to build it from within the debian sub-folder inside of the vlc-qt directory, but no idea how.

                              1 Reply Last reply
                              0
                              • M Offline
                                M Offline
                                MichRX7
                                wrote on 12 Feb 2020, 12:36 last edited by
                                #15

                                So, following this page for install directions on the vlc-qt: https://github.com/vlc-qt/vlc-qt/blob/master/BUILDING.md

                                It says for Linux:
                                Linux
                                Install requirements from your distribution's repository. Supported generators are make and ninja.

                                Make example:

                                $ mkdir build
                                $ cd build
                                $ cmake .. -DCMAKE_BUILD_TYPE=Debug
                                $ make -j8
                                $ make install

                                So, I go into the git debian directory because I believe my Rpi4 is running raspbian debian stretch. I then do the mkdir build and cd build so I'm in the build subdirectory of debian. I then use the following cmake command:
                                cmake -SYSTEM_QML -WITH_X11 -DCMAKE_BUILD_TYPE=Debug

                                And I get the following error:
                                CMake Error: The source directory "/home/pi/vlc-qt/debian/-dcmake_build_type=Debug" does not exist.
                                Specify --help for usage, or press the help button on the CMake GUI.

                                Was I supposed to put something else where the ".." is in the cmake directions?

                                jsulmJ 1 Reply Last reply 12 Feb 2020, 12:38
                                0
                                • M MichRX7
                                  12 Feb 2020, 12:36

                                  So, following this page for install directions on the vlc-qt: https://github.com/vlc-qt/vlc-qt/blob/master/BUILDING.md

                                  It says for Linux:
                                  Linux
                                  Install requirements from your distribution's repository. Supported generators are make and ninja.

                                  Make example:

                                  $ mkdir build
                                  $ cd build
                                  $ cmake .. -DCMAKE_BUILD_TYPE=Debug
                                  $ make -j8
                                  $ make install

                                  So, I go into the git debian directory because I believe my Rpi4 is running raspbian debian stretch. I then do the mkdir build and cd build so I'm in the build subdirectory of debian. I then use the following cmake command:
                                  cmake -SYSTEM_QML -WITH_X11 -DCMAKE_BUILD_TYPE=Debug

                                  And I get the following error:
                                  CMake Error: The source directory "/home/pi/vlc-qt/debian/-dcmake_build_type=Debug" does not exist.
                                  Specify --help for usage, or press the help button on the CMake GUI.

                                  Was I supposed to put something else where the ".." is in the cmake directions?

                                  jsulmJ Offline
                                  jsulmJ Offline
                                  jsulm
                                  Lifetime Qt Champion
                                  wrote on 12 Feb 2020, 12:38 last edited by
                                  #16

                                  @MichRX7 You need to tell cmake where the source code is:

                                  cmake PATH_TO_SRC -SYSTEM_QML -WITH_X11 -DCMAKE_BUILD_TYPE=Debug
                                  

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

                                  M 1 Reply Last reply 12 Feb 2020, 12:49
                                  0
                                  • jsulmJ jsulm
                                    12 Feb 2020, 12:38

                                    @MichRX7 You need to tell cmake where the source code is:

                                    cmake PATH_TO_SRC -SYSTEM_QML -WITH_X11 -DCMAKE_BUILD_TYPE=Debug
                                    
                                    M Offline
                                    M Offline
                                    MichRX7
                                    wrote on 12 Feb 2020, 12:49 last edited by
                                    #17

                                    @jsulm Thanks for the quick reply.

                                    In the interim I did get a .mov file straight from a new iPhone and moved that over onto my Rpi4, and guess what. It plays, so it must be a codec issue on the mp4 (though it didn't have sound, but maybe the Rpi4 doesn't output sound through hdmi).

                                    Is there a page that tells newbies like me how to install the right codec for my mp4 videos?

                                    1 Reply Last reply
                                    0
                                    • M Offline
                                      M Offline
                                      MichRX7
                                      wrote on 12 Feb 2020, 13:25 last edited by
                                      #18

                                      Hahaha, of course though I take a .mp4 into my video editing software and export it is a .mov and it won't play either. So is there a way to tell what I need to do to a video to get it to play or how I install the codec's I need in QT? I don't want to have to use only non-edited iPhone vids, lol...

                                      (Seriously, so glad to just see a video play... thank you all for the help so far.)

                                      jsulmJ 1 Reply Last reply 12 Feb 2020, 13:29
                                      0
                                      • M MichRX7
                                        12 Feb 2020, 13:25

                                        Hahaha, of course though I take a .mp4 into my video editing software and export it is a .mov and it won't play either. So is there a way to tell what I need to do to a video to get it to play or how I install the codec's I need in QT? I don't want to have to use only non-edited iPhone vids, lol...

                                        (Seriously, so glad to just see a video play... thank you all for the help so far.)

                                        jsulmJ Offline
                                        jsulmJ Offline
                                        jsulm
                                        Lifetime Qt Champion
                                        wrote on 12 Feb 2020, 13:29 last edited by
                                        #19

                                        @MichRX7 Most safe method is to install all GStreamer plug-ins your distribution is providing.

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

                                        M 1 Reply Last reply 12 Feb 2020, 13:51
                                        0
                                        • jsulmJ jsulm
                                          12 Feb 2020, 13:29

                                          @MichRX7 Most safe method is to install all GStreamer plug-ins your distribution is providing.

                                          M Offline
                                          M Offline
                                          MichRX7
                                          wrote on 12 Feb 2020, 13:51 last edited by
                                          #20

                                          @jsulm And I'm stuck again (of course), so I did the following on my Rpi4:
                                          sudo apt-get install gstreamer1.0-tools
                                          Reading package lists... Done
                                          Building dependency tree
                                          Reading state information... Done
                                          gstreamer1.0-tools is already the newest version (1.14.4-1).
                                          0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

                                          So, I already had the newest version of gstreamer installed. Is there something else I need to do to download specific codec's or all codec's? I tried going to the gstreamer website, but not seeing anything on codecs.

                                          1 Reply Last reply
                                          0

                                          3/44

                                          10 Feb 2020, 20:33

                                          topic:navigator.unread, 41
                                          • Login

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