Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Receiving NV21 pixel format from camera using an implemented QAbstractVideoSurface class but result is gray not colorful



  • The following code is used to write every video frame.
    but the result is gray.

    problem 1 :

    frame.image().isNull();// true forever
    

    problem 2 :

    frame.image().convertToFormat(someFormat).isNull();//true forever
    

    problem 3 :

    QImage	defaultImage ( frame.bits ( ), frame.width ( ), frame.height ( ), frame.bytesPerLine ( ), QImage::Format_Grayscale8 );// this operation does not work for every format and many of those make our result image null other than Alpha8, Mono, MonoLSB (all make our image terrible), Indexed, grayscale8 (gray style)
    

    videosurface.cpp

    bool VideoSurfacer::present ( const QVideoFrame & f )
    {
    	QVideoFrame frame ( f );
    	if ( frame.isValid ( ) && frame.map ( QAbstractVideoBuffer::MapMode::ReadWrite ) )
    		{
    			QImage	defaultImage ( frame.bits ( ), frame.width ( ), frame.height ( ), frame.bytesPerLine ( ), QImage::Format_Grayscale8 );
    			QString path = QStandardPaths::writableLocation ( QStandardPaths::GenericDataLocation ) + "/download/" + QString::number ( ++i );
    			QFile ( path + ".jpg" ).remove ( );
    			defaultImage.save ( path + ".jpg", "JPG" );
    
    			frame.unmap ( );
    		}
    	return true;
    }
    

    attention : QVideoFrame::imageFormatFromPixelformat(frame.pixelFormat());
    returns Format_Invalid which makes our image terrible like Mono etc


  • Lifetime Qt Champion

    So from the documentation you can only access it when mapping the frame. So you have to manage the data yourself.


  • Lifetime Qt Champion

    Hi,

    Did you check the handle type ?



  • Handle type is NoHandle


  • Lifetime Qt Champion

    So from the documentation you can only access it when mapping the frame. So you have to manage the data yourself.


Log in to reply