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

QVideoSink QVideoFrame format



  • In Qt 6.2.2 I have custom QVideoSInk

    class Frames
    	:	public QVideoSink
    

    In this class I have

    void newFrame( const QVideoFrame & frame );
    

    slot connected to

    connect( this, &QVideoSink::videoFrameChanged,
    			this, &Frames::newFrame );
    

    In this class I have members

    QCamera * m_cam;
    QMediaCaptureSession m_capture;
    

    I initialize camera with

    void
    Frames::initCam()
    {
    	const auto camDev = CameraSettings::instance().camName();
    
    	if( !camDev.isEmpty() )
    		m_cam = new QCamera( CameraSettings::instance().camInfo( camDev ), this );
    	else
    		m_cam = new QCamera( this );
    
    	m_cam->setFocusMode( QCamera::FocusModeAuto );
    	qDebug() << CameraSettings::instance().camSettings().pixelFormat();
    	m_cam->setCameraFormat( CameraSettings::instance().camSettings() );
    	m_capture.setCamera( m_cam );
    	m_capture.setVideoSink( this );
    
    	m_cam->start();
    }
    

    where

    CameraSettings::instance().camSettings().pixelFormat()
    

    is "Format_""Jpeg". I set specially format of camera to JPEG to have ability to convert QVideoFrame to QImage.

    But in

    void
    Frames::newFrame( const QVideoFrame & frame )
    {
    	QVideoFrame f = frame;
    	f.map( QVideoFrame::ReadOnly );
    
    	const auto fmt = QVideoFrameFormat::imageFormatFromPixelFormat( f.pixelFormat() );
    
    	QImage image;
    
    	if( fmt != QImage::Format_Invalid )
    		image = QImage( f.bits( 0 ), f.width(), f.height(), f.bytesPerLine( 0 ), fmt );
    	else
    		image.loadFromData( f.bits( 0 ), f.mappedBytes( 0 ) );
    
    	qDebug() << f.pixelFormat();
    	f.unmap();
    

    I see that format of QVideoFrame is "Format_""YUV420P".

    So my question is this a desired behavior, or this is a bug of Qt 6.2.2? In Qt 5.15 format of QVideoFrame was as set in QCamera...


  • Lifetime Qt Champion

    Hi,

    Did you check the supported format from your device ?
    Does it generate jpeg ?



  • During initialization I gather supported formats of cameras that can be converted to QImage with the following code:

    for( auto it = m_camsInfo.cbegin(), last = m_camsInfo.cend(); it != last; ++it )
    {
    	const auto settings = it.value().videoFormats();
    
    	for( const auto & s : settings )
    	{
    		if( s.pixelFormat() == QVideoFrameFormat::Format_Jpeg ||
    			QVideoFrameFormat::imageFormatFromPixelFormat( s.pixelFormat() ) !=
    				QImage::Format_Invalid )
    		{
    			const auto resolutionStr = resolution( s.resolution().width(),
    				s.resolution().height(), s.maxFrameRate() );
    
    			m_resolutions[ it.key() ].insert( resolutionStr, s );
    		}
    	}
    }
    

    So settings for camera can't be set so that can't be converted to QImage. I'm sure that my camera supports JPEG format, and I set to it exactly JPEG format to generate. But in newFrame() format is YUV420P.



  • I created an issue. Will have a look what developers will say.



  • This post is deleted!

Log in to reply