FFmepg学习笔记(二):QT+FFmpeg 创建第一个工程

运行环境:Ubuntu

本笔记在QT上创建一个工程,验证FFmpeg可以跑通

1、在QT上创建一个工程

2、在pro文件中加入了对应的ffmpeg的lib和include

 1 QT       += core gui
 2 
 3 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
 4 
 5 CONFIG += c++17
 6 
 7 # You can make your code fail to compile if it uses deprecated APIs.
 8 # In order to do so, uncomment the following line.
 9 #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
10 
11 ##ffmpeg
12 FFMPEG_LIB = /usr/local/ffmpeg/lib
13 FFMPEG_INCLUDE = /usr/local/ffmpeg/include
14 
15 SOURCES += \
16     main.cpp \
17     mainwindow.cpp
18 
19 HEADERS += \
20     mainwindow.h
21 
22 FORMS += \
23     mainwindow.ui
24 
25 INCLUDEPATH += $$FFMPEG_INCLUDE \
26 
27 LIBS += $$FFMPEG_LIB/libavcodec.so \
28         $$FFMPEG_LIB/libavdevice.so \
29         $$FFMPEG_LIB/libavfilter.so \
30         $$FFMPEG_LIB/libavformat.so \
31         $$FFMPEG_LIB/libavutil.so \
32         $$FFMPEG_LIB/libswresample.so \
33         $$FFMPEG_LIB/libswscale.so \
34 
35 # Default rules for deployment.
36 qnx: target.path = /tmp/$${TARGET}/bin
37 else: unix:!android: target.path = /opt/$${TARGET}/bin
38 !isEmpty(target.path): INSTALLS += target

3、修改main.cpp文件

 1 extern "C"
 2 {
 3     #include "libavcodec/avcodec.h"
 4     #include "libavformat/avformat.h"
 5     #include "libavutil/pixfmt.h"
 6     #include "libswscale/swscale.h"
 7     #include "libavdevice/avdevice.h"
 8 }
 9 
10 #include "mainwindow.h"
11 #include <QApplication>
12 
13 #include <iostream>
14 
15 using namespace std;
16 
17 int main(int argc, char *argv[])
18 {
19 
20     unsigned int version = avcodec_version();
21     cout<<version<<endl;
22 
23     QApplication a(argc, argv);
24     MainWindow w;
25     w.show();
26     return a.exec();
27 }

4、执行文件,可以从控制台中看到打印的codec version信息

posted @ 2022-06-17 16:36  进击的米豆  阅读(98)  评论(0)    收藏  举报