I'm working on a QML Qt6.2 app that receives images that I would like to display to the user, I am using a VideoOutput and a QVideoSink to change the frames, however I have to convert my images to QVideoFrames before I can set them as frames for the sink, I need some help on how to do that.
Since they changed the VideoOutput handling in Qt6 I cannot seem to find and relevant help surfing the web.
CodePudding user response:
QImage img( ... Any valid QImage with any format ... );
img = img.convertToFormat( QImage::Format_ARGB32 );
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();
CodePudding user response:
Such method does the job for me
QVideoFrame frame(QVideoFrameFormat(img.size(), QVideoFrameFormat::pixelFormatFromImageFormat(img.format()));
frame.map(QVideoFrame::ReadWrite);
memcpy(frame.bits(0), img.bits(), img.sizeInBytes());
frame.unmap();
m_videoSink->setVideoFrame(frame);
however generating the videoframe format from an image format returns an invalid frame, explicitly providing a format does show the image but it's messed up due to incompatible formats, so now I want to find a videoframe format that would show my RGB888 formatted image as is, memcpy does the job as an answer to the question, and if the image format is compatible with the supported frame formats the code block above would do .