QVideoFrame conversion to QImage seems to corrupt my image
-
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"); }
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 -
@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.