Qt/C++ writing video surveillance system 82-custom sound column display

I. Introduction

The amplitude of the currently played sound is displayed in real time through the sound column control. Thanks to the built-in calculation of audio amplitude in the audio playback component, it can be turned on and off dynamically. After being turned on, the sound data sent to be played will be calculated. Get the amplitude of the current audio data, similar to decibels. The greater the decibel, the louder the sound you hear and the greater the amplitude. On the issue of how to place the sound column control, we have considered various solutions. For example, we initially placed it on the right side of the video control. That is, we first placed a video control in a vertical layout, and then placed the left channel sound. column, and finally place a right channel sound column, and set the spacing between the three controls. Later, users proposed that the sound column control be directly suspended above the video control. This can save space and allow the video control to strive for the largest display area. Therefore, it has been specially redesigned recently. The sound column can be placed on the left, right, or top. , bottom, sides, floating and other positions, and then you can also set the size of the sound column. If it is placed vertically, the corresponding size is the width. If it is placed up and down, the corresponding size is the height. Another difficulty is the pure audio channel and volume. The bar needs to be placed in the middle position. For example, there are springs on the left and right sides of the volume bar. The size of the volume bar is one-quarter of the width, so that it looks very beautiful.

Since the video control also has a floating bar, the position of the sound column needs to leave enough space for the floating bar to be displayed. However, the floating bar has many positions. For example, it can also be set at the bottom, so it needs to be placed according to the floating bar. position of the strips, and then leave corresponding gaps. With the convenience of Qt, it is very convenient to design such a video form with a suspended video band and a sound column, and it also supports very flexible parameter settings. For example, just create a new frmVideoWidgetVolume video form with a sound column, and the floating bar is also An independent widget that moves around according to size changes. On the sound column control side, the corresponding controls are inserted through the table layout. For example, if you need to display sound columns on both sides, insert the left channel sound column first, then insert the video control, and finally insert the right channel sound column control. The difficulty lies in the pure audio channel control. It needs to be automatically stretched according to the size ratio, and a form needs to distinguish whether it is pure audio based on the opened address, so it needs to be judged when the decoding is completed and ended. , call it a day.

2. Effect drawing

Insert image description here

3. Experience address

  1. Domestic site: https://gitee.com/feiyangqingyun
  2. International site: https://github.com/feiyangqingyun
  3. Personal work: 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

#include "frmvideowidgetvolume.h"
#include "ui_frmvideowidgetvolume.h"
#include "qthelper.h"
#include "videowidgetx.h"
#include "barvolume.h"

frmVideoWidgetVolume::frmVideoWidgetVolume(int position, VideoWidget *videoWidget, QWidget *parent) : QWidget(parent), ui(new Ui::frmVideoWidgetVolume)
{
    
    
    ui->setupUi(this);

    this->position = position;
    this->videoWidget = videoWidget;
    bgText = videoWidget->getBgText();

    isVertical = true;
    if (position == 2 || position == 4) {
    
    
        isVertical = false;
    }

    //实例化音柱控件并设置方向
    leftVolume = new BarVolume;
    rightVolume = new BarVolume;
    leftVolume->setVertical(isVertical);
    rightVolume->setVertical(isVertical);

    //实例化布局并设置边距间距
    QGridLayout *layout = new QGridLayout(this);
    layout->setContentsMargins(0, 0, 0, 0);
    layout->setSpacing(3);

    //将音柱控件和视频控件插入到对应位置/可以自行拓展各种布局
    if (position == 1) {
    
    
        layout->addWidget(leftVolume, 0, 0);
        layout->addWidget(rightVolume, 0, 1);
        layout->addWidget(videoWidget, 0, 2);
    } else if (position == 2) {
    
    
        layout->addWidget(leftVolume, 0, 0);
        layout->addWidget(rightVolume, 1, 0);
        layout->addWidget(videoWidget, 2, 0);
    } else if (position == 3) {
    
    
        layout->addWidget(videoWidget, 0, 0);
        layout->addWidget(leftVolume, 0, 1);
        layout->addWidget(rightVolume, 0, 2);
    } else if (position == 4) {
    
    
        layout->addWidget(videoWidget, 0, 0);
        layout->addWidget(leftVolume, 1, 0);
        layout->addWidget(rightVolume, 2, 0);
    } else if (position == 5) {
    
    
        layout->addWidget(leftVolume, 0, 0);
        layout->addWidget(videoWidget, 0, 1);
        layout->addWidget(rightVolume, 0, 2);
    } else if (position == 6) {
    
    
        //实例化弹簧控件
        spaceLeft = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Preferred);
        spaceCenter = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Preferred);
        spaceRight = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Preferred);

        //实例化布局并插入控件
        hlayout = new QHBoxLayout;
        hlayout->addWidget(leftVolume);
        hlayout->addItem(spaceCenter);
        hlayout->addWidget(rightVolume);
        videoWidget->setLayout(hlayout);
        layout->addWidget(videoWidget);
    }

    //关联音频振幅信号
    connect(videoWidget, SIGNAL(sig_receiveLevel(qreal, qreal)), this, SLOT(receiveLevel(qreal, qreal)));
    //打开和关闭后需要清空下(有可能残留上一次的数据)
    connect(videoWidget, SIGNAL(sig_receivePlayStart(int)), this, SLOT(reset()));
    connect(videoWidget, SIGNAL(sig_receivePlayFinsh()), this, SLOT(reset()));
    //音柱窗体参数变化后需要重置
    connect(AppEvent::Instance(), SIGNAL(changeVolumeWidget()), this, SLOT(reset()));
}

