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. QVideoFrame conversion to QImage seems to corrupt my image

QVideoFrame conversion to QImage seems to corrupt my image

Scheduled Pinned Locked Moved Unsolved General and Desktop
qvideosinkqimagevideo frame
2 Posts 2 Posters 460 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.
  • F Offline
    F Offline
    friendlyQtBeginner
    wrote on 25 Oct 2023, 02:47 last edited by friendlyQtBeginner
    #1

    I am working on a project that is very similar to what is discussed in this forum post. I have an application that is able to load and play videos using QMediaPlayer with no issues, but when I try to save a frame from my video that is playing, I get an error stating:

    Failed to map readback staging texture: COM error 0x8007000e: Not enough memory resources are available to complete this operation.
    

    The code that I am using to try and save my images, built based off Bonnie's suggestion from the linked forum post. My m_mediaPlayer variable is declared in a separate header file.

    Bonnie's suggestion:

    QVideoSink *sink = mplayer->videoSink();
    QVideoFrame frame = sink->videoFrame();
    

    My Code and the saved result:

    void Camera::saveFrame()
    {
        QVideoSink* sink = m_mediaPlayer.videoSink();
        QVideoFrame frame = sink->videoFrame();
    
        QImage image = frame.toImage();
        image.save("C:\\Users\\myPC\\Documents\\test_saving_image\\video_snapshot.jpeg", "JPEG");
    
    }
    
    

    video_snapshot.jpeg

    What could be causing this issue? Am I using the tools wrong? Not sure how much this will matter, but here is some info on my VideoFrame:

    frame.pixelFormat() is NV12
    frame.isValid() is true

    J 1 Reply Last reply 25 Oct 2023, 05:28
    0
    • F friendlyQtBeginner
      25 Oct 2023, 02:47

      I am working on a project that is very similar to what is discussed in this forum post. I have an application that is able to load and play videos using QMediaPlayer with no issues, but when I try to save a frame from my video that is playing, I get an error stating:

      Failed to map readback staging texture: COM error 0x8007000e: Not enough memory resources are available to complete this operation.
      

      The code that I am using to try and save my images, built based off Bonnie's suggestion from the linked forum post. My m_mediaPlayer variable is declared in a separate header file.

      Bonnie's suggestion:

      QVideoSink *sink = mplayer->videoSink();
      QVideoFrame frame = sink->videoFrame();
      

      My Code and the saved result:

      void Camera::saveFrame()
      {
          QVideoSink* sink = m_mediaPlayer.videoSink();
          QVideoFrame frame = sink->videoFrame();
      
          QImage image = frame.toImage();
          image.save("C:\\Users\\myPC\\Documents\\test_saving_image\\video_snapshot.jpeg", "JPEG");
      
      }
      
      

      video_snapshot.jpeg

      What could be causing this issue? Am I using the tools wrong? Not sure how much this will matter, but here is some info on my VideoFrame:

      frame.pixelFormat() is NV12
      frame.isValid() is true

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 25 Oct 2023, 05:28 last edited by jsulm
      #2

      @friendlyQtBeginner I guess you should connect to videoFrameChanged() signal as described in documentation to make sure there actually is a frame when you call videoFrame:
      "QVideoSink will provide individual video frames to the application developer through the videoFrameChanged() signal."
      You can also call https://doc.qt.io/qt-6/qvideoframe.html#isValid to check whether you got a valid frame.

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

      1 Reply Last reply
      2

      2/2

      25 Oct 2023, 05:28

      • Login

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