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. Drawing data over a video
Qt 6.11 is out! See what's new in the release blog

Drawing data over a video

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 378 Views 1 Watching
  • 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.
  • L Offline
    L Offline
    LucaCiucci
    wrote on last edited by
    #1

    Hi, I'm new on this forum.
    In my project, I want to to display some preprocessed data over a video. Basically I want to do some markers tracking and then draw them over a video with some other informations. To do that I use OpenCV to analyze the video and then I use the QMediaPlayer and QGraphicsVideoItem to draw the video in a graphics scene.

    My problem is how to synchronize the video with the data. In the beginning, I was using QMediaPlayer::position() but it has two problems:

    1. the video is not perfectly sychronized with the time given by QMediaPlayer::position()
    2. depending on the video codec, sometimes the QGraphicsVideoItem cannot keep up with the player speed and lags behind by several seconds (windows)

    I found simple solution by connecting QVideoSink::videoFrameChanged and using the time information stored in the video frame, for example:

    QVideoSink *const videoSink = m_videoItem->videoSink();
    connect(videoSink, &QVideoSink::videoFrameChanged, this, &VideoScene::onVideoFrameChanged);
    

    and then:

    void VideoScene::onVideoFrameChanged(const QVideoFrame& frame)
    {
        qint64 frame_pos_us = frame.startTime();
        ...
    }
    

    This gave me frame perfect synchronization but, unfortunately, QVideoFrame::startTime and QVideoFrame::endTime always return zero on MacOS (sometimes even on Windows but it was not reproducible).

    So I want to ask if anyone has some more reliable solutions...

    Some other notes:

    • I've found this other discussion but there was not a simple solution
    • I'm using OpenCV to do the video analysis, but the problem is independent of OpenCV, the problem is all in the Qt multimedia system
    • I'm considering throwing away the Qt multimedia system because it has some other problems, but, for now, I don't see any simple alternative

    I hope I was clear, thanks in advance.

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

      Hi,

      There's currently a backend in the works based on ffmpeg that should give you a more complete cross-platform support.

      You might want to check it.

      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

      • Login

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