Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. I have a question about accessing libmpv properties in Qt

I have a question about accessing libmpv properties in Qt

Scheduled Pinned Locked Moved 3rd Party Software
5 Posts 3 Posters 840 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.
  • C Offline
    C Offline
    CodeFarmer
    wrote on 18 Apr 2024, 14:11 last edited by
    #1

    Problem descriptionL:

    "I've been working on a small project, creating a demo for a video player. I'm trying to access the frame rate of the currently playing video using mpv_observe_property(mpv, 0, "estimated-vf-fps", MPV_FORMAT_DOUBLE);. It works fine in the callback mpv_events and I can retrieve the frame rate. However, the issue arises when I also try to observe the video time information using mpv_observe_property(mpv, 0, "time-pos", MPV_FORMAT_DOUBLE); during program initialization. This seems to cause the program to crash. It appears that I can only observe one property at a time when the mpv object is created. How can I solve this problem?"

    Below is the relevant code snippet:

    void MpvPlayer::create_mvpPlayer(QWidget *videoWin)
    {
        // create mpv instance
        mpv = mpv_create();
        if (!mpv)
            throw std::runtime_error("can't create mpv instance");
    
        int64_t wid = videoWin->winId();
    
        mpv_set_option(mpv, "wid", MPV_FORMAT_INT64, &wid);
    
        mpv_observe_property(mpv, 0, "time-pos", MPV_FORMAT_DOUBLE);
    
        //mpv_observe_property(mpv, 0, "estimated-vf-fps", MPV_FORMAT_DOUBLE);
    
    
        
    
    
    connect(this, &MpvPlayer::mpv_events, this, &MpvPlayer::on_mpv_events,
                Qt::QueuedConnection);
        
        
    
        mpv_set_wakeup_callback(mpv, wakeup, this);
    
        
        if (mpv_initialize(mpv) < 0)
            throw std::runtime_error("mpv to initialize failed !");
    }
    
    void MpvPlayer::on_mpv_events()
    {
        // All events are processed until the event queue is empty
        while (mpv)
        {
            mpv_event *event = mpv_wait_event(mpv, 0);
            if (event->event_id == MPV_EVENT_NONE)
                break;
            handle_mpv_event(event);
        }
    }
    void MpvPlayer::handle_mpv_event(mpv_event *event)
    {
        switch (event->event_id)
        {
            
            case MPV_EVENT_PROPERTY_CHANGE:
            {
                mpv_event_property *prop = (mpv_event_property *)event->data;
    
                if (strcmp(prop->name, "time-pos") == 0)
                {
                    if (prop->format == MPV_FORMAT_DOUBLE)
                    {
                        
                        double time = *(double *)prop->data;
    
                        //qDebug() << "time: " << QString::number(time, 10, 2);
                        //qDebug() << prop->name << prop->format << prop->data;
                       // qDebug() << getProperty("time-pos");
                        //qDebug() <<getProperty("playback-time");
                        //qDebug()<<getProperty("duration");
                        double totalTime = getProperty("duration").toDouble();
                        double passTime = time;
                        emit mpv_sendTimeInformat(totalTime,passTime);
    
    
                    }
                    else if (prop->format == MPV_FORMAT_NONE)
                    {
                        
                        emit mpv_palyEnd();
                        qDebug() << "End of playback";
                    }
                } else if(strcmp(prop->name, "estimated-vf-fps") == 0) {
                    
                    double estimated_fps = *(double *)prop->data;
                    emit fpsChanged(estimated_fps);
                }
    
            }
            break;
    
            // palyer Exit event triggering
            case MPV_EVENT_SHUTDOWN:
            {
                mpv_terminate_destroy(mpv);
                mpv = NULL;
            }
            break;
    
            default: ;
        }
    }
    
    
    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 18 Apr 2024, 18:55 last edited by
      #2

      Hi and welcome to devnet,

      Are you using this example as a base ?

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

      C 1 Reply Last reply 21 Apr 2024, 14:17
      0
      • S SGaist
        18 Apr 2024, 18:55

        Hi and welcome to devnet,

        Are you using this example as a base ?

        C Offline
        C Offline
        CodeFarmer
        wrote on 21 Apr 2024, 14:17 last edited by
        #3

        @SGaist
        Yeah, I checked out an example. It's basically built upon the example provided by the official mpv. So, you can say what I wrote is kind of based on that.

        T 1 Reply Last reply 21 Apr 2024, 18:46
        0
        • C CodeFarmer
          21 Apr 2024, 14:17

          @SGaist
          Yeah, I checked out an example. It's basically built upon the example provided by the official mpv. So, you can say what I wrote is kind of based on that.

          T Offline
          T Offline
          trin94
          wrote on 21 Apr 2024, 18:46 last edited by trin94
          #4

          @CodeFarmer There's a library in the KDE landscape that you can have a look at :)

          https://invent.kde.org/libraries/mpvqt

          C 1 Reply Last reply 28 Apr 2024, 16:29
          0
          • T trin94
            21 Apr 2024, 18:46

            @CodeFarmer There's a library in the KDE landscape that you can have a look at :)

            https://invent.kde.org/libraries/mpvqt

            C Offline
            C Offline
            CodeFarmer
            wrote on 28 Apr 2024, 16:29 last edited by
            #5

            @trin94 Thanks for getting back to me and for all your help

            1 Reply Last reply
            0
            • C CodeFarmer marked this topic as a regular topic on 28 Apr 2024, 16:29

            3/5

            21 Apr 2024, 14:17

            • Login

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