frmVideoWidgetVolume::~frmVideoWidgetVolume()
{
    
    
    delete ui;
}

void frmVideoWidgetVolume::resizeEvent(QResizeEvent *)
{
    
    
    int width = this->width();
    int height = this->height();

    //根据宽度动态设置音量条宽度或者高度/也可以设置成固定值
    int size = (isVertical ? width : height);
    if (AppConfig::VolumeSize == 0) {
    
    
        size = size * 0.05;
        size = (size > 20 ? 20 : size);
    } else {
    
    
        size = AppConfig::VolumeSize;
    }

    if (isVertical) {
    
    
        leftVolume->setMaximumWidth(size);
        rightVolume->setMaximumWidth(size);
    } else {
    
    
        leftVolume->setMaximumHeight(size);
        rightVolume->setMaximumHeight(size);
    }

    //根据高度动态设置音量格子数量(一般高度越小格子数越少)
    int step = height / (position == 6 ? 10 : 6);
    leftVolume->setStep(step);
    rightVolume->setStep(step);

    //根据音柱位置摆放控件
    if (position == 6) {
    
    
        if (videoWidget->getIsRunning() && videoWidget->getVideoThread()->getIsOk()) {
    
    
            leftVolume->show();
            rightVolume->show();

            //根据悬浮条的位置留出空余的地方
            int offset = 35;
            if (AppConfig::BannerPosition == 1) {
    
    
                hlayout->setContentsMargins(9, 9, 9, offset);
            } else if (AppConfig::BannerPosition == 2) {
    
    
                hlayout->setContentsMargins(offset, 9, 9, 9);
            } else if (AppConfig::BannerPosition == 3) {
    
    
                hlayout->setContentsMargins(9, 9, offset, 9);
            } else {
    
    
                hlayout->setContentsMargins(9, offset, 9, 9);
            }

            //先把布局中的挨个移除
            hlayout->removeItem(spaceLeft);
            hlayout->removeItem(spaceCenter);
            hlayout->removeItem(spaceRight);
            hlayout->removeWidget(leftVolume);
            hlayout->removeWidget(rightVolume);

            //纯音频需要占用比较大的面积
            if (videoWidget->getOnlyAudio()) {
    
    
                videoWidget->setBgText("");
                size = width / 4;
                leftVolume->setMaximumWidth(size);
                rightVolume->setMaximumWidth(size);
                leftVolume->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Ignored);
                rightVolume->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Ignored);
                hlayout->addItem(spaceLeft);
                hlayout->addWidget(leftVolume);
                hlayout->addWidget(rightVolume);
                hlayout->addItem(spaceRight);
            } else {
    
    
                leftVolume->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Ignored);
                rightVolume->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Ignored);
                hlayout->addWidget(leftVolume);
                hlayout->addItem(spaceCenter);
                hlayout->addWidget(rightVolume);
            }
        } else {
    
    
            leftVolume->hide();
            rightVolume->hide();
            videoWidget->setBgText(bgText);
        }
    }
}

void frmVideoWidgetVolume::reset()
{
    
    
    leftVolume->clear();
    rightVolume->clear();
    this->resizeEvent(NULL);
}

void frmVideoWidgetVolume::receiveLevel(qreal leftLevel, qreal rightLevel)
{
    
    
    leftVolume->setValue(leftLevel);
    rightVolume->setValue(rightLevel);
}

5. Functional features

5.1 Software modules

  1. Video surveillance module, various docking small form sub-modules, including device list, graphic and text alarm information, window information, PTZ control, preset position, cruise settings, 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, route 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.), recorder management, camera management, polling configuration, recording plan, user management, etc.

