最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

qt - Qt6 QMediaRecorder not record using QVideoFrameInput on Windows 11 - Stack Overflow

programmeradmin1浏览0评论

I'm developing the app using IP camera. I'm able to display it using QML but unable to record although it's create file but only 0 KB.

File created by QMediaRecorder:

My QML file

Rectangle {
    id: root

    property alias fillMode: output.fillMode

    VideoOutput {
        id: output
        anchors.fill: parent
        fillMode: root.fillMode
    }

    MediaRecorder {
        id: recorder
        encodingMode: "AverageBitRateEncoding"

        onRecorderStateChanged: {
            console.debug(error)
            console.debug(errorString)
        }

        onErrorOccurred: {
            console.debug(error)
            console.debug(errorString)
        }

    }

    CaptureSession {
        id: session
        objectName: "session"
        videoOutput: output
        recorder: recorder
    }

    // My custom class
    Player {
        id: player
        captureSession: session
    }
}

The output said:

QObject::connect: Cannot queue arguments of type 'RecorderState'
(Make sure 'RecorderState' is registered using qRegisterMetaType().)QObject::connect: Cannot queue arguments of type 'RecorderState'

Inside custom class:

void Player::record()
{
    if (m_captureSession.isNull())
    {
        qWarning() << QString("No capture session attached!").toStdString();
        return;
    }

    m_videoFrameInput = new QVideoFrameInput();

    m_mediaRecorder = m_captureSession->recorder();
    m_mediaRecorder->setOutputLocation(QUrl::fromLocalFile(m_fileName));
    m_mediaRecorder->record();
}

This callback able to display QVideoFrame to VideoOutput but not record into file:

void Player::frameReceived(int streamIndex, char *buf, long bufSize, long width, long height, long stamp, long type, long frameRate)
{
    m_mutex.lock();

    QVideoFrame vf(QVideoFrameFormat(QSize(width, height), QVideoFrameFormat::Format_YV12));

    if(!vf.isValid() || !vf.map(QVideoFrame::WriteOnly))
    {
        qWarning() << "QVideoFrame is not valid or not writable!";
        m_mutex.unlock();
        return;
    }

    memcpy(vf.bits(0), buf, bufSize);
    vf.unmap();

    if (m_mediaRecorder->recorderState() == QMediaRecorder::StoppedState)
    {
        m_mediaRecorder->record();
    }

    m_videoFrameInput->sendVideoFrame(vf); // VideoFrame displayed

    m_mutex.unlock();
}

I would like to display and recording simultaneously.
If possible, is there any technique to playback, seek the recording file during the record in [1]?

发布评论

评论列表(0)

  1. 暂无评论