Qt/C++ programming video surveillance system 80-remote playback video stream

I. Introduction

There are generally three ways to remotely play back video files on the NVR or server. The first is to call the manufacturer’s SDK, which has the most complete functions, but the obvious disadvantage is that each manufacturer’s equipment has its own SDK, which is only compatible with its own equipment. If your software needs to be connected to multiple manufacturers, it means that you have to write many sets of SDK connections. Moreover, most of the SDKs provided by general manufacturers are only win ones, and a small number of large manufacturers also provide linux ones, but basically they are all X86 ones. The second way is to use GB28181, which is the national standard protocol of the monitoring industry. It can play back and download video files. This is the most suitable. After all, it is a standard protocol. According to the protocol, it can be used on any platform. The disadvantage is that it is more complicated and requires various procedures. Compatibility testing of equipment requires some adjustments. The third is to play back through the rtsp protocol. This is the easiest way to implement. Just combine the corresponding rtsp playback video address according to the manufacturer's regulations. The address has parameters such as start time and end time. The disadvantage is that it can only play back and switch the playback progress. , if you need to download, you need to enable storage to the local, this is not advisable, it should be better to download video files from the server.

At present, the equipment made by various monitoring manufacturers basically supports direct streaming display through rtsp, and the better ones also support playback streaming via rtsp. Basically, a string rule is agreed, and each manufacturer does not The same rules, for example, the rtsp address corresponding to the playback must also have a time range, and the playback must specify a start time and end time. What needs to be specially reminded here is that rtsp is a real-time video stream, which generally has no duration, and the playback rtsp video stream has a duration, so you can use seek to locate the playback position, which is very convenient for users to use on the software. Arbitrarily drag and switch the playback position. I used to think that the rtsp real-time video stream could not be long for a long time. It turned out that I was ignorant. I only learned about this feature under the guidance of an old audio and video expert. Of course, this feature requires equipment. Manufacturers implement support in the backend.

With the feature that the playback can switch the playback progress position, it means that the playback does not need to be parsed by the GB28181 national standard, and the corresponding playback video stream string can be directly constructed. After the current test, there is no problem with normal playback and switching progress playback. The only problem is double-speed playback. At present, it still does not support double-speed playback. I don’t know if there are other mechanism elements to control such as parameters. In fact, the core of streaming and playback is to get the rtsp string of the corresponding device according to different manufacturers, and the decoding side needs to get the duration, and treat it as a file, because the file type can switch the playback progress.

Video address: https://www.bilibili.com/video/BV13G411Z7V1

2. Rendering

insert image description here

3. Experience address

  1. Domestic site: https://gitee.com/feiyangqingyun
  2. International site: https://github.com/feiyangqingyun
  3. Personal works: https://blog.csdn.net/feiyangqingyun/article/details/97565652
  4. Experience address: https://pan.baidu.com/s/1d7TH_GEYl5nOecuNlWJJ7g Extraction code: 01jf File name: bin_video_system.

4. Related codes