5.2 Basic functions

  1. Supports various video streams (rtsp, rtmp, http, etc.), video files (mp4, rmvb, avi, etc.), and local USB camera playback.
  2. Supports multi-screen switching, including 1, 4, 6, 8, 9, 13, 16, 25, 36, 64 screen switching.
  3. Supports full-screen switching, multiple switching methods include mouse right-click menu, toolbar buttons, shortcut keys (alt+enter to full screen, esc to exit full screen).
  4. Supports video polling, including 1, 4, 9, and 16 screen polling, and can set polling group (polling plan), polling interval, code stream type, etc.
  5. Supports onvif protocol, including device search, PTZ control, preset positions, device control (picture parameters, calibration time, system restart, picture capture, etc.).
  6. Supports permission management. Different users can correspond to different module permissions, such as deleting logs, shutting down the system, etc.
  7. The database supports a variety of databases, including sqlite, mysql, sqlserver, postgresql, oracle, Renmin University of Finance and Economics, 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 hiding, which can be popped up by right-clicking on the title bar.
  10. Supports displaying all modules, hiding all modules, resetting normal layout, and resetting full-screen layout.
  11. Double-click the device to pop up a real-time preview video, supporting picture maps, online maps, offline maps, etc.
  12. Drag the camera node to the corresponding form to play the video, and support dragging local files for direct playback.
  13. Deleting video supports multiple methods such as right-click deletion, closing the floating bar to delete, dragging it outside the video monitoring panel, etc.
  14. The device buttons on the picture map can be dragged freely and location information is automatically saved. On the Baidu map, you can click the mouse to obtain the latitude and longitude information, which can be used to update the device location.
  15. Any channel in the video surveillance panel form supports drag and drop exchange, with instant response.
  16. It encapsulates Baidu map, view switching, motion trajectory, device location, mouse click to obtain latitude and longitude, etc.
  17. Operations such as double-clicking a node, dragging a node, and dragging a window to swap positions 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 automatically hides when it loses focus, and the volume bar has a mute icon.
  19. Supports video screenshots. You can specify a single or all channels to take screenshots. There is also a screenshot button in the small toolbar at the bottom.
  20. Supports automatic hiding of mouse pointer over time and automatic full-screen mechanism.
  21. Supports onvif PTZ control, which can move the PTZ camera up, down, left and right, including reset and focus adjustment.
  22. Supports onvif preset positions, you can add, delete, modify preset positions, and call the starting position.
  23. Support onvif image parameter settings, including brightness, contrast, saturation, sharpness, etc.
  24. Supports other onvif operations, including screenshots, network settings, time adjustment, restart, event subscription, etc.
  25. Supports any onvif camera, including but not limited to Hikvision, Dahua, Uniview, Tiandi Weiye, Huawei, etc.
  26. Videos can be saved, timed storage or single file storage can be selected, and the storage interval can be selected.
  27. The video stream communication mode can be set to tcp+udp, and the video decoding can be set to speed priority, quality priority, balance, etc.
  28. The Chinese name, English name, LOGO icon, etc. of the software can be set.
  29. Stored video files can be exported to a specified directory and uploaded to the server in batches.
  30. Complete recording plan settings, supporting each channel 7 * 24 hours to set whether to store recordings every half hour.

5.3 Features

  1. The main interface adopts docked form mode, and various components are added in the form of small modules. Any module can be customized and added.
  2. The docking module can be dragged to any position to embed and float, and supports maximized full screen and multi-screen support.
  3. Dual layout file storage mechanism, normal mode and full-screen mode correspond to different layout schemes, automatically switching and saving. For example, full-screen mode can highlight several modules and display them transparently at designated positions, which is more modern and sci-fi.
  4. The original onvif protocol mechanism uses underlying protocol analysis (udp broadcast search + http request execution command), which is more lightweight, easy to understand, easy to learn and expand, and does not rely on any third-party components such as gsoap.
  5. The original data import, export, and printing mechanism is cross-platform and does not rely on any components, exporting data instantly.
  6. Built-in multiple original components, the universe is super valuable and awesome, including data import and export components (export to xls, pdf, printing), database components (database management thread, automatic data cleaning thread, universal paging, data request, etc.), map components , video surveillance components, file multi-threaded sending and receiving components, onvif communication components, general browser kernel components, etc.
  7. Customized information box + error box + query box + lower right corner prompt box (including multiple formats), etc.
  8. Exquisite skin change, up to 17 sets of skin styles can be changed at will, all styles are unified, including menus, etc.
  9. Multiple buttons can be added to the video control floating bar, and buttons can also be added to the small toolbar at the bottom of the monitoring interface.
  10. Double-click the camera node to automatically play the video. Double-click the node to automatically add videos in sequence and 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 and camera management can add, delete, modify, import and export print information, and immediately apply new device information to generate a tree list without restarting.
  12. A variety of cores can be freely switched, such as ffmpeg, vlc, mpv, etc., which can all be set in pro. It is recommended to use ffmpeg, which is the most cross-platform and provides compiled libraries for Linux and Mac platforms by default.
  13. Supports hard decoding and can set the hard decoding type (qsv, dxva2, d3d11va, etc.).
  14. By default, opengl is used to draw videos, which consumes ultra-low CPU resources. It supports drawing in two formats, yuyv and nv12, and has explosive performance.
  15. Labels and graphic information support three drawing methods: drawing to mask layer, drawing to picture, and source drawing (corresponding information can be stored in a file).
  16. It is highly customizable, and users can easily derive their own functions on this basis, such as adding custom modules, adding operating modes, robot monitoring, drone monitoring, excavator monitoring, etc.
  17. Supports 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 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/135355456