Install FFmpeg

1, install,

  • In a Mac environment, install FFmpeg directly using Homebrew.
brew install ffmpeg
Copy the code
  • After the installation is complete, if you can view the FFmpeg version number on the command line, it indicates that the installation is successful.
ffmpeg -version
Copy the code

2. Directory structure

  • You can viewFFmpegThe installation path
which ffmpeg
Copy the code

  • Check the file
open /usr/local/bin
Copy the code

  • Right click on theffmpeg, click on theAccording to the original body

  • You can jump toffmpegSpecific installation position

  • HomebrewThe installation of theFFmpegIt’s stored away/usr/local/Cellar/ffmpegThe installed version is4.3.2

  • bin: There are compiled executable programs: ffmpeg, ffplay, etc., which can be used directly on the command line, for example
    • ffplay xx.mp4: You can play a video directly
    • ffmpeg -version: You can view the FFmpeg version number
  • include: a header file that needs to be included during development
  • lib: library file to use when linking

Second, the QT

  • If you want to develop a player, must write interface, also in order to ensure cross-platform development, the GUI library used here isQt, the official developer tool QtCreator is cross-platform (Windows, Mac, Linux). Qt is developed using C++ programming language.
  • For this tutorial, select version 5.14.2 (paid versions starting with version 5.15),MacOS Big Sur version 11.1Above, you can install this packagehttps://d13lb3tujbc8s0.cloudfront.net/onlineinstallers/qt-unified-mac-x64-4.0.0-online.dmg, the choice of5.15Can be

1. Download from the official website

  • You can download the Mac installation package from the official website

  • Download and install step by step

2. Homebrew download

  • Qt is installed via Brew Install, and is finally installed on/usr/local/Cellar/qtDirectory.
brew install qt
Copy the code
  • Install Qt Creator via Brew Install –cask, which is finally installed in the/usr/local/Caskroom/qt-creatorDirectory.
brew install --cask qt-creator
Copy the code

3, configuration,

  • Qt installed via BREW is separate from Qt Creator. You need to set the Qt path in Qt Creator.
  • Open theQT Creatorpreferences

  • findKitsQt Versions, click on theadd

  • Qt’s path is in/usr/localIs hidden by default.
    • You can use shortcut keysCommand + Shift + .Show hidden files and folders
    • You can use shortcut keysCommand + Shift + GManually enter the Qt folder:/usr/local/Cellar/qt

  • You can seeqtThe folder

  • choosebinIn the directoryqmake

  • Then the configurationBuild a suite

Third, the development of

1. New projects

  • After you create the project, look as follows

  • Click on the building

  • Eliminate version warnings intest.proAdd to fileCONFIG+=sdk_no_version_check

2. Integrate FFmpeg into Qt project

  • Integration with FFmpeg requires modification of the. Pro file
INCLUDEPATH + # set header file path = / usr/local/Cellar/ffmpeg4.32./ include # Settings library file path LIBS + = L/usr/local/Cellar/ffmpeg4.32./lib \
        -lavcodec \
        -lavdevice \
        -lavfilter \
        -lavformat \
        -lavutil \
        -lpostproc \
        -lswscale \
        -lswresample \
        -lavresample
Copy the code

  • Print FFmpeg version number in the program
#include "mainwindow.h"

#include <QDebug>

// Ffmpeg is a C library, so extern imports are required
extern "C" {
    #include <libavcodec/avcodec.h>
}

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    qDebug() < <av_version_info(a); }Copy the code

  • QTIt is cross-platform. If you need to import different paths on different platforms, you can also use the following methods

  • Paths can also be extracted and imported

Iv. Development basis

1. Basic use of controls

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    // Set the window title
    setWindowTitle("Main window");

    // Set the window size
    // Windows can be freely scaled by dragging edges
// resize(400, 400);

    // Set the window to a fixed size
    // Windows cannot freely shrink by dragging edges
    setFixedSize(400.400);

    // Set the window position
    // Use the upper-left corner of the parent control as the origin
    // If there is no parent control, use the upper-left corner of the screen as the origin
    move(100.100);
}
Copy the code

2. Add child controls

#include <QPushButton>
 
// Create button
QPushButton *btn = new QPushButton;
// Set the text of the button
btn->setText("Login");
// Sets the parent control to the current window
btn->setParent(this);
// Set the position and size of the button
btn->move(50.50);
btn->resize(100.50);
 
// Create the second button
new QPushButton("Registered".this);
Copy the code

C++ instance object

  • In many languages, instance objects created are stored inHeap memory areaIn the
  • C++, however, can be inThe stack areaStorage instance object
1) The heap stores instance objects
  • Use keywordsnewThe created instance object is stored in the heap
// Create a button in the heap
QPushButton *btn = new QPushButton;
// Set the text of the button
btn->setText("Login");
// Sets the parent control to the current window
btn->setParent(this);
// Set the position and size of the button
btn->move(50.50);
btn->resize(100.50);

// Create the second button
new QPushButton("Registered".this);
Copy the code
2) Stack area stores instance objects
  • inmain.cppIn the file, the code is as follows
#include "mainwindow.h"

#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show(a);return a.exec(a); }Copy the code
  • One of theMainWindow w;This statement creates a stackMainWindowTypew
  • whenmainAt the end of the function,wBe released
  • QApplication a(argc, argv);This sentence is created in the stack areaQApplicationTypea
  • return a.exec();This sentence ismainThe return of the function,a.exec();Will callOperating cycleTo ensuremainThe function doesn’t end, sowWill never be released (will still be released after the program is closed)
3) Instance objects added to the main window cannot be created in the stack
  • There is no advanced memory management in C++ (such as reference counting in OC), which we created inThe stack areaCreate instance variables whenscopeWhen it’s over, they’ll be released

Instance variables created in the heap need to be released manually, but QT already does this for us. When the main window is released, it will automatically release all child controls added to the main window