[Interest] Qt6: how to construct QVideoFrame from QImage ?

David M. Cotter dave at kjams.com
Fri Jul 9 17:30:40 CEST 2021


the correct implementation is this: (note it still does one extra copy, i do not know how to remove that)

static
QVideoFrame		QVideoFrame_fromImage(const QImage& image)
{
	QVideoFrameFormat	frameFormat(
		image.size(),
		QVideoFrameFormat::pixelFormatFromImageFormat(image.format()));
	QVideoFrame		vidFrame(frameFormat); vidFrame.map(QVideoFrame::WriteOnly);
	qsizetype		image_rowbytesI(image.bytesPerLine());
	qsizetype		frame_rowbytesI(vidFrame.bytesPerLine());
	const uchar*		imageBitsP(image.bits());
	uchar*			frameBitsP(vidFrame.bits());
	int			maxRowY(image.size().height());

	CF_ASSERT(image_rowbytesI <= frame_rowbytesI);

	for (int rowY = 0; rowY < maxRowY; ++rowY) {
		std::copy(imageBitsP, imageBitsP + image_rowbytesI, frameBitsP);
		imageBitsP += image_rowbytesI;
		frameBitsP += frame_rowbytesI;
	}

	vidFrame.unmap();
	return vidFrame;
}



> On Jul 7, 2021, at 12:23 PM, David M. Cotter <dave at kjams.com> wrote:
> 
> that goes in the other direction. what i want is to set the image, not get it.
> 
>> On Jul 7, 2021, at 12:17 PM, Vladyslav Stelmakhovskyi <vladstelmahovsky at gmail.com <mailto:vladstelmahovsky at gmail.com>> wrote:
>> 
>> Hmm. What happens with .toImage() in Qt6's QVideoFrame?
>> 
>> On 2021-07-07 18:38, David M. Cotter wrote:
>>> does this seem right?
>>> 
>>> 	const QImage&	image(pix);
>>> 	#if _QT6_
>>> 		QVideoFrameFormat	frameFormat(
>>> 			image.size(),
>>> 			QVideoFrameFormat::pixelFormatFromImageFormat(image.format()));
>>> 		QVideoFrame		vidFrame(frameFormat); vidFrame.map(QVideoFrame::WriteOnly);
>>> 		uchar*			memBitsP(vidFrame.bits());
>>> 		const uchar*		imageBitsP(image.bits());
>>> 		size_t			memSizeL(vidFrame.mappedBytes());
>>> 		size_t			imgSizeL(image.sizeInBytes());
>>> 		CF_ASSERT(memSizeL == imgSizeL);
>>> 		std::copy(imageBitsP, imageBitsP + memSizeL, memBitsP);
>>> 		vidFrame.unmap();
>>> 	#else
>>> 		// qt5 version
>>> 		QVideoFrame		vidFrame(image);
>>> 	#endif
>>> 	present(vidFrame, opacityF);
>>> seems like a lot of convolution just to get an image into a video frame. also why was the API designed to have the unnecessary copy? the api should take a bits* directly, rather than forcing you to copy your bits into yet another buffer.
>>> 
>>> am i missing something?
>>> 
>>>> On Jul 7, 2021, at 8:48 AM, David M. Cotter <dave at kjams.com <mailto:dave at kjams.com>> wrote:
>>>> 
>>>> seems the API to so so has been removed, so how do i do it?
>>>> 
>>>> i can't find any documentation on porting guidance
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20210709/39b0fad8/attachment.html>


More information about the Interest mailing list