Qt audio and video development 25-ffmpeg volume setting

I. Introduction

The basic functions of playing, closing, pausing, and continuing audio and video are handled by most people at their fingertips. Regarding the volume adjustment, I still spared the bend a little. At the beginning, I planned to use the api of each system to handle it. Sit down. I found that it is not good. The system support is not perfect. For example, some APIs limit win7, but XP does not, and this thing controls the global volume, not good. Most of the time, the volume of the currently playing media needs to be controlled. Players such as vlc and mpv have also had such scene analysis when processing sound. Later, I have also tested the use of ffmpeg's filter code to control the decibel value of audio data. It is more cumbersome and the amount of code is large, which is not convenient for beginners to learn. At last, I thought to find the function of QAudioOutput to see if there is any function of volume. It really came from the belt, and the love for Qt has increased by a few tenths. What should be noted here is the volume value of QAudioOutput. The parameter is a double type in the range of 0-1, not a value of 0-100 for players like vlc, so you need to convert it yourself.
If you get the volume control, then the mute setting is of course minutes, nothing more than memorizing the previous volume, and then set the volume to 0, and automatically set the volume to the last memorized volume value when unmuting.

2. Features

  1. Multi-threaded real-time playback of video stream + local video + USB camera, etc.
  2. Support windows+linux+mac, support ffmpeg3 and ffmpeg4, support 32-bit and 64-bit.
  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 the file to the ffmpegwidget control to play.
  10. Support common video streams such as h265 video stream + rtmp.
  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. Can take screenshots (original pictures) and screenshots of videos.
  17. Video file storage supports bare stream and MP4 files.
  18. Audio and video are perfectly synchronized, using an external clock synchronization strategy.
  19. Support seek to locate the playback position.
  20. Supports hard decoding such as qsv, dxva2, d3d11va, etc.
  21. Support OpenGL to draw video data, very low CPU usage.
  22. Support Android and embedded linux, just cross compile.

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

bool FFmpegThread::getMute()
{
    return (getVolume() == 0);
}

int volume = 0;
void FFmpegThread::setMute(bool mute)
{
    //先记住之前的音量以便重新设置
    if (mute) {
        volume = getVolume();
        setVolume(0);
    } else {
        setVolume(volume);
    }
}

int FFmpegThread::getVolume()
{
    if (this->isRunning()) {
#if (QT_VERSION > QT_VERSION_CHECK(5,0,0))
        return audioOutput->volume() * 100;
#endif
    } else {
        return 0;
    }
}

void FFmpegThread::setVolume(int volume)
{
    if (this->isRunning()) {
#if (QT_VERSION > QT_VERSION_CHECK(5,0,0))
        //查阅手册说范围值是 0.0 - 1.0
        audioOutput->setVolume((float)volume / 100.0);
#endif
    }
}

Guess you like

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