QString UrlHelper::getRtspUrl(const UrlPara &urlPara)
{
    
    
    QString url;
    //头部地址格式完全一致
    QString head = QString("rtsp://%1:%2@%3:554").arg(urlPara.userName).arg(urlPara.userPwd).arg(urlPara.deviceIP);
    if (urlPara.companyType == CompanyType_HaiKang) {
    
    
        //实时预览格式 rtsp://admin:[email protected]:554/Streaming/Channels/101?transportmode=unicast
        //视频回放格式 rtsp://admin:[email protected]:554/Streaming/tracks/101?starttime=20120802t063812z&endtime=20120802t064816z
        //流媒体视频流 rtsp://172.6.24.15:554/Devicehc8://172.6.22.106:8000:0:0?username=admin&password=12345
        //日期时间格式 ISO 8601 表示Zulu(GMT) 时间 YYYYMMDD”T”HHmmSS.fraction”Z”,
        //unicast表示单播,multicast表示多播,默认单播可以省略
        //101解析: 1是通道号 01是通道的码流编号 也可以是02 03
        QString startTimeISO = urlPara.dateTimeStart.toString(Qt::ISODate);
        startTimeISO.replace("-", "");
        startTimeISO.replace(":", "");
        startTimeISO.toLower();

        QString endTimeISO = urlPara.dateTimeEnd.toString(Qt::ISODate);
        endTimeISO.replace("-", "");
        endTimeISO.replace(":", "");
        endTimeISO.toLower();

        //通道号和码流编号
        QString info = QString("%1%2%3").arg(urlPara.channel).arg(0).arg(urlPara.streamType + 1);
        //回放时间范围
        QString time = QString("starttime=%1z&endtime=%2z").arg(startTimeISO).arg(endTimeISO);
        //实时和回放地址格式不同
        if (urlPara.videoType == 0) {
    
    
            url = QString("%1/Streaming/Channels/%2").arg(head).arg(info);
        } else if (urlPara.videoType == 1) {
    
    
            url = QString("%1/Streaming/tracks/%2?%3").arg(head).arg(info).arg(time);
        }
    } else if (urlPara.companyType == CompanyType_DaHua) {
    
    
        //实时预览格式 rtsp://192.168.1.128:554/cam/realmonitor?channel=1&subtype=0&unicast=true&proto=Onvif
        //视频回放格式 rtsp://admin:[email protected]:554/cam/playback?channel=1&subtype=0&starttime=2021_03_18_11_36_01&endtime=2021_03_18_12_05_01
        QString startTimeStr = urlPara.dateTimeStart.toString("yyyy_MM_dd_HH_mm_ss");
        QString endTimeStr = urlPara.dateTimeEnd.toString("yyyy_MM_dd_HH_mm_ss");
        //通道号和码流编号
        QString info = QString("channel=%1&subtype=%2").arg(urlPara.channel).arg(urlPara.streamType);
        //回放时间范围
        QString time = QString("starttime=%1&endtime=%2").arg(startTimeStr).arg(endTimeStr);
        //实时和回放地址格式不同
        if (urlPara.videoType == 0) {
    
    
            url = QString("%1/cam/realmonitor?%2&unicast=true&proto=Onvif").arg(head).arg(info);
        } else if (urlPara.videoType == 1) {
    
    
            url = QString("%1/cam/playback?%2&%3").arg(head).arg(info).arg(time);
        }
    } else {
    
    
        //实时预览格式 rtsp://admin:[email protected]:554/live?channel=1&stream=1
        //视频回放格式 rtsp://admin:[email protected]:554/file?channel=1&start=1494485280&stop=1494485480
        //先转换时间戳,1970年到该时间经过的秒数
        qint64 startTimeSec = urlPara.dateTimeStart.toMSecsSinceEpoch() / 1000;
        qint64 stopTimeSec = urlPara.dateTimeEnd.toMSecsSinceEpoch() / 1000;
        //回放时间范围
        QString time = QString("start=%1&stop=%2").arg(startTimeSec).arg(stopTimeSec);
        //实时和回放地址格式不同
        if (urlPara.videoType == 0) {
    
    
            url = QString("%1/live?channel=%2&stream=%3").arg(head).arg(urlPara.channel).arg(urlPara.streamType);
        } else if (urlPara.videoType == 1) {
    
    
            url = QString("%1/file?channel=%2&%3").arg(head).arg(urlPara.channel).arg(time);
        }
    }

    //还有一种通用格式 rtsp://admin:[email protected]:554/0  0-主码流 1-子码流
    return url;
}

5. Features

5.1 Software modules

  1. Video monitoring module, various docking small window sub-modules, including device list, graphic alarm information, window information, PTZ control, preset position, cruise setting, device control, floating map, web browsing, etc.
  2. Video playback module, including local playback, remote playback, device playback, picture playback, video upload, etc.
  3. Electronic map module, including picture map, online map, offline map, path planning, etc.
  4. Log query module, including local logs, device logs, etc.
  5. System settings module, including system settings (basic settings, video parameters, database settings, map configuration, serial port configuration, etc.), video recorder management, camera management, polling configuration, recording plan, user management, etc.

