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 view
FFmpeg
The installation path
which ffmpeg
Copy the code
- Check the file
open /usr/local/bin
Copy the code
- Right click on the
ffmpeg
, click on theAccording to the original body
- You can jump to
ffmpeg
Specific installation position
Homebrew
The installation of theFFmpeg
It’s stored away/usr/local/Cellar/ffmpeg
The installed version is4.3.2
bin
: There are compiled executable programs: ffmpeg, ffplay, etc., which can be used directly on the command line, for exampleffplay xx.mp4
: You can play a video directlyffmpeg -version
: You can view the FFmpeg version number
include
: a header file that needs to be included during developmentlib
: 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 is
Qt
, 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.1
Above, you can install this packagehttps://d13lb3tujbc8s0.cloudfront.net/onlineinstallers/qt-unified-mac-x64-4.0.0-online.dmg
, the choice of5.15
Can 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/qt
Directory.
brew install qt
Copy the code
- Install Qt Creator via Brew Install –cask, which is finally installed in the
/usr/local/Caskroom/qt-creator
Directory.
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 the
QT Creator
的preferences
- find
Kits
的Qt Versions
, click on theadd
- Qt’s path is in
/usr/local
Is hidden by default.- You can use shortcut keys
Command + Shift + .
Show hidden files and folders - You can use shortcut keys
Command + Shift + G
Manually enter the Qt folder:/usr/local/Cellar/qt
- You can use shortcut keys
- You can see
qt
The folder
- choose
bin
In the directoryqmake
- Then the configuration
Build a suite
Third, the development of
1. New projects
- After you create the project, look as follows
- Click on the building
- Eliminate version warnings in
test.pro
Add 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
QT
It 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 in
Heap memory area
In the - C++, however, can be in
The stack area
Storage instance object
1) The heap stores instance objects
- Use keywords
new
The 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
- in
main.cpp
In 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 the
MainWindow w;
This statement creates a stackMainWindow
Typew
- when
main
At the end of the function,w
Be released QApplication a(argc, argv);
This sentence is created in the stack areaQApplication
Typea
return a.exec();
This sentence ismain
The return of the function,a.exec();
Will callOperating cycle
To ensuremain
The function doesn’t end, sow
Will 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 in
The stack area
Create instance variables whenscope
When 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