Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Display Gstreamer video on Android
QtWS25 Last Chance

Display Gstreamer video on Android

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
gstreamergstreamer videoandroidopengl
36 Posts 4 Posters 21.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.
  • SGaistS SGaist

    It should run on the same platforms as Qt as long as you can satisfy its dependencies.

    I'd first try to build the backend. It will likely be less work.

    don-progD Offline
    don-progD Offline
    don-prog
    wrote on last edited by
    #15

    @SGaist understood. Thanks for the explanations. About backend:
    I need download GStreamer for Android(this I already did, right?), create plugins.pro file in the my project(I don't know even what is it, but I will read) and add GStreamer dir to the list in the android scope(don't heard about this too). Is it all what I need?

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

      No, you have to build the plugin from the sources and then install them

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

      don-progD 1 Reply Last reply
      0
      • SGaistS SGaist

        No, you have to build the plugin from the sources and then install them

        don-progD Offline
        don-progD Offline
        don-prog
        wrote on last edited by
        #17

        @SGaist can you share the link which describes what I need to do? Or some additional reading? I'm sorry but I really don't understand a lot of things. Where I need to set a plugins.pro? What I need to set within it? About which plugin are you said? How and where I need to install it? How connect GStreamer to all these things?

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

          You don't need to create any file. You have to first get the sources of the QtMultimedia module.

          There you'll find the plugins folder with the matching plugins.pro file

          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
          • LuJoRiL Offline
            LuJoRiL Offline
            LuJoRi
            wrote on last edited by LuJoRi
            #19

            Hi don-prog!

            I've had the same issue as you...displaying a GStreamer video on Android within a Qt application!
            It was a hard way to find out how to get it alltogether work and it took me a long time! I wasn't able to find really useful hints about this issue.

            First I also tried it with QtGStreamer, but I didn't get it work for Android. After trying and trying and trying (...) I decided to look for another way to go. By the way - for Linux the QtGStreamer worked like a charm.

            As you can see at this link (https://wiki.qt.io/Qt_5.5.0_Multimedia_Backends) the multimedia backend of Qt uses different multimedia frameworks on different platforms --> GStreamer is only used for Linux and I think this decision wasn't made causeless! I don't think it will be so easy to get the Qt's GStreamer-Backend to work for Android since a Qt application for Android comes with partial other characteristics than a Qt application for Linux. That's based in the differences between the dissimilar windowing-systems of Android and Desktop-Linux.

            If you display some patience I'll show you how I did it?

            Greetz, Lukas

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

              Hi and welcome to devnet,

              @LuJoRi Indeed it wasn't mad causeless because Qt uses as much as possible native frameworks.

              If I understand you correctly you successfully used GStreamer on Android with Qt to do video rendering ?

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

              don-progD LuJoRiL 2 Replies Last reply
              0
              • SGaistS SGaist

                Hi and welcome to devnet,

                @LuJoRi Indeed it wasn't mad causeless because Qt uses as much as possible native frameworks.

                If I understand you correctly you successfully used GStreamer on Android with Qt to do video rendering ?

                don-progD Offline
                don-progD Offline
                don-prog
                wrote on last edited by
                #21

                @SGaist ok, I downloaded QtMultimedia source and found that block:

                android {
                   SUBDIRS += android opensles
                }
                

                What I should to do next? Just add /home/user/Downloads/gstreamer-1.0-android-armv7-1.8.0 in the end?

                1 Reply Last reply
                0
                • SGaistS SGaist

                  Hi and welcome to devnet,

                  @LuJoRi Indeed it wasn't mad causeless because Qt uses as much as possible native frameworks.

                  If I understand you correctly you successfully used GStreamer on Android with Qt to do video rendering ?

                  LuJoRiL Offline
                  LuJoRiL Offline
                  LuJoRi
                  wrote on last edited by LuJoRi
                  #22

                  @SGaist, yes exactly! It was one of my core topics of my master thesis which I'll finally release after the weekend :)
                  @don-prog, @SGaist, are you interested in my solution? It will take some time for me to explain you in english since it isn't my first language (it's german).

                  A few quick hints:

                  • you should look for a surface of the Java/Android-API and get the pointer on it via ANativeWindow_fromSurface(...) --> so you can handle the surface's display area within C++/Qt

                  • with this pointer you are able to use the standard GStreamer way to render a video in a specific display area.
                    Your function call was:
                    gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(video_sink), this->ui->playback_widget->winId());
                    --> you have to use the pointer on the native window instead of winId()...the winId() function returns useful values on Linux but not on Android!

                  don-progD 1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #23

                    @don-prog Sure thing !

                    That may avoid @don-prog some pain.

                    @don-prog you would need to add gstreamer to SUBDIRS. It's the name of the plugin dir. However, AFAIK, that plugin uses pkg-config to find gstreamer's library/includes so it may be problematic. You would have to put the the paths yourself in there.

                    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
                    • LuJoRiL LuJoRi

                      @SGaist, yes exactly! It was one of my core topics of my master thesis which I'll finally release after the weekend :)
                      @don-prog, @SGaist, are you interested in my solution? It will take some time for me to explain you in english since it isn't my first language (it's german).

                      A few quick hints:

                      • you should look for a surface of the Java/Android-API and get the pointer on it via ANativeWindow_fromSurface(...) --> so you can handle the surface's display area within C++/Qt

                      • with this pointer you are able to use the standard GStreamer way to render a video in a specific display area.
                        Your function call was:
                        gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(video_sink), this->ui->playback_widget->winId());
                        --> you have to use the pointer on the native window instead of winId()...the winId() function returns useful values on Linux but not on Android!

                      don-progD Offline
                      don-progD Offline
                      don-prog
                      wrote on last edited by
                      #24

                      @LuJoRi many thanks for your support and experience! I am very interested in your solution because I already thought about some way like yours, but I have some misunderstandings:
                      How can I use ANativeWindow_fromSurface() from Qt and with which arguments?

                      LuJoRiL 1 Reply Last reply
                      0
                      • don-progD don-prog

                        @LuJoRi many thanks for your support and experience! I am very interested in your solution because I already thought about some way like yours, but I have some misunderstandings:
                        How can I use ANativeWindow_fromSurface() from Qt and with which arguments?

                        LuJoRiL Offline
                        LuJoRiL Offline
                        LuJoRi
                        wrote on last edited by LuJoRi
                        #25

                        @don-prog you have to do function calls from C++/Qt to Java/Android-API via JNI. Look for QAndroidJniObject (http://doc.qt.io/qt-5/qandroidjniobject.html) --> that's a way to create instances of classes of the Java/Android-API. Furthermore you can call their methods - for example via

                         QAndroidJniObject::callObjectMethod(const char *methodName, const char *signature, ... ) 
                        

                        That means that you first have to manage a Java surface object will be created. You do this via JNI. Then you can put this one as an argument to the ANativeWindow_fromSurface function.

                        don-progD 1 Reply Last reply
                        1
                        • LuJoRiL LuJoRi

                          @don-prog you have to do function calls from C++/Qt to Java/Android-API via JNI. Look for QAndroidJniObject (http://doc.qt.io/qt-5/qandroidjniobject.html) --> that's a way to create instances of classes of the Java/Android-API. Furthermore you can call their methods - for example via

                           QAndroidJniObject::callObjectMethod(const char *methodName, const char *signature, ... ) 
                          

                          That means that you first have to manage a Java surface object will be created. You do this via JNI. Then you can put this one as an argument to the ANativeWindow_fromSurface function.

                          don-progD Offline
                          don-progD Offline
                          don-prog
                          wrote on last edited by
                          #26

                          @LuJoRi understood, via JNI :)
                          But I still don't understand what I need to put in the ANativeWindow_fromSurface() function as first(JNIEnv * env) and second(jobject surface) argument?

                          LuJoRiL 1 Reply Last reply
                          0
                          • don-progD don-prog

                            @LuJoRi understood, via JNI :)
                            But I still don't understand what I need to put in the ANativeWindow_fromSurface() function as first(JNIEnv * env) and second(jobject surface) argument?

                            LuJoRiL Offline
                            LuJoRiL Offline
                            LuJoRi
                            wrote on last edited by LuJoRi
                            #27

                            @don-prog
                            The first agrument requires something like a pointer on the Java environment which is needed because on Android even a Qt application is based on a JVM respectively ART (Android Runtime).
                            The second one is the C++/Qt handle of the Java surface. Once you've retrieved it after your JNI calls, you can cast it to jobject type and then put it to the ANativeWindow_fromSurface function :)

                            Unfortunately I'm short of time the next days (till sunday). Regardless I'd really like to help you! Feel free to ask if there are any questions :)

                            don-progD 1 Reply Last reply
                            0
                            • LuJoRiL LuJoRi

                              @don-prog
                              The first agrument requires something like a pointer on the Java environment which is needed because on Android even a Qt application is based on a JVM respectively ART (Android Runtime).
                              The second one is the C++/Qt handle of the Java surface. Once you've retrieved it after your JNI calls, you can cast it to jobject type and then put it to the ANativeWindow_fromSurface function :)

                              Unfortunately I'm short of time the next days (till sunday). Regardless I'd really like to help you! Feel free to ask if there are any questions :)

                              don-progD Offline
                              don-progD Offline
                              don-prog
                              wrote on last edited by
                              #28

                              @LuJoRi excuse for troubling! And what is the second argument in Qt exactly? I think it's not qwidget->winId(), so what?

                              LuJoRiL 1 Reply Last reply
                              0
                              • don-progD don-prog

                                @LuJoRi excuse for troubling! And what is the second argument in Qt exactly? I think it's not qwidget->winId(), so what?

                                LuJoRiL Offline
                                LuJoRiL Offline
                                LuJoRi
                                wrote on last edited by LuJoRi
                                #29

                                @don-prog
                                Sorry for the late response!

                                No, forget winId() respectively the returned WId on Android for your purposes :)

                                The second argument for ANativeWindow_fromSurface is the pure JNI object of a Java surface which you'll retrieve from the Java/Android world! The ANativeWindow_fromSurface function will return a pointer to the display which is managed by the Java surface. With this pointer you are able to access this display area within C++/Qt...since Qt's winId() function doesn't return proper values on Android the pointer you retrieve via ANativeWindow_fromSurface will be something like a replacement for the "missing" WId.

                                Are you familiar with the Android-API and how to get a surface in standard Android way? --> you need a SurfaceView and with its SurfaceHolder you can get access to the corresponding Surface. Since you are working with Qt, you have to try doing this stuff via JNI respectively QAndroidJNIObject :) When you get the JNI object of a Java surface this will be your second argument for the function ANativeWindow_fromSurface.

                                For my thesis I've created a clear view of the whole procedure...I hope you understand I have first to go in conversation with my professor before I'll post things (diagrams, figures) which I created for my thesis. These days I'm doing the final cut for my thesis document which I'll deliver after the weekend. I'd like to do the delivery of the thesis first and then help you out with detailed description :) I hope it's okay for you?

                                Nevertheless I'll try to answer your questions in the meantime :)

                                Lukas

                                don-progD 1 Reply Last reply
                                0
                                • LuJoRiL LuJoRi

                                  @don-prog
                                  Sorry for the late response!

                                  No, forget winId() respectively the returned WId on Android for your purposes :)

                                  The second argument for ANativeWindow_fromSurface is the pure JNI object of a Java surface which you'll retrieve from the Java/Android world! The ANativeWindow_fromSurface function will return a pointer to the display which is managed by the Java surface. With this pointer you are able to access this display area within C++/Qt...since Qt's winId() function doesn't return proper values on Android the pointer you retrieve via ANativeWindow_fromSurface will be something like a replacement for the "missing" WId.

                                  Are you familiar with the Android-API and how to get a surface in standard Android way? --> you need a SurfaceView and with its SurfaceHolder you can get access to the corresponding Surface. Since you are working with Qt, you have to try doing this stuff via JNI respectively QAndroidJNIObject :) When you get the JNI object of a Java surface this will be your second argument for the function ANativeWindow_fromSurface.

                                  For my thesis I've created a clear view of the whole procedure...I hope you understand I have first to go in conversation with my professor before I'll post things (diagrams, figures) which I created for my thesis. These days I'm doing the final cut for my thesis document which I'll deliver after the weekend. I'd like to do the delivery of the thesis first and then help you out with detailed description :) I hope it's okay for you?

                                  Nevertheless I'll try to answer your questions in the meantime :)

                                  Lukas

                                  don-progD Offline
                                  don-progD Offline
                                  don-prog
                                  wrote on last edited by
                                  #30

                                  @LuJoRi of course, it's absolutely ok! I'm student too and I understand you fully :)
                                  I just have two questions:

                                  1. Can I display video in NOT full screen(display video in some child widget of my application)? Or I can display video ONLY in full screen? Of course I mean via Qt and GStreamer.
                                  2. How can I get SurfaceView of the widget(if I can display video in not full screen) or of the full window(if I can display video only in full screen)?
                                    Regards.
                                  LuJoRiL 1 Reply Last reply
                                  0
                                  • don-progD don-prog

                                    @LuJoRi of course, it's absolutely ok! I'm student too and I understand you fully :)
                                    I just have two questions:

                                    1. Can I display video in NOT full screen(display video in some child widget of my application)? Or I can display video ONLY in full screen? Of course I mean via Qt and GStreamer.
                                    2. How can I get SurfaceView of the widget(if I can display video in not full screen) or of the full window(if I can display video only in full screen)?
                                      Regards.
                                    LuJoRiL Offline
                                    LuJoRiL Offline
                                    LuJoRi
                                    wrote on last edited by LuJoRi
                                    #31

                                    Okay, good to know :)

                                    @don-prog said:

                                    1. Can I display video in NOT full screen(display video in some child widget of my application)? Or I can display video ONLY in full screen? Of course I mean via Qt and GStreamer.
                                    2. How can I get SurfaceView of the widget(if I can display video in not full screen) or of the full window(if I can display video only in full screen)?
                                      Regards.
                                    1. Yes, you can display a video wherever you want and in every size you want
                                    2. In fact the surface isn't part of your Qt-GUI --> you'll get something like a "mixed GUI" with a Qt part and a Java part. All of your GUI will be drawn by Qt except the part where your video will be rendered because this will happen inside the display area which is hold by the Java surface. If you create a Java surface with size 100x100 px via JNI there will be an area with this size ontop of your Qt-GUI which has nothing to do with Qt itself. To describe how you can get it is a longer term which I'll show you after my delivery :))
                                    don-progD chaudhryC 2 Replies Last reply
                                    0
                                    • LuJoRiL LuJoRi

                                      Okay, good to know :)

                                      @don-prog said:

                                      1. Can I display video in NOT full screen(display video in some child widget of my application)? Or I can display video ONLY in full screen? Of course I mean via Qt and GStreamer.
                                      2. How can I get SurfaceView of the widget(if I can display video in not full screen) or of the full window(if I can display video only in full screen)?
                                        Regards.
                                      1. Yes, you can display a video wherever you want and in every size you want
                                      2. In fact the surface isn't part of your Qt-GUI --> you'll get something like a "mixed GUI" with a Qt part and a Java part. All of your GUI will be drawn by Qt except the part where your video will be rendered because this will happen inside the display area which is hold by the Java surface. If you create a Java surface with size 100x100 px via JNI there will be an area with this size ontop of your Qt-GUI which has nothing to do with Qt itself. To describe how you can get it is a longer term which I'll show you after my delivery :))
                                      don-progD Offline
                                      don-progD Offline
                                      don-prog
                                      wrote on last edited by
                                      #32

                                      @LuJoRi understood, that is a very good news! I will wait when you can share your information about this subject. By the way, good luck :)

                                      1 Reply Last reply
                                      0
                                      • LuJoRiL LuJoRi

                                        Okay, good to know :)

                                        @don-prog said:

                                        1. Can I display video in NOT full screen(display video in some child widget of my application)? Or I can display video ONLY in full screen? Of course I mean via Qt and GStreamer.
                                        2. How can I get SurfaceView of the widget(if I can display video in not full screen) or of the full window(if I can display video only in full screen)?
                                          Regards.
                                        1. Yes, you can display a video wherever you want and in every size you want
                                        2. In fact the surface isn't part of your Qt-GUI --> you'll get something like a "mixed GUI" with a Qt part and a Java part. All of your GUI will be drawn by Qt except the part where your video will be rendered because this will happen inside the display area which is hold by the Java surface. If you create a Java surface with size 100x100 px via JNI there will be an area with this size ontop of your Qt-GUI which has nothing to do with Qt itself. To describe how you can get it is a longer term which I'll show you after my delivery :))
                                        chaudhryC Offline
                                        chaudhryC Offline
                                        chaudhry
                                        wrote on last edited by
                                        #33

                                        @LuJoRi I also have exactly the same requirement that is to render video inside a Qt application on Android using gstreamer. It would be really helpful if you could explain the steps for building gstreamer for a qt application with Android as a target.

                                        1 Reply Last reply
                                        0
                                        • LuJoRiL Offline
                                          LuJoRiL Offline
                                          LuJoRi
                                          wrote on last edited by
                                          #34

                                          Hey guys ... my thesis is done :)

                                          I will explain you the procedure step by step this evening or tomorrow in the afternoon.

                                          Greetz Lukas

                                          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