1#include <QLoggingCategory> 
    4#include "RecordVideo.h" 
    6static Q_LOGGING_CATEGORY(log, 
"Record.Video")
 
    7static Q_LOGGING_CATEGORY(logThread, "Record.Video.Thread")
 
   17    bool check = connect(
this, SIGNAL(finished()),
 
   18                         this, SLOT(deleteLater()));
 
 
   22int CRecordVideoThread::SetFile(
const QString &szFile)
 
   28void CRecordVideoThread::run()
 
   31    qDebug(logThread) << 
"Record video thread start ...";
 
   33    int nRet = record.Start(m_szFile);
 
   35        qCritical(logThread) << 
"Start record fail:" << nRet;
 
   36        emit sigStatusChanged(CFrmViewer::RecordVideoStatus::Error);
 
   39    check = connect(&record, SIGNAL(sigStatusChanged(CFrmViewer::RecordVideoStatus)),
 
   40                    this, SIGNAL(sigStatusChanged(CFrmViewer::RecordVideoStatus)));
 
   42    check = connect(
this, SIGNAL(sigUpdate(QImage)),
 
   43                    &record, SLOT(slotUpdate(QImage)));
 
   45    check = connect(&record, SIGNAL(sigError(
int,QString)),
 
   46                    this, SIGNAL(sigError(
int,QString)));
 
   48    emit sigStatusChanged(CFrmViewer::RecordVideoStatus::Recording);
 
   54        qCritical(logThread) << 
"Stop record fail:" << nRet;
 
   55        emit sigStatusChanged(CFrmViewer::RecordVideoStatus::Error);
 
   58        emit sigStatusChanged(CFrmViewer::RecordVideoStatus::Stop);
 
   59    qDebug(logThread) << 
"Record video thread end";
 
   62CRecordVideo::CRecordVideo(QObject *parent)
 
   65#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) 
   67        &m_Recorder, &QMediaRecorder::errorOccurred,
 
   68        this, [&](QMediaRecorder::Error error, 
const QString &errorString) {
 
   69            qDebug(log) << 
"Recorder error occurred:" << error << errorString;
 
   71            emit sigError(error, errorString);
 
   77int CRecordVideo::Start(
const QString &szFile)
 
   80    qDebug(log) << 
"Start";
 
   81#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) 
   82    m_Parameter.SetEnable(
true);
 
   83    m_Parameter >> m_Recorder;
 
   84    m_CaptureSession.setVideoFrameInput(&m_VideoFrameInput);
 
   86    m_CaptureSession.setRecorder(&m_Recorder);
 
   87    m_Recorder.setOutputLocation(QUrl::fromLocalFile(m_Parameter.GetFile(
true)));
 
   93int CRecordVideo::Stop()
 
   96    qDebug(log) << 
"Stop";
 
   97#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) 
   99    m_CaptureSession.setVideoFrameInput(
nullptr);
 
  100    m_CaptureSession.setAudioBufferInput(
nullptr);
 
  101    m_CaptureSession.setRecorder(
nullptr);
 
  107void CRecordVideo::slotUpdate(QImage img)
 
  109    qDebug(log) << 
"Update image";
 
  110#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) 
  111    QVideoFrame frame(img);
 
  112    bool bRet = m_VideoFrameInput.sendVideoFrame(frame);
 
  116        qDebug(log) << 
"m_VideoFrameInput.sendVideoFrame fail";