Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. Qt6 Porting guidance: construct QVideoFrame from QImage
Forum Updated to NodeBB v4.3 + New Features

Qt6 Porting guidance: construct QVideoFrame from QImage

Scheduled Pinned Locked Moved Solved Qt 6
2 Posts 1 Posters 309 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    davecotter
    wrote on 9 Jul 2021, 15:33 last edited by
    #1

    it took me a long time to figure this out so i thought i'd share, so this is searchable in the future:

    if anyone knows how to do this without performing the extra copy, i'd love to know. (ie: move the bits directly from the QImage into video memory, without going through the staging area. eg: am i just missing a QVideoFrame API that i don't know about?

    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;
    }
    
    1 Reply Last reply
    1
    • D Offline
      D Offline
      davecotter
      wrote on 9 Jul 2021, 15:34 last edited by
      #2

      the correct answer is posted above, but a question remains: is this the most efficient method?

      1 Reply Last reply
      1

      1/2

      9 Jul 2021, 15:33

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved