How to convert QImage to QVideoFrame so I would set it as frame for VideoSink Qt6.2
-
Hi,
@Christian-Ehrlicher except that it's not the case anymore for Qt 6 since the class has heavily changed.
From an educated guess, you shall create a QVideoFrame with a format compatible with your QImage and then memcpy the data from one to the other.
-
Oh sorry. Don't know why they removed it (or why they made QAbstractVideoBuffer private so creating an own is no longer possible...)
Then emulate the ctor with something similar to (untested):
auto format = QVideoFrameFormat(img.size(), QVideoFrameFormat::pixelFormatFromImageFormat(img.format()); auto frame = new QVideoFrame(format); frame.map(QVideoFrame::ReadWrite); memcpy(frame.bits(), img.bits(), img.sizeInBytes());
-
The app crashes when I try to execute that block of code..
I get the idea but I do not seem to have an implementation of it in mind so far. -
@UbiMiles said in How to convert QImage to QVideoFrame so I would set it as frame for VideoSink Qt6.2:
The app crashes
Did you debug to see where exactly and why it crashes?
-
QImage img( QStringLiteral( "sample_640×426.png" ) ); QVideoFrameFormat fmt( img.size(), QVideoFrameFormat::Format_YUYV ); QVideoFrame vf( fmt ); vf.map( QVideoFrame::WriteOnly ); libyuv::ARGBToYUY2( (const uint8_t*) img.bits(), img.bytesPerLine(), vf.bits( 0 ), vf.bytesPerLine( 0 ), img.width(), img.height() ); vf.unmap();
Only be sure that QImage pixel format is ARGB32...
-
@imironchik My QImage pixel type is RGB888
memcpy managed to get the job done , yet if I try declaring a video frame with the format of my QImage an invalid frame is returned, Explicitly providing the format shows that it does indeed work yet it's messed up do to incompatible formats,I submitted this question on stackoverflow and provided an answer myself, now I am trying to find a way to get it to work with RGB888
https://stackoverflow.com/questions/71407367/how-to-convert-qimage-to-qvideoframe-so-i-would-set-it-as-frame-for-videosink-qt/71409775#71409775 -
@imironchik
I see, thanks
one last question is where is "libyuv" namespace coming from