Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.4.0, 6.5.0 Beta1, 6.7.3
-
None
-
armeabi-v7a
Description
Hi
I want to save QVideoFrame of QML MediaPlayer as an image.
Since `videoFrame()` function of QVideoSink no accessible from QML, I have to use a C++ helper to access QVideoSink functionalities.
C++
this class use use Q_OBJECT and QML_ELEMENT
void Helper::saveCurrentFrame(QObject *videoOutput) { if (m_sink == nullptr){ m_sink = qvariant_cast<QVideoSink*>(videoOutput->property("videoSink")); } m_sink->videoFrame().toImage().save("frame.png"); }
QML
Helper {
id: helper
}
MediaPlayer {
id: player
videoOutput: videoOutput
}
VideoOutput {
id: videoOutput
anchors.fill: parent
}
Button {
text: "save frame"
onClicked: {
helper.saveCurrentFrame(videoOutput)
}
}
But this raise Cannot make QOpenGLContext current in a different thread
and causes the App crash in both Windows and Android.
I was able to hack this error with help of converting QVideoFrame to QImage manually :
QVideoFrame currentFrame = m_sink->videoFrame();
currentFrame.map(QVideoFrame::ReadOnly);
QImage::Format imageFormat = QVideoFrameFormat::imageFormatFromPixelFormat(currentFrame.pixelFormat());
QImage image(currentFrame.bits(0),
currentFrame.width(),
currentFrame.height(),imageFormat);
QImage delegateImage = image.scaled( 400, 200, Qt::KeepAspectRatio);
delegateImage.save("frame.png")
but this trick just works in Windows and not Android.
in Android I'm still getting Cannot make QOpenGLContext current in a different thread.
If you need full sample code just comment please, thank you Qt team.
Attachments
Issue Links
- relates to
-
QTBUG-131107 QVideoFrame::toImage / qImageFromVideoFrame not safe to call from worker thread
-
- Reported
-
-
QTBUG-129994 Video QML component crashes with "Cannot make QOpenGLContext current in a different thread"
-
- Closed
-
- mentioned in
-
Page Loading...