Qt audio and video development 19-haikang sdk video storage

I. Introduction

Regarding calling the Haikang SDK for video storage, the overall framework architecture processing flow follows the previous practice of vlc, ffmpeg, and mpv cores. For timing storage, set a timer to judge, and close the original video storage when the time comes. , And then start a new video storage, re-input the new file name, so this piece of code can be directly copied over and can be used, all you have to do is to replace two lines of code, one line is the function NET_DVR_SaveRealData to start video storage, One line is the function NET_DVR_StopSaveRealData to stop the video storage. The manual of the Hikvision SDK is very detailed and the naming is relatively standard. Basically, you can know the general meaning through the method function name, no need to guess.

There is also a screenshot function in the same category as the video storage function. This is implemented in the vlc kernel, ffmpeg kernel, and mpv kernel. The screenshot summarizes three types. The first is the screenshot in the handle mode. This needs to be called Related SDK functions to execute, the resolution size is the original image; the second is the screenshot in the callback mode, this has already got the picture data, just take the picture corresponding to the saved video in the form, and the resolution size is the original Figure; The third type is a screenshot of the window, which is a screenshot of the current video window, and the resolution is the size of the current window;

Regarding the three functions of opening video files, video storage, and screenshot saving, pay special attention to the Chinese path. Of course, if there is only an English path, then no processing is required. However, for Chinese people, the Chinese path is definitely unavoidable. There are two possible treatments, one is that the path needs to be converted to utf8 format, and the other is to use QTextCodec to specify the gb2312 format to re-translate the path to take effect. For example, under the Haikang sdk kernel, otherwise the path may be invalid.

2. Features

  1. Supports playing video streams and local MP4 files.
  2. Support two modes: handle and callback.
  3. Multi-threaded display images, not stuck in the main interface.
  4. Reconnect the webcam automatically.
  5. You can set the border size, offset and border color.
  6. You can set whether to draw OSD labels, that is, label text or pictures and label positions.
  7. Two OSD positions and styles can be set.
  8. Can set whether to save to file and file name.
  9. You can directly drag files to haikangwidget control to play.
  10. Support h264/h265 video stream.
  11. Can pause and resume playing.
  12. Support storage of single video files and timing storage of video files.
  13. Customize the top floating bar, send a click signal notification, and set whether to enable it.
  14. You can set the screen stretch fill or equal proportion fill.
  15. You can set the decoding to be speed priority, quality priority, and equalization processing.
  16. You can take screenshots (original pictures) and screenshots (video forms) of videos.
  17. The video files are stored as MP4 files.
  18. Support focus control, pan/tilt control.
  19. Customizable functions.

Three, renderings

Insert picture description here

Four, related sites

  1. Domestic site: https://gitee.com/feiyangqingyun/QWidgetDemo
  2. International site: https://github.com/feiyangqingyun/QWidgetDemo
  3. Personal homepage: https://blog.csdn.net/feiyangqingyun
  4. Zhihu Homepage: https://www.zhihu.com/people/feiyangqingyun/
  5. Experience address: https://blog.csdn.net/feiyangqingyun/article/details/97565652

Five, the core code

void HaiKangThread::initSave()
{
    if (!saveFile || !isRtsp) {
        return;
    }

    if (saveInterval == 0) {
        saveVideo(fileName);
    }
}

void HaiKangThread::saveVideo()
{
    if (!saveFile || !isRtsp) {
        return;
    }

    //重新设置文件名称
    QString dirName = QString("%1/%2").arg(savePath).arg(QDATE);
    newDir(dirName);
    fileName = QString("%1/%2_%3.mp4").arg(dirName).arg(fileFlag).arg(STRDATETIME);
    saveVideo(fileName);
}

void HaiKangThread::saveVideo(const QString &fileName)
{
    if (hand >= 0) {
        //转码以便支持中文路径
        QTextCodec *codec = QTextCodec::codecForName("gb2312");
        QByteArray data = codec->fromUnicode(fileName);

        //先停止再设置
        NET_DVR_StopSaveRealData(hand);
        NET_DVR_SaveRealData(hand, data.data());
    }
}

Guess you like

Origin blog.csdn.net/feiyangqingyun/article/details/108253660