5.2 Basic functions

  1. Support various video streams (rtsp, rtmp, http, etc.), video files (mp4, rmvb, avi, etc.), local USB camera playback.
  2. Support multi-screen switching, including 1, 4, 6, 8, 9, 13, 16, 25, 36, 64 screen switching.
  3. Support full screen switching, a variety of switching methods including the right mouse button menu, toolbar buttons, shortcut keys (alt+enter full screen, esc to exit full screen).
  4. Support video polling, including 1, 4, 9, 16 screen polling, and can set polling group (polling plan), polling interval, code stream type, etc.
  5. Support onvif protocol, including device search, PTZ control, preset position, device control (picture parameters, proofreading time, system restart, snapshot pictures, etc.).
  6. Support permission management, different users can correspond to different module permissions, such as deleting logs, shutting down the system, etc.
  7. Various databases are supported, including sqlite, mysql, sqlserver, postgresql, oracle, Renda Jincang, etc.
  8. The local USB camera supports setting parameters such as resolution and frame rate.
  9. All docking modules automatically generate corresponding menus to control display and hide, which can be popped up by right clicking on the title bar.
  10. Support display all modules, hide all modules, reset normal layout, reset full screen layout.
  11. Double-click the device to pop up a real-time preview video, supporting image maps, online maps, offline maps, etc.
  12. Drag the camera node to the corresponding window to play the video, and support dragging local files to play directly.
  13. Deleting videos supports multiple methods such as right mouse button deletion, suspension bar closing deletion, dragging to the outside of the video monitoring panel to delete, etc.
  14. The device button on the picture map can be dragged freely, and the location information is automatically saved. On the Baidu map, you can click the mouse to obtain the latitude and longitude information, which is used to update the device location.
  15. Any channel in the video monitoring panel window supports dragging and switching, and responds instantly.
  16. It encapsulates Baidu map, view switching, movement track, equipment point, mouse press to obtain latitude and longitude, etc.
  17. Operations such as double-clicking a node, dragging a node, or dragging a window to exchange positions, etc., will automatically update and save the last playback address, which will be automatically applied next time the software is opened.
  18. The volume bar control in the lower right corner, loses focus and automatically hides, and the volume bar has a mute icon.
  19. Support video screenshot, you can specify a single or screenshot of all channels, and there is also a screenshot button in the small toolbar at the bottom.
  20. Support overtime automatically hide the mouse pointer, automatic full screen mechanism.
  21. Support onvif PTZ control, you can move the PTZ camera up, down, left, and right, including reset and focus adjustment.
  22. Support onvif preset position, you can add, delete, modify the preset position, you can call the start position.
  23. Support onvif image parameter settings, including brightness, contrast, saturation, sharpness, etc.
  24. Support other operations of onvif, including image capture, network settings, time adjustment, restart, event subscription, etc.
  25. Support any onvif camera, including but not limited to Hikvision, Dahua, Uniview, Tiandiweiye, Huawei, etc.
  26. Video can be saved, with optional timing storage or single file storage, and optional storage interval.
  27. You can set the video stream communication mode tcp+udp, and you can set the video decoding speed priority, quality priority, balance, etc.
  28. You can set the software Chinese name, English name, LOGO icon, etc.
  29. Stored video files can be exported to a specified directory and uploaded to the server in batches.
  30. Perfect recording plan settings, support for each channel 7 * 24 hours every half hour to set whether to store recordings.

5.3 Features

  1. The main interface adopts the docking form mode, and various components are added in the form of small modules, and any module can be customized to add.
  2. The docking module can be dragged anywhere to embed and float, and it supports maximizing full screen and multiple screens.
  3. Dual layout file storage mechanism, normal mode and full-screen mode correspond to different layout schemes, automatically switch and save, for example, full-screen mode can highlight several modules and display them transparently in the designated position, which is more sci-fi and modern.
  4. The original onvif protocol mechanism adopts the underlying protocol analysis (udp broadcast search + http request execution command), which is lighter, easier to understand and easier to learn and expand, and does not rely on any third-party components such as gsoap.
  5. Original data import, export, and print mechanisms, cross-platform without relying on any components, and instantly export data.
  6. Multiple built-in original components, super value in the universe, including data import and export components (export to xls, pdf, printing), database components (database management thread, automatic cleaning data thread, universal paging, data request, etc.), map components , video monitoring components, multi-threaded file sending and receiving components, onvif communication components, common browser kernel components, etc.
  7. Custom information box + error box + inquiry box + prompt box in the lower right corner (including multiple formats), etc.
  8. Exquisite skinning, up to 17 sets of skin styles can be changed at will, all styles are unified, including menus, etc.
  9. The video control floating bar can add multiple buttons by itself, and the small toolbar at the bottom of the monitoring interface can also add buttons by itself.
  10. Double-click the camera node to automatically play the video, double-click the node to automatically add videos in sequence, and automatically jump to the next one, double-click the parent node to automatically add all videos under the node. Optional main stream and sub stream.
  11. Video recorder management, camera management, can add, delete, modify, import, export and print information, and immediately apply the new device information to generate a tree list without restarting.
  12. A variety of kernels can be selected to switch freely, ffmpeg, vlc, mpv, etc., can be set in pro. It is recommended to use ffmpeg, which is the most cross-platform, and the compiled libraries on the linux and mac platforms are provided by default.
  13. Support hard decoding, you can set the hard decoding type (qsv, dxva2, d3d11va, etc.).
  14. By default, opengl is used to draw video, ultra-low CPU resource usage, supports yuyv and nv12 two formats of drawing, and the performance is explosive.
  15. Labels and graphic information support three drawing methods, drawing to the mask layer, drawing to the picture, and drawing from the source (corresponding information can be stored in a file).
  16. Highly customizable, users can easily derive their own functions on this basis, such as adding custom modules, adding operation modes, robot monitoring, drone monitoring, excavator monitoring, etc.
  17. Support xp, win7, win10, win11, linux, mac, various domestic systems (UOS, Winning Kirin, Galaxy Kirin, etc.), embedded linux and other systems.
  18. The comments are complete, the project structure is clear, the super detailed and complete user development manual is accurate to the function description of each code file, and the version is continuously iterated.

Guess you like

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