├── 10.10.3.video_decode_by_cuda_display_by_qml
├── qml.qrc
├── main.cpp
├── nv12render.h
├── 10.10.3.video_decode_by_cuda_display_by_qml.pro
├── videoitem.h
├── ffmpegdecoder.h
├── main.qml
├── videoitem.cpp
├── nv12render.cpp
└── ffmpegdecoder.cpp
├── 10.09.video_decode_by_cpu_display_by_qml
├── qml.qrc
├── main.cpp
├── main.qml
├── i420render.h
├── videoitem.h
├── 10.09.video_decode_by_cpu_display_by_qml.pro
├── ffmpegdecoder.h
├── videoitem.cpp
├── ffmpegdecoder.cpp
└── i420render.cpp
├── H264Parser
├── main.cpp
├── mainwindow.cpp
├── mainwindow.h
├── mainwindow.ui
└── H264Parser.pro
├── RTSParser
├── main.cpp
├── mainwindow.h
├── mainwindow.cpp
├── RTSParser.pro
├── mainwindow.ui
└── rtspdata.h
├── 10.08.1.video_decode_by_cpu_display_by_qopengl
├── main.cpp
├── mainwindow.cpp
├── mainwindow.h
├── i420render2.h
├── i420render.h
├── 10.08.1.video_decode_by_cpu_display_by_qopengl.pro
├── ffmpegdecoder.h
├── mainwindow.ui
├── ffmpegdecoder.cpp
├── i420render2.cpp
└── i420render.cpp
├── 10.08.2.video_decode_by_cpu_display_by_qopengl
├── main.cpp
├── mainwindow.cpp
├── mainwindow.h
├── i420render2.h
├── i420render.h
├── 10.08.2.video_decode_by_cpu_display_by_qopengl.pro
├── ffmpegdecoder.h
├── mainwindow.ui
├── ffmpegdecoder.cpp
├── i420render2.cpp
└── i420render.cpp
├── 10.10.1.video_decode_by_cuda_display_by_qwidget
├── main.cpp
├── mainwindow.h
├── mainwindow.cpp
├── 10.10.1.video_decode_by_cuda_display_by_qwidget.pro
├── mainwindow.ui
└── ffmpegvideo.h
├── 10.10.2.video_decode_by_cuda_display_by_qopengl
├── main.cpp
├── mainwindow.h
├── mainwindow.cpp
├── 10.10.2.video_decode_by_cuda_display_by_qopengl.pro
├── mainwindow.ui
└── ffmpegvideo.h
├── 10.19.audio_video_sync
├── main.cpp
├── mainwindow.h
├── mainwindow.cpp
├── 10.19.audio_video_sync.pro
├── mainwindow.ui
└── ffmpegwidget.h
├── 10.07.video_decode_by_cpu_display_by_qwidget
├── main.cpp
├── mainwindow.h
├── mainwindow.cpp
├── 10.07.video_decode_by_cpu_display_by_qwidget.pro
├── ffmpegwidget.h
├── mainwindow.ui
└── ffmpegwidget.cpp
├── 10.20.video_decode_add_filter_display_by_qwidget
├── main.cpp
├── mainwindow.h
├── 10.20.video_decode_add_filter_display_by_qwidget.pro
├── mainwindow.cpp
├── ffmpegwidget.h
└── mainwindow.ui
├── 10.02.get_lib_version
├── 10.02.get_lib_version.pro
└── main.c
├── 10.03.get_stream_info
├── 10.03.get_stream_info.pro
└── main.c
├── 10.04.video_decode_flow
├── 10.04.video_decode_flow.pro
└── main.c
├── 10.11.video_encode_yuv2h264
└── 10.11.video_encode_yuv2h264.pro
├── 10.12.video_encode_h2642mp4
├── 10.12.video_encode_h2642mp4.pro
└── main.c
├── 10.14.audio_decode_mp32pcm
├── 10.14.audio_decode_mp32pcm.pro
└── main.c
├── 10.18.audio_encode_pcm2mp3
├── 10.18.audio_encode_pcm2mp3.pro
└── main.c
├── 10.05.video_decode_frame_save
├── 10.05.video_decode_frame_save.pro
└── main.c
├── 10.15.audio_decode_swr_mp32pcm
├── 10.15.audio_decode_swr_mp32pcm.pro
└── main.c
├── 10.23.video_muxer_mp3h2642mp4
└── 10.23.video_muxer_mp3h2642mp4.pro
├── 10.21.video_demuxer_mp42h264mp3
└── 10.21.video_demuxer_mp42h264mp3.pro
├── 10.22.video_demuxer_mp42yuvpcm
└── 10.22.video_demuxer_mp42yuvpcm.pro
├── 10.06.1.video_decode_mp42yuv420p
├── 10.06.1.video_decode_mp42yuv420p.pro
└── main.c
├── 10.06.2.video_decode_mp42yuv420sp
├── 10.06.2.video_decode_mp42yuv420sp.pro
└── main.c
├── 10.13.video_encode_camera2h264
└── 10.13.video_encode_camera2h264.pro
├── 10.16.audio_player_decode_by_ffmpeg_play_by_qt
├── 10.16.audio_player_decode_by_ffmpeg_play_by_qt.pro
└── main.cpp
├── 10.17.audio_player_decode_from_mem_play_by_qt
└── 10.17.audio_player_decode_from_mem_play_by_qt.pro
├── .gitignore
├── LICENSE
├── ffmpeg.pro
├── ffmpeg.pri
└── README.md
/10.10.3.video_decode_by_cuda_display_by_qml/qml.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | main.qml
4 |
5 |
6 |
--------------------------------------------------------------------------------
/10.09.video_decode_by_cpu_display_by_qml/qml.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | main.qml
4 |
5 |
6 |
--------------------------------------------------------------------------------
/H264Parser/main.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 |
3 | #include
4 |
5 | int main(int argc, char *argv[])
6 | {
7 | QApplication a(argc, argv);
8 | MainWindow w;
9 | w.show();
10 | return a.exec();
11 | }
12 |
--------------------------------------------------------------------------------
/RTSParser/main.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 |
3 | #include
4 |
5 | int main(int argc, char *argv[])
6 | {
7 | QApplication a(argc, argv);
8 | MainWindow w;
9 | w.show();
10 | return a.exec();
11 | }
12 |
--------------------------------------------------------------------------------
/10.08.1.video_decode_by_cpu_display_by_qopengl/main.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include
3 |
4 | int main(int argc, char *argv[])
5 | {
6 | QApplication a(argc, argv);
7 | MainWindow w;
8 | w.show();
9 |
10 | return a.exec();
11 | }
12 |
--------------------------------------------------------------------------------
/10.08.2.video_decode_by_cpu_display_by_qopengl/main.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include
3 |
4 | int main(int argc, char *argv[])
5 | {
6 | QApplication a(argc, argv);
7 | MainWindow w;
8 | w.show();
9 |
10 | return a.exec();
11 | }
12 |
--------------------------------------------------------------------------------
/10.10.1.video_decode_by_cuda_display_by_qwidget/main.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 |
3 | #include
4 |
5 | int main(int argc, char *argv[])
6 | {
7 | QApplication a(argc, argv);
8 |
9 | MainWindow w;
10 | w.show();
11 |
12 | return a.exec();
13 | }
14 |
--------------------------------------------------------------------------------
/10.10.2.video_decode_by_cuda_display_by_qopengl/main.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 |
3 | #include
4 |
5 | int main(int argc, char *argv[])
6 | {
7 | QApplication a(argc, argv);
8 |
9 | MainWindow w;
10 | w.show();
11 |
12 | return a.exec();
13 | }
14 |
--------------------------------------------------------------------------------
/10.19.audio_video_sync/main.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 |
3 | #include
4 |
5 | int main(int argc, char *argv[])
6 | {
7 | QApplication a(argc, argv);
8 | MainWindow w;
9 | w.setWindowTitle(QObject::tr("Player"));
10 | w.show();
11 |
12 | return a.exec();
13 | }
14 |
--------------------------------------------------------------------------------
/H264Parser/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include "ui_mainwindow.h"
3 |
4 | MainWindow::MainWindow(QWidget *parent)
5 | : QMainWindow(parent)
6 | , ui(new Ui::MainWindow)
7 | {
8 | ui->setupUi(this);
9 | }
10 |
11 | MainWindow::~MainWindow()
12 | {
13 | delete ui;
14 | }
15 |
16 |
--------------------------------------------------------------------------------
/10.07.video_decode_by_cpu_display_by_qwidget/main.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 |
3 | #include
4 |
5 | int main(int argc, char *argv[])
6 | {
7 | QApplication a(argc, argv);
8 | MainWindow w;
9 | w.setWindowTitle(QObject::tr("Player"));
10 | w.show();
11 |
12 | return a.exec();
13 | }
14 |
--------------------------------------------------------------------------------
/10.20.video_decode_add_filter_display_by_qwidget/main.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 |
3 | #include
4 |
5 | int main(int argc, char *argv[])
6 | {
7 | QApplication a(argc, argv);
8 | MainWindow w;
9 | w.setWindowTitle(QObject::tr("Player"));
10 | w.show();
11 |
12 | return a.exec();
13 | }
14 |
--------------------------------------------------------------------------------
/10.02.get_lib_version/10.02.get_lib_version.pro:
--------------------------------------------------------------------------------
1 | TEMPLATE = app
2 | CONFIG += console c++17
3 | CONFIG -= app_bundle
4 | CONFIG -= qt
5 |
6 | include(../ffmpeg.pri)
7 |
8 | DESTDIR = ../bin
9 | TARGET = 3_version
10 | OBJECTS_DIR = obj
11 | MOC_DIR = moc
12 | RCC_DIR = rcc
13 | UI_DIR = ui
14 |
15 | SOURCES += \
16 | main.c
17 |
--------------------------------------------------------------------------------
/10.03.get_stream_info/10.03.get_stream_info.pro:
--------------------------------------------------------------------------------
1 | TEMPLATE = app
2 | CONFIG += console c++17
3 | CONFIG -= app_bundle
4 | CONFIG -= qt
5 |
6 | include(../ffmpeg.pri)
7 |
8 | DESTDIR = ../bin
9 | TARGET = 4_stream_info
10 | OBJECTS_DIR = obj
11 | MOC_DIR = moc
12 | RCC_DIR = rcc
13 | UI_DIR = ui
14 |
15 | SOURCES += \
16 | main.c
17 |
--------------------------------------------------------------------------------
/10.04.video_decode_flow/10.04.video_decode_flow.pro:
--------------------------------------------------------------------------------
1 | TEMPLATE = app
2 | CONFIG += console c++17
3 | CONFIG -= app_bundle
4 | CONFIG -= qt
5 |
6 | include(../ffmpeg.pri)
7 |
8 | DESTDIR = ../bin
9 | TARGET = 5_decode_flow
10 | OBJECTS_DIR = obj
11 | MOC_DIR = moc
12 | RCC_DIR = rcc
13 | UI_DIR = ui
14 |
15 | SOURCES += \
16 | main.c
17 |
--------------------------------------------------------------------------------
/10.11.video_encode_yuv2h264/10.11.video_encode_yuv2h264.pro:
--------------------------------------------------------------------------------
1 | TEMPLATE = app
2 | CONFIG += console c++17
3 | CONFIG -= app_bundle
4 | CONFIG -= qt
5 |
6 | include(../ffmpeg.pri)
7 |
8 | DESTDIR = ../bin
9 | TARGET = 12_encode_yuv2h264
10 | OBJECTS_DIR = obj
11 | MOC_DIR = moc
12 | RCC_DIR = rcc
13 | UI_DIR = ui
14 |
15 | SOURCES += \
16 | main.c
17 |
--------------------------------------------------------------------------------
/10.12.video_encode_h2642mp4/10.12.video_encode_h2642mp4.pro:
--------------------------------------------------------------------------------
1 | TEMPLATE = app
2 | CONFIG += console c++17
3 | CONFIG -= app_bundle
4 | CONFIG -= qt
5 |
6 | include(../ffmpeg.pri)
7 |
8 | DESTDIR = ../bin
9 | TARGET = 13_encode_h2642mp4
10 | OBJECTS_DIR = obj
11 | MOC_DIR = moc
12 | RCC_DIR = rcc
13 | UI_DIR = ui
14 |
15 | SOURCES += \
16 | main.c
17 |
--------------------------------------------------------------------------------
/10.14.audio_decode_mp32pcm/10.14.audio_decode_mp32pcm.pro:
--------------------------------------------------------------------------------
1 | TEMPLATE = app
2 | CONFIG += console c++17
3 | CONFIG -= app_bundle
4 | CONFIG -= qt
5 |
6 | include(../ffmpeg.pri)
7 |
8 | DESTDIR = ../bin
9 | TARGET = 15_decode_mp32pcm
10 | OBJECTS_DIR = obj
11 | MOC_DIR = moc
12 | RCC_DIR = rcc
13 | UI_DIR = ui
14 |
15 | SOURCES += \
16 | main.c
17 |
--------------------------------------------------------------------------------
/10.18.audio_encode_pcm2mp3/10.18.audio_encode_pcm2mp3.pro:
--------------------------------------------------------------------------------
1 | TEMPLATE = app
2 | CONFIG += console c++17
3 | CONFIG -= app_bundle
4 | CONFIG -= qt
5 |
6 | include(../ffmpeg.pri)
7 |
8 | DESTDIR = ../bin
9 | TARGET = 19_encode_pcm2mp3
10 | OBJECTS_DIR = obj
11 | MOC_DIR = moc
12 | RCC_DIR = rcc
13 | UI_DIR = ui
14 |
15 | SOURCES += \
16 | main.c
17 |
--------------------------------------------------------------------------------
/10.05.video_decode_frame_save/10.05.video_decode_frame_save.pro:
--------------------------------------------------------------------------------
1 | TEMPLATE = app
2 | CONFIG += console c++17
3 | CONFIG -= app_bundle
4 | CONFIG -= qt
5 |
6 | include(../ffmpeg.pri)
7 |
8 | DESTDIR = ../bin
9 | TARGET = 6_save_decoded_frame
10 | OBJECTS_DIR = obj
11 | MOC_DIR = moc
12 | RCC_DIR = rcc
13 | UI_DIR = ui
14 |
15 | SOURCES += \
16 | main.c
17 |
--------------------------------------------------------------------------------
/10.15.audio_decode_swr_mp32pcm/10.15.audio_decode_swr_mp32pcm.pro:
--------------------------------------------------------------------------------
1 | TEMPLATE = app
2 | CONFIG += console c++17
3 | CONFIG -= app_bundle
4 | CONFIG -= qt
5 |
6 | include(../ffmpeg.pri)
7 |
8 | DESTDIR = ../bin
9 | TARGET = 16_decode_mp42pcm
10 | OBJECTS_DIR = obj
11 | MOC_DIR = moc
12 | RCC_DIR = rcc
13 | UI_DIR = ui
14 |
15 | SOURCES += \
16 | main.c
17 |
--------------------------------------------------------------------------------
/10.23.video_muxer_mp3h2642mp4/10.23.video_muxer_mp3h2642mp4.pro:
--------------------------------------------------------------------------------
1 | TEMPLATE = app
2 | CONFIG += console c++17
3 | CONFIG -= app_bundle
4 | CONFIG -= qt
5 |
6 | include(../ffmpeg.pri)
7 |
8 | DESTDIR = ../bin
9 | TARGET = 24_muxer_mp3h2642mp4
10 | OBJECTS_DIR = obj
11 | MOC_DIR = moc
12 | RCC_DIR = rcc
13 | UI_DIR = ui
14 |
15 | SOURCES += \
16 | main.c
17 |
--------------------------------------------------------------------------------
/10.21.video_demuxer_mp42h264mp3/10.21.video_demuxer_mp42h264mp3.pro:
--------------------------------------------------------------------------------
1 | TEMPLATE = app
2 | CONFIG += console c++17
3 | CONFIG -= app_bundle
4 | CONFIG -= qt
5 |
6 | include(../ffmpeg.pri)
7 |
8 | DESTDIR = ../bin
9 | TARGET = 22_demuxer_mp42h264mp3
10 | OBJECTS_DIR = obj
11 | MOC_DIR = moc
12 | RCC_DIR = rcc
13 | UI_DIR = ui
14 |
15 | SOURCES += \
16 | main.cpp
17 |
--------------------------------------------------------------------------------
/10.22.video_demuxer_mp42yuvpcm/10.22.video_demuxer_mp42yuvpcm.pro:
--------------------------------------------------------------------------------
1 | TEMPLATE = app
2 | CONFIG += console c++17
3 | CONFIG -= app_bundle
4 | CONFIG -= qt
5 |
6 | include(../ffmpeg.pri)
7 |
8 | DESTDIR = ../bin
9 | TARGET = 23_demuxer_mp42yuvpcm
10 | OBJECTS_DIR = obj
11 | MOC_DIR = moc
12 | RCC_DIR = rcc
13 | UI_DIR = ui
14 |
15 | SOURCES += \
16 | main.cpp
17 |
--------------------------------------------------------------------------------
/10.06.1.video_decode_mp42yuv420p/10.06.1.video_decode_mp42yuv420p.pro:
--------------------------------------------------------------------------------
1 | TEMPLATE = app
2 | CONFIG += console c++17
3 | CONFIG -= app_bundle
4 | CONFIG -= qt
5 |
6 | include(../ffmpeg.pri)
7 |
8 | DESTDIR = ../bin
9 | TARGET = 7_1_decode_mp42yuv420p
10 | OBJECTS_DIR = obj
11 | MOC_DIR = moc
12 | RCC_DIR = rcc
13 | UI_DIR = ui
14 |
15 | SOURCES += \
16 | main.c
17 |
--------------------------------------------------------------------------------
/10.06.2.video_decode_mp42yuv420sp/10.06.2.video_decode_mp42yuv420sp.pro:
--------------------------------------------------------------------------------
1 | TEMPLATE = app
2 | CONFIG += console c++17
3 | CONFIG -= app_bundle
4 | CONFIG -= qt
5 |
6 | include(../ffmpeg.pri)
7 |
8 | DESTDIR = ../bin
9 | TARGET = 7_2_decode_mp42yuv420sp
10 | OBJECTS_DIR = obj
11 | MOC_DIR = moc
12 | RCC_DIR = rcc
13 | UI_DIR = ui
14 |
15 | SOURCES += \
16 | main.c
17 |
--------------------------------------------------------------------------------
/10.13.video_encode_camera2h264/10.13.video_encode_camera2h264.pro:
--------------------------------------------------------------------------------
1 | TEMPLATE = app
2 | CONFIG += console c++17
3 | CONFIG -= app_bundle
4 | CONFIG -= qt
5 |
6 | include(../ffmpeg.pri)
7 |
8 | DESTDIR = ../bin
9 | TARGET = 14_camera2h264
10 | OBJECTS_DIR = obj
11 | MOC_DIR = moc
12 | RCC_DIR = rcc
13 | UI_DIR = ui
14 |
15 |
16 | SOURCES += \
17 | main.c
18 |
--------------------------------------------------------------------------------
/10.16.audio_player_decode_by_ffmpeg_play_by_qt/10.16.audio_player_decode_by_ffmpeg_play_by_qt.pro:
--------------------------------------------------------------------------------
1 | QT += core multimedia testlib
2 |
3 | TEMPLATE = app
4 | CONFIG += console c++17
5 | CONFIG -= app_bundle
6 |
7 | include(../ffmpeg.pri)
8 |
9 | DESTDIR = ../bin
10 | TARGET = 17_audio_decode
11 | OBJECTS_DIR = obj
12 | MOC_DIR = moc
13 | RCC_DIR = rcc
14 | UI_DIR = ui
15 |
16 | SOURCES += \
17 | main.cpp
18 |
--------------------------------------------------------------------------------
/H264Parser/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 |
6 | QT_BEGIN_NAMESPACE
7 | namespace Ui { class MainWindow; }
8 | QT_END_NAMESPACE
9 |
10 | class MainWindow : public QMainWindow
11 | {
12 | Q_OBJECT
13 |
14 | public:
15 | MainWindow(QWidget *parent = nullptr);
16 | ~MainWindow();
17 |
18 | private:
19 | Ui::MainWindow *ui;
20 | };
21 | #endif // MAINWINDOW_H
22 |
--------------------------------------------------------------------------------
/10.08.1.video_decode_by_cpu_display_by_qopengl/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include "ui_mainwindow.h"
3 |
4 | MainWindow::MainWindow(QWidget *parent) :
5 | QMainWindow(parent),
6 | ui(new Ui::MainWindow)
7 | {
8 | ui->setupUi(this);
9 | }
10 |
11 | MainWindow::~MainWindow()
12 | {
13 | delete ui;
14 | }
15 |
16 | void MainWindow::on_btnPlay_clicked()
17 | {
18 | ui->openGLWidget->setUrl(ui->lineUrl->text());
19 | ui->openGLWidget->startVideo();
20 | }
21 |
--------------------------------------------------------------------------------
/10.08.2.video_decode_by_cpu_display_by_qopengl/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include "ui_mainwindow.h"
3 |
4 | MainWindow::MainWindow(QWidget *parent) :
5 | QMainWindow(parent),
6 | ui(new Ui::MainWindow)
7 | {
8 | ui->setupUi(this);
9 | }
10 |
11 | MainWindow::~MainWindow()
12 | {
13 | delete ui;
14 | }
15 |
16 | void MainWindow::on_btnPlay_clicked()
17 | {
18 | ui->openGLWidget->setUrl(ui->lineUrl->text());
19 | ui->openGLWidget->startVideo();
20 | }
21 |
--------------------------------------------------------------------------------
/10.08.1.video_decode_by_cpu_display_by_qopengl/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 |
6 | namespace Ui {
7 | class MainWindow;
8 | }
9 |
10 | class MainWindow : public QMainWindow
11 | {
12 | Q_OBJECT
13 |
14 | public:
15 | explicit MainWindow(QWidget *parent = 0);
16 | ~MainWindow();
17 |
18 | private slots:
19 | void on_btnPlay_clicked();
20 |
21 | private:
22 | Ui::MainWindow *ui;
23 | };
24 |
25 | #endif // MAINWINDOW_H
26 |
--------------------------------------------------------------------------------
/10.08.2.video_decode_by_cpu_display_by_qopengl/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 |
6 | namespace Ui {
7 | class MainWindow;
8 | }
9 |
10 | class MainWindow : public QMainWindow
11 | {
12 | Q_OBJECT
13 |
14 | public:
15 | explicit MainWindow(QWidget *parent = 0);
16 | ~MainWindow();
17 |
18 | private slots:
19 | void on_btnPlay_clicked();
20 |
21 | private:
22 | Ui::MainWindow *ui;
23 | };
24 |
25 | #endif // MAINWINDOW_H
26 |
--------------------------------------------------------------------------------
/10.19.audio_video_sync/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 |
6 | QT_BEGIN_NAMESPACE
7 | namespace Ui { class MainWindow; }
8 | QT_END_NAMESPACE
9 |
10 | class MainWindow : public QMainWindow
11 | {
12 | Q_OBJECT
13 |
14 | public:
15 | MainWindow(QWidget *parent = nullptr);
16 | ~MainWindow();
17 |
18 | private slots:
19 | void on_btnPlay_clicked();
20 |
21 | void on_btnStop_clicked();
22 |
23 | private:
24 | Ui::MainWindow *ui;
25 | };
26 | #endif // MAINWINDOW_H
27 |
--------------------------------------------------------------------------------
/10.19.audio_video_sync/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include "ui_mainwindow.h"
3 |
4 | MainWindow::MainWindow(QWidget *parent)
5 | : QMainWindow(parent)
6 | , ui(new Ui::MainWindow)
7 | {
8 | ui->setupUi(this);
9 | }
10 |
11 | MainWindow::~MainWindow()
12 | {
13 | delete ui;
14 | }
15 |
16 |
17 | void MainWindow::on_btnPlay_clicked()
18 | {
19 | ui->wgtPlayer->setUrl(ui->lineUrl->text());
20 | ui->wgtPlayer->play();
21 | }
22 |
23 | void MainWindow::on_btnStop_clicked()
24 | {
25 | ui->wgtPlayer->stop();
26 | }
27 |
--------------------------------------------------------------------------------
/RTSParser/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 |
6 | #include "rtspdata.h"
7 |
8 | QT_BEGIN_NAMESPACE
9 | namespace Ui { class MainWindow; }
10 | QT_END_NAMESPACE
11 |
12 | class MainWindow : public QMainWindow
13 | {
14 | Q_OBJECT
15 |
16 | public:
17 | MainWindow(QWidget *parent = nullptr);
18 | ~MainWindow();
19 |
20 | private slots:
21 | void on_btnRun_clicked();
22 |
23 | private:
24 | Ui::MainWindow *ui;
25 |
26 | RTSPData *rtsp;
27 | };
28 | #endif // MAINWINDOW_H
29 |
--------------------------------------------------------------------------------
/10.07.video_decode_by_cpu_display_by_qwidget/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 |
6 | QT_BEGIN_NAMESPACE
7 | namespace Ui { class MainWindow; }
8 | QT_END_NAMESPACE
9 |
10 | class MainWindow : public QMainWindow
11 | {
12 | Q_OBJECT
13 |
14 | public:
15 | MainWindow(QWidget *parent = nullptr);
16 | ~MainWindow();
17 |
18 | private slots:
19 | void on_btnPlay_clicked();
20 |
21 | void on_btnStop_clicked();
22 |
23 | private:
24 | Ui::MainWindow *ui;
25 | };
26 | #endif // MAINWINDOW_H
27 |
--------------------------------------------------------------------------------
/10.07.video_decode_by_cpu_display_by_qwidget/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include "ui_mainwindow.h"
3 |
4 | MainWindow::MainWindow(QWidget *parent)
5 | : QMainWindow(parent)
6 | , ui(new Ui::MainWindow)
7 | {
8 | ui->setupUi(this);
9 | }
10 |
11 | MainWindow::~MainWindow()
12 | {
13 | delete ui;
14 | }
15 |
16 |
17 | void MainWindow::on_btnPlay_clicked()
18 | {
19 | ui->wgtPlayer->setUrl(ui->lineUrl->text());
20 | ui->wgtPlayer->play();
21 | }
22 |
23 | void MainWindow::on_btnStop_clicked()
24 | {
25 | ui->wgtPlayer->stop();
26 | }
27 |
--------------------------------------------------------------------------------
/10.10.3.video_decode_by_cuda_display_by_qml/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | #include "videoitem.h"
5 |
6 | int main(int argc, char *argv[])
7 | {
8 | QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
9 |
10 | QGuiApplication app(argc, argv);
11 |
12 | QQmlApplicationEngine engine;
13 |
14 | qmlRegisterType("VideoItem",1,0,"VideoItem");
15 |
16 | engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
17 | if (engine.rootObjects().isEmpty())
18 | return -1;
19 |
20 | return app.exec();
21 | }
22 |
--------------------------------------------------------------------------------
/10.09.video_decode_by_cpu_display_by_qml/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | #include "videoitem.h"
5 |
6 | int main(int argc, char *argv[])
7 | {
8 | QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
9 |
10 | QGuiApplication app(argc, argv);
11 |
12 | qmlRegisterType("VideoItem",1,0,"VideoItem");
13 |
14 | QQmlApplicationEngine engine;
15 | engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
16 | if (engine.rootObjects().isEmpty())
17 | return -1;
18 |
19 | return app.exec();
20 | }
21 |
--------------------------------------------------------------------------------
/10.10.1.video_decode_by_cuda_display_by_qwidget/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 | #include
6 |
7 | QT_BEGIN_NAMESPACE
8 | namespace Ui { class MainWindow; }
9 | QT_END_NAMESPACE
10 |
11 | class MainWindow : public QMainWindow
12 | {
13 | Q_OBJECT
14 |
15 | public:
16 | MainWindow(QWidget *parent = nullptr);
17 | ~MainWindow();
18 |
19 | private slots:
20 | void on_btnPS_clicked();
21 |
22 | private:
23 | Ui::MainWindow *ui;
24 |
25 | bool isPlay=false;
26 | };
27 | #endif // MAINWINDOW_H
28 |
--------------------------------------------------------------------------------
/10.10.2.video_decode_by_cuda_display_by_qopengl/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 | #include
6 |
7 | QT_BEGIN_NAMESPACE
8 | namespace Ui { class MainWindow; }
9 | QT_END_NAMESPACE
10 |
11 | class MainWindow : public QMainWindow
12 | {
13 | Q_OBJECT
14 |
15 | public:
16 | MainWindow(QWidget *parent = nullptr);
17 | ~MainWindow();
18 |
19 | private slots:
20 | void on_btnPS_clicked();
21 |
22 | private:
23 | Ui::MainWindow *ui;
24 |
25 | bool isPlay=false;
26 | };
27 | #endif // MAINWINDOW_H
28 |
--------------------------------------------------------------------------------
/RTSParser/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include "ui_mainwindow.h"
3 |
4 | MainWindow::MainWindow(QWidget *parent)
5 | : QMainWindow(parent)
6 | , ui(new Ui::MainWindow)
7 | , rtsp(new RTSPData)
8 | {
9 | ui->setupUi(this);
10 | }
11 |
12 | MainWindow::~MainWindow()
13 | {
14 | if(rtsp->isRunning()){
15 | rtsp->requestInterruption();
16 | rtsp->quit();
17 | rtsp->deleteLater();
18 | }
19 | delete ui;
20 | }
21 |
22 |
23 | void MainWindow::on_btnRun_clicked()
24 | {
25 | rtsp->rtspInit("rtsp://192.168.1.31/test");
26 | rtsp->start();
27 | }
28 |
29 |
--------------------------------------------------------------------------------
/H264Parser/mainwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 800
10 | 600
11 |
12 |
13 |
14 | MainWindow
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/10.10.1.video_decode_by_cuda_display_by_qwidget/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include "ui_mainwindow.h"
3 |
4 | MainWindow::MainWindow(QWidget *parent)
5 | : QMainWindow(parent)
6 | , ui(new Ui::MainWindow)
7 | {
8 | ui->setupUi(this);
9 | }
10 |
11 | MainWindow::~MainWindow()
12 | {
13 | delete ui;
14 | }
15 |
16 | void MainWindow::on_btnPS_clicked()
17 | {
18 | QString url = ui->lineUrl->text().trimmed();
19 | if(url.isEmpty()){
20 | QMessageBox::information(this,tr("Warning"),"Please input url",QMessageBox::Ok);
21 | return;
22 | }
23 | ui->widget->play(url);
24 | }
25 |
--------------------------------------------------------------------------------
/10.10.2.video_decode_by_cuda_display_by_qopengl/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include "ui_mainwindow.h"
3 |
4 | MainWindow::MainWindow(QWidget *parent)
5 | : QMainWindow(parent)
6 | , ui(new Ui::MainWindow)
7 | {
8 | ui->setupUi(this);
9 | }
10 |
11 | MainWindow::~MainWindow()
12 | {
13 | delete ui;
14 | }
15 |
16 | void MainWindow::on_btnPS_clicked()
17 | {
18 | QString url = ui->lineUrl->text().trimmed();
19 | if(url.isEmpty()){
20 | QMessageBox::information(this,tr("Warning"),"Please input url",QMessageBox::Ok);
21 | return;
22 | }
23 | ui->widget->play(url);
24 | }
25 |
--------------------------------------------------------------------------------
/10.17.audio_player_decode_from_mem_play_by_qt/10.17.audio_player_decode_from_mem_play_by_qt.pro:
--------------------------------------------------------------------------------
1 | QT -= gui
2 | QT += sql multimedia
3 |
4 | CONFIG += c++17 console
5 | CONFIG -= app_bundle
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 | include(../ffmpeg.pri)
12 |
13 | DESTDIR = ../bin
14 | TARGET = 18_decode_from_mem
15 | OBJECTS_DIR = obj
16 | MOC_DIR = moc
17 | RCC_DIR = rcc
18 | UI_DIR = ui
19 |
20 | SOURCES += \
21 | main.cpp
22 |
--------------------------------------------------------------------------------
/10.09.video_decode_by_cpu_display_by_qml/main.qml:
--------------------------------------------------------------------------------
1 | import QtQuick 2.9
2 | import QtQuick.Window 2.2
3 | import QtQuick.Controls 2.3
4 |
5 | import VideoItem 1.0
6 |
7 | Window {
8 | visible: true
9 | width: 1280
10 | height: 720
11 | title: qsTr("Hello World")
12 |
13 | VideoItem{
14 | id:videoitem
15 | anchors.fill: parent
16 | }
17 |
18 | Button {
19 | id: button
20 | x: 29
21 | y: 27
22 | text: qsTr("Play")
23 |
24 | onClicked: {
25 | videoitem.setUrl("C:\\Users\\hyper\\Videos\\Sample.wmv")
26 | videoitem.start()
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/H264Parser/H264Parser.pro:
--------------------------------------------------------------------------------
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 | SOURCES += \
12 | main.cpp \
13 | mainwindow.cpp
14 |
15 | HEADERS += \
16 | mainwindow.h
17 |
18 | FORMS += \
19 | mainwindow.ui
20 |
21 | # Default rules for deployment.
22 | qnx: target.path = /tmp/$${TARGET}/bin
23 | else: unix:!android: target.path = /opt/$${TARGET}/bin
24 | !isEmpty(target.path): INSTALLS += target
25 |
--------------------------------------------------------------------------------
/10.20.video_decode_add_filter_display_by_qwidget/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 | #include
6 |
7 | QT_BEGIN_NAMESPACE
8 | namespace Ui { class MainWindow; }
9 | QT_END_NAMESPACE
10 |
11 | class MainWindow : public QMainWindow
12 | {
13 | Q_OBJECT
14 |
15 | public:
16 | MainWindow(QWidget *parent = nullptr);
17 | ~MainWindow();
18 |
19 | private slots:
20 | void on_btnPlay_clicked();
21 |
22 | void on_btnStop_clicked();
23 |
24 | void on_spinBoxContrast_valueChanged(int c);
25 |
26 | void on_spinBoxLightness_valueChanged(int b);
27 |
28 | private:
29 | Ui::MainWindow *ui;
30 |
31 | int contrast=5,brightness=5;
32 | };
33 | #endif // MAINWINDOW_H
34 |
--------------------------------------------------------------------------------
/10.02.get_lib_version/main.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include "libavcodec/avcodec.h"
4 | #include "libavfilter/avfilter.h"
5 | #include "libavformat/avformat.h"
6 | #include "libavutil/avutil.h"
7 | #include "libavutil/ffversion.h"
8 | #include "libswresample/swresample.h"
9 | #include "libswscale/swscale.h"
10 | #include "libpostproc/postprocess.h"
11 |
12 | int main()
13 | {
14 | unsigned codecVer = avcodec_version();
15 | int ver_major,ver_minor,ver_micro;
16 | ver_major = (codecVer>>16)&0xff;
17 | ver_minor = (codecVer>>8)&0xff;
18 | ver_micro = (codecVer)&0xff;
19 | printf("FFmpeg version is: %s .\navcodec version is: %d=%d.%d.%d.\n",
20 | FFMPEG_VERSION,
21 | codecVer,ver_major,ver_minor,ver_micro);
22 |
23 | return 0;
24 | }
25 |
--------------------------------------------------------------------------------
/10.20.video_decode_add_filter_display_by_qwidget/10.20.video_decode_add_filter_display_by_qwidget.pro:
--------------------------------------------------------------------------------
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 | include(../ffmpeg.pri)
12 |
13 | DESTDIR = ../bin
14 | TARGET = 21_filter
15 | OBJECTS_DIR = obj
16 | MOC_DIR = moc
17 | RCC_DIR = rcc
18 | UI_DIR = ui
19 |
20 | SOURCES += \
21 | ffmpegwidget.cpp \
22 | main.cpp \
23 | mainwindow.cpp
24 |
25 | HEADERS += \
26 | ffmpegwidget.h \
27 | mainwindow.h
28 |
29 | FORMS += \
30 | mainwindow.ui
31 |
--------------------------------------------------------------------------------
/10.10.3.video_decode_by_cuda_display_by_qml/nv12render.h:
--------------------------------------------------------------------------------
1 | #ifndef NV12RENDER_H
2 | #define NV12RENDER_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | class NV12Render : public QOpenGLFunctions
12 | {
13 | public:
14 | ///
15 | /// \brief NV12Render 构造函数
16 | ///
17 | NV12Render();
18 |
19 | ///
20 | /// \brief render 渲染绘制纹理
21 | /// \param p 纹理数据指针
22 | /// \param width 纹理图片的宽度
23 | /// \param height 纹理图片的高度
24 | ///
25 | void render(uchar *p, int width, int height);
26 |
27 | private:
28 | QOpenGLShaderProgram program;//着色程序对象
29 | GLuint idY,idUV;//纹理分量ID
30 | QOpenGLBuffer vbo;//纹理buffer
31 | };
32 |
33 | #endif // NV12RENDER_H
34 |
--------------------------------------------------------------------------------
/RTSParser/RTSParser.pro:
--------------------------------------------------------------------------------
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 | TARGET=rtsparser
12 | OBJECTS_DIR=obj
13 | MOC_DIR=moc
14 | RCC_DIR=rcc
15 | UI_DIR=ui
16 |
17 | SOURCES += \
18 | main.cpp \
19 | mainwindow.cpp \
20 | rtspdata.cpp
21 |
22 | HEADERS += \
23 | mainwindow.h \
24 | rtspdata.h
25 |
26 | FORMS += \
27 | mainwindow.ui
28 |
29 | # Default rules for deployment.
30 | qnx: target.path = /tmp/$${TARGET}/bin
31 | else: unix:!android: target.path = /opt/$${TARGET}/bin
32 | !isEmpty(target.path): INSTALLS += target
33 |
--------------------------------------------------------------------------------
/10.10.1.video_decode_by_cuda_display_by_qwidget/10.10.1.video_decode_by_cuda_display_by_qwidget.pro:
--------------------------------------------------------------------------------
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 | include(../ffmpeg.pri)
12 |
13 | DESTDIR = ../bin
14 | TARGET = 11_1_decode_by_cuda_qwidget
15 | OBJECTS_DIR = obj
16 | MOC_DIR = moc
17 | RCC_DIR = rcc
18 | UI_DIR = ui
19 |
20 | SOURCES += \
21 | ffmpegvideo.cpp \
22 | main.cpp \
23 | mainwindow.cpp
24 |
25 | HEADERS += \
26 | ffmpegvideo.h \
27 | mainwindow.h
28 |
29 | FORMS += \
30 | mainwindow.ui
31 |
--------------------------------------------------------------------------------
/10.10.2.video_decode_by_cuda_display_by_qopengl/10.10.2.video_decode_by_cuda_display_by_qopengl.pro:
--------------------------------------------------------------------------------
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 | include(../ffmpeg.pri)
12 |
13 | DESTDIR = ../bin
14 | TARGET = 11_2_decode_by_cuda_qopengl
15 | OBJECTS_DIR = obj
16 | MOC_DIR = moc
17 | RCC_DIR = rcc
18 | UI_DIR = ui
19 |
20 | SOURCES += \
21 | ffmpegvideo.cpp \
22 | main.cpp \
23 | mainwindow.cpp
24 |
25 | HEADERS += \
26 | ffmpegvideo.h \
27 | mainwindow.h
28 |
29 | FORMS += \
30 | mainwindow.ui
31 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # C++ objects and libs
2 | *.slo
3 | *.lo
4 | *.o
5 | *.a
6 | *.la
7 | *.lai
8 | *.so
9 | *.so.*
10 | *.dll
11 | *.dylib
12 |
13 | # Qt-es
14 | object_script.*.Release
15 | object_script.*.Debug
16 | *_plugin_import.cpp
17 | /.qmake.cache
18 | /.qmake.stash
19 | *.pro.user
20 | *.pro.user.*
21 | *.qbs.user
22 | *.qbs.user.*
23 | *.moc
24 | moc_*.cpp
25 | moc_*.h
26 | qrc_*.cpp
27 | ui_*.h
28 | *.qmlc
29 | *.jsc
30 | Makefile*
31 | *build-*
32 | *.qm
33 | *.prl
34 |
35 | # Qt unit tests
36 | target_wrapper.*
37 |
38 | # QtCreator
39 | *.autosave
40 |
41 | # QtCreator Qml
42 | *.qmlproject.user
43 | *.qmlproject.user.*
44 |
45 | # QtCreator CMake
46 | CMakeLists.txt.user*
47 |
48 | # QtCreator 4.8< compilation database
49 | compile_commands.json
50 |
51 | # QtCreator local machine specific files for imported projects
52 | *creator.user*
53 |
54 |
55 | temp
56 | .qmake.stash
57 | lib
58 |
--------------------------------------------------------------------------------
/10.08.1.video_decode_by_cpu_display_by_qopengl/i420render2.h:
--------------------------------------------------------------------------------
1 | #ifndef I420RENDER2_H
2 | #define I420RENDER2_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | #include "ffmpegdecoder.h"
12 |
13 | class I420Render2 : public QOpenGLWidget,public QOpenGLFunctions
14 | {
15 | Q_OBJECT
16 | public:
17 | I420Render2(QWidget *parent =nullptr);
18 | ~I420Render2();
19 |
20 | void setUrl(QString url);
21 |
22 | void startVideo();
23 |
24 | void initializeGL();
25 | void resizeGL(int w,int h);
26 | void paintGL();
27 |
28 | private:
29 | //shader程序
30 | QOpenGLShaderProgram m_program;
31 | QOpenGLBuffer vbo;
32 |
33 | int idY,idU,idV;
34 |
35 | int width,height;
36 |
37 | FFmpegDecoder *decoder;
38 |
39 | uchar* ptr;
40 | };
41 |
42 | #endif // I420RENDER2_H
43 |
--------------------------------------------------------------------------------
/10.08.2.video_decode_by_cpu_display_by_qopengl/i420render2.h:
--------------------------------------------------------------------------------
1 | #ifndef I420RENDER2_H
2 | #define I420RENDER2_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | #include "ffmpegdecoder.h"
12 |
13 | class I420Render2 : public QOpenGLWidget,public QOpenGLFunctions
14 | {
15 | Q_OBJECT
16 | public:
17 | I420Render2(QWidget *parent =nullptr);
18 | ~I420Render2();
19 |
20 | void setUrl(QString url);
21 |
22 | void startVideo();
23 |
24 | void initializeGL();
25 | void resizeGL(int w,int h);
26 | void paintGL();
27 |
28 | private:
29 | //shader程序
30 | QOpenGLShaderProgram m_program;
31 | QOpenGLBuffer vbo;
32 |
33 | int idY,idU,idV;
34 |
35 | int width,height;
36 |
37 | FFmpegDecoder *decoder;
38 |
39 | uchar* ptr;
40 | };
41 |
42 | #endif // I420RENDER2_H
43 |
--------------------------------------------------------------------------------
/10.09.video_decode_by_cpu_display_by_qml/i420render.h:
--------------------------------------------------------------------------------
1 | #ifndef I420RENDER2_H
2 | #define I420RENDER2_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | #include
12 |
13 | #include "ffmpegdecoder.h"
14 |
15 | class I420Render : public QOpenGLFunctions
16 | {
17 | public:
18 | I420Render();
19 | ~I420Render();
20 |
21 | void init();
22 | void updateTextureInfo(int w, int h);
23 | void updateTextureData(const YUVData &data);
24 | void paint();
25 | void resize(int w, int h);
26 |
27 | private:
28 | //shader程序
29 | QOpenGLShaderProgram m_program;
30 | QOpenGLTexture *mTexY = nullptr,*mTexU=nullptr,*mTexV=nullptr;
31 |
32 | bool mTextureAlloced = false;
33 |
34 | QVector vertices;
35 | QVector textures;
36 | };
37 |
38 | #endif // I420RENDER2_H
39 |
--------------------------------------------------------------------------------
/10.20.video_decode_add_filter_display_by_qwidget/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include "ui_mainwindow.h"
3 |
4 | MainWindow::MainWindow(QWidget *parent)
5 | : QMainWindow(parent)
6 | , ui(new Ui::MainWindow)
7 | {
8 | ui->setupUi(this);
9 | }
10 |
11 | MainWindow::~MainWindow()
12 | {
13 | delete ui;
14 | }
15 |
16 |
17 | void MainWindow::on_btnPlay_clicked()
18 | {
19 | QString url = ui->lineUrl->text();
20 | if(url.isEmpty()){
21 | QMessageBox::information(this,tr("Warning"),"Please input url first.",QMessageBox::Ok);
22 | return;
23 | }
24 | ui->wgtPlayer->play(url);
25 | }
26 |
27 | void MainWindow::on_btnStop_clicked()
28 | {
29 | ui->wgtPlayer->stop();
30 | }
31 |
32 | void MainWindow::on_spinBoxContrast_valueChanged(int c)
33 | {
34 | contrast=c;
35 | ui->wgtPlayer->setFilterDescr(c,brightness);
36 | }
37 |
38 | void MainWindow::on_spinBoxLightness_valueChanged(int b)
39 | {
40 | brightness=b;
41 | ui->wgtPlayer->setFilterDescr(contrast,b);
42 | }
43 |
--------------------------------------------------------------------------------
/10.03.get_stream_info/main.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include "libavcodec/avcodec.h"
4 | #include "libavfilter/avfilter.h"
5 | #include "libavformat/avformat.h"
6 | #include "libavutil/avutil.h"
7 | #include "libavutil/ffversion.h"
8 | #include "libswresample/swresample.h"
9 | #include "libswscale/swscale.h"
10 | #include "libpostproc/postprocess.h"
11 |
12 | int main()
13 | {
14 | AVFormatContext *fmt_ctx = avformat_alloc_context();//创建对象并初始化
15 | int ret=0;
16 | char* fileName="C:\\Users\\hyper\\Videos\\Sample.wmv";//文件地址
17 |
18 | do{
19 | //打开文件
20 | if ((ret = avformat_open_input(&fmt_ctx, fileName, NULL, NULL))<0)
21 | break;//Cannot open video file
22 |
23 | //查找流信息(音频流和视频流)
24 | if ((ret = avformat_find_stream_info(fmt_ctx, NULL)) < 0) {
25 | printf("Cannot find stream information\n");
26 | break;
27 | }
28 |
29 | av_dump_format(fmt_ctx,0,fileName,0);//输出视频信息
30 | }while(0);
31 |
32 | avformat_close_input(&fmt_ctx);//关闭文件
33 |
34 | return ret;
35 | }
36 |
--------------------------------------------------------------------------------
/10.08.1.video_decode_by_cpu_display_by_qopengl/i420render.h:
--------------------------------------------------------------------------------
1 | #ifndef I420RENDER_H
2 | #define I420RENDER_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | #include "ffmpegdecoder.h"
12 |
13 | class I420Render : public QOpenGLWidget,public QOpenGLFunctions
14 | {
15 | Q_OBJECT
16 | public:
17 | I420Render(QWidget *parent =nullptr);
18 | ~I420Render();
19 |
20 | void setUrl(QString url);
21 |
22 | void startVideo();
23 |
24 | void initializeGL();
25 | void resizeGL(int w,int h);
26 | void paintGL();
27 |
28 | private:
29 | //shader程序
30 | QOpenGLShaderProgram m_program;
31 | //shader中yuv变量地址
32 | GLuint m_textureUniformY, m_textureUniformU , m_textureUniformV;
33 | //创建纹理
34 | GLuint m_idy , m_idu , m_idv;
35 |
36 | int width,height;
37 |
38 | FFmpegDecoder *decoder;
39 |
40 | uchar* ptr;
41 | };
42 |
43 | #endif // I420RENDER_H
44 |
--------------------------------------------------------------------------------
/10.08.2.video_decode_by_cpu_display_by_qopengl/i420render.h:
--------------------------------------------------------------------------------
1 | #ifndef I420RENDER_H
2 | #define I420RENDER_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | #include "ffmpegdecoder.h"
12 |
13 | class I420Render : public QOpenGLWidget,public QOpenGLFunctions
14 | {
15 | Q_OBJECT
16 | public:
17 | I420Render(QWidget *parent =nullptr);
18 | ~I420Render();
19 |
20 | void setUrl(QString url);
21 |
22 | void startVideo();
23 |
24 | void initializeGL();
25 | void resizeGL(int w,int h);
26 | void paintGL();
27 |
28 | private:
29 | //shader程序
30 | QOpenGLShaderProgram m_program;
31 | //shader中yuv变量地址
32 | GLuint m_textureUniformY, m_textureUniformU , m_textureUniformV;
33 | //创建纹理
34 | GLuint m_idy , m_idu , m_idv;
35 |
36 | int width,height;
37 |
38 | FFmpegDecoder *decoder;
39 |
40 | uchar* ptr;
41 | };
42 |
43 | #endif // I420RENDER_H
44 |
--------------------------------------------------------------------------------
/10.10.3.video_decode_by_cuda_display_by_qml/10.10.3.video_decode_by_cuda_display_by_qml.pro:
--------------------------------------------------------------------------------
1 | QT += quick qml quickwidgets multimedia gui opengl
2 |
3 | CONFIG += c++17
4 |
5 | # You can make your code fail to compile if it uses deprecated APIs.
6 | # In order to do so, uncomment the following line.
7 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
8 |
9 | include(../ffmpeg.pri)
10 |
11 | DESTDIR = ../bin
12 | TARGET = 11_3_decode_by_cuda_qml
13 | OBJECTS_DIR = obj
14 | MOC_DIR = moc
15 | RCC_DIR = rcc
16 | UI_DIR = ui
17 |
18 | HEADERS += \
19 | ffmpegdecoder.h \
20 | nv12render.h \
21 | videoitem.h
22 |
23 |
24 | SOURCES += \
25 | ffmpegdecoder.cpp \
26 | main.cpp \
27 | nv12render.cpp \
28 | videoitem.cpp
29 |
30 | RESOURCES += qml.qrc
31 |
32 | # Additional import path used to resolve QML modules in Qt Creator's code model
33 | QML_IMPORT_PATH =
34 |
35 | # Additional import path used to resolve QML modules just for Qt Quick Designer
36 | QML_DESIGNER_IMPORT_PATH =
37 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 JackeyLea
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/RTSParser/mainwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 800
10 | 600
11 |
12 |
13 |
14 | MainWindow
15 |
16 |
17 |
18 |
19 |
20 | 100
21 | 130
22 | 84
23 | 27
24 |
25 |
26 |
27 | run
28 |
29 |
30 |
31 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/10.19.audio_video_sync/10.19.audio_video_sync.pro:
--------------------------------------------------------------------------------
1 | QT += core gui multimedia testlib
2 |
3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
4 |
5 | CONFIG += c++17
6 |
7 | # The following define makes your compiler emit warnings if you use
8 | # any Qt feature that has been marked deprecated (the exact warnings
9 | # depend on your compiler). Please consult the documentation of the
10 | # deprecated API in order to know how to port your code away from it.
11 | DEFINES += QT_DEPRECATED_WARNINGS
12 |
13 | # You can also make your code fail to compile if it uses deprecated APIs.
14 | # In order to do so, uncomment the following line.
15 | # You can also select to disable deprecated APIs only up to a certain version of Qt.
16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
17 |
18 | include(../ffmpeg.pri)
19 |
20 | DESTDIR = ../bin
21 | TARGET = 20_sync
22 | OBJECTS_DIR = obj
23 | MOC_DIR = moc
24 | RCC_DIR = rcc
25 | UI_DIR = ui
26 |
27 | SOURCES += \
28 | ffmpegwidget.cpp \
29 | main.cpp \
30 | mainwindow.cpp
31 |
32 | HEADERS += \
33 | ffmpegwidget.h \
34 | mainwindow.h
35 |
36 | FORMS += \
37 | mainwindow.ui
38 |
--------------------------------------------------------------------------------
/10.09.video_decode_by_cpu_display_by_qml/videoitem.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include "ffmpegdecoder.h"
7 |
8 | class VideoItem : public QQuickFramebufferObject
9 | {
10 | Q_OBJECT
11 | public:
12 | VideoItem(QQuickItem *parent = nullptr);
13 | void timerEvent(QTimerEvent *) override;
14 |
15 | YUVData getFrame();
16 | bool infoDirty() const
17 | {
18 | return m_infoChanged;
19 | }
20 | void makeInfoDirty(bool dirty)
21 | {
22 | m_infoChanged = dirty;
23 | }
24 | int videoWidth() const
25 | {
26 | return m_videoWidth;
27 | }
28 | int videoHeght() const
29 | {
30 | return m_videoHeight;
31 | }
32 | public slots:
33 | void setUrl(const QString &url);
34 | void start();
35 | void stop();
36 |
37 | protected slots:
38 | void onVideoInfoReady(int width, int height);
39 | public:
40 | Renderer *createRenderer() const override;
41 |
42 | FFmpegDecoder *m_decoder = nullptr;
43 |
44 | int m_videoWidth;
45 | int m_videoHeight;
46 | bool m_infoChanged = false;
47 | };
48 |
49 |
--------------------------------------------------------------------------------
/10.07.video_decode_by_cpu_display_by_qwidget/10.07.video_decode_by_cpu_display_by_qwidget.pro:
--------------------------------------------------------------------------------
1 | QT += core gui
2 |
3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
4 |
5 | CONFIG += c++17
6 |
7 | include(../ffmpeg.pri)
8 |
9 | DESTDIR = ../bin
10 | TEMPLATE = app
11 | TARGET = 8_decode_qwidget
12 | OBJECTS_DIR = obj
13 | MOC_DIR = moc
14 | RCC_DIR = rcc
15 | UI_DIR = ui
16 |
17 | # The following define makes your compiler emit warnings if you use
18 | # any Qt feature that has been marked deprecated (the exact warnings
19 | # depend on your compiler). Please consult the documentation of the
20 | # deprecated API in order to know how to port your code away from it.
21 | DEFINES += QT_DEPRECATED_WARNINGS
22 |
23 | # You can also make your code fail to compile if it uses deprecated APIs.
24 | # In order to do so, uncomment the following line.
25 | # You can also select to disable deprecated APIs only up to a certain version of Qt.
26 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
27 |
28 | SOURCES += \
29 | ffmpegwidget.cpp \
30 | main.cpp \
31 | mainwindow.cpp
32 |
33 | HEADERS += \
34 | ffmpegwidget.h \
35 | mainwindow.h
36 |
37 | FORMS += \
38 | mainwindow.ui
39 |
--------------------------------------------------------------------------------
/ffmpeg.pro:
--------------------------------------------------------------------------------
1 | TEMPLATE = subdirs
2 |
3 | SUBDIRS += 10.02.get_lib_version \
4 | 10.03.get_stream_info \
5 | 10.04.video_decode_flow \
6 | 10.05.video_decode_frame_save \
7 | 10.06.1.video_decode_mp42yuv420p \
8 | 10.06.2.video_decode_mp42yuv420sp \
9 | 10.07.video_decode_by_cpu_display_by_qwidget \
10 | 10.08.1.video_decode_by_cpu_display_by_qopengl \
11 | 10.08.2.video_decode_by_cpu_display_by_qopengl \
12 | 10.09.video_decode_by_cpu_display_by_qml \
13 | 10.10.1.video_decode_by_cuda_display_by_qwidget \
14 | 10.10.2.video_decode_by_cuda_display_by_qopengl \
15 | 10.10.3.video_decode_by_cuda_display_by_qml \
16 | 10.11.video_encode_yuv2h264 \
17 | 10.12.video_encode_h2642mp4 \
18 | 10.13.video_encode_camera2h264 \
19 | 10.14.audio_decode_mp32pcm \
20 | 10.15.audio_decode_swr_mp32pcm \
21 | 10.16.audio_player_decode_by_ffmpeg_play_by_qt \
22 | 10.17.audio_player_decode_from_mem_play_by_qt \
23 | 10.18.audio_encode_pcm2mp3 \
24 | 10.19.audio_video_sync \
25 | 10.20.video_decode_add_filter_display_by_qwidget \
26 | 10.21.video_demuxer_mp42h264mp3 \
27 | 10.22.video_demuxer_mp42yuvpcm \
28 | 10.23.video_muxer_mp3h2642mp4
29 |
--------------------------------------------------------------------------------
/10.10.3.video_decode_by_cuda_display_by_qml/videoitem.h:
--------------------------------------------------------------------------------
1 | #ifndef VIDEOITEM_H
2 | #define VIDEOITEM_H
3 |
4 | #include
5 | #include
6 | #include
7 |
8 | #include "ffmpegdecoder.h"
9 |
10 | class VideoItem : public QQuickFramebufferObject
11 | {
12 | Q_OBJECT
13 | public:
14 | ///
15 | /// \brief VideoItem qml界面对象构造函数
16 | /// \param parent qml界面父指针
17 | ///
18 | explicit VideoItem(QQuickItem* parent = nullptr);
19 |
20 | ///
21 | /// \brief ~VideoItem 释放所有资源
22 | ~VideoItem() override;
23 |
24 | ///
25 | /// \brief createRenderer 创建一个渲染器对象
26 | /// \return 创建的对象指针
27 | ///
28 | Renderer *createRenderer() const override;
29 |
30 | ///
31 | /// \brief getFrame 从缓冲区里面获取一帧数据
32 | /// \param ptr 数据指针
33 | /// \param w 图像宽度
34 | /// \param h 图像高度
35 | ///
36 | void getFrame(uchar **ptr, int *w, int *h);
37 |
38 | ///
39 | /// \brief setUrl 设置解码视频流地址,可在qml中调用
40 | /// \param url 新的视频流地址
41 | ///
42 | Q_INVOKABLE void setUrl(QString url);
43 |
44 | ///
45 | /// \brief start 启动视频解码线程,开始显示视频
46 | ///
47 | Q_INVOKABLE void start();
48 | ///
49 | /// \brief start 停止视频解码线程,不显示视频
50 | ///
51 | Q_INVOKABLE void stop();
52 |
53 | private:
54 | FFmpegDecoder *m_decoder;//解码对象
55 |
56 | QTimer *m_timer=nullptr;//界面刷新定时器
57 |
58 | QString m_url;//视频流地址变量
59 | };
60 |
61 | #endif // VIDEORENDER_H
62 |
--------------------------------------------------------------------------------
/10.09.video_decode_by_cpu_display_by_qml/10.09.video_decode_by_cpu_display_by_qml.pro:
--------------------------------------------------------------------------------
1 | QT += quick multimedia opengl
2 | CONFIG += c++17
3 |
4 | # The following define makes your compiler emit warnings if you use
5 | # any feature of Qt which as been marked deprecated (the exact warnings
6 | # depend on your compiler). Please consult the documentation of the
7 | # deprecated API in order to know how to port your code away from it.
8 | DEFINES += QT_DEPRECATED_WARNINGS
9 |
10 | # You can also make your code fail to compile if you use deprecated APIs.
11 | # In order to do so, uncomment the following line.
12 | # You can also select to disable deprecated APIs only up to a certain version of Qt.
13 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
14 |
15 | include(../ffmpeg.pri)
16 |
17 | DESTDIR = ../bin
18 | TARGET = 10_decode_qml
19 | OBJECTS_DIR = obj
20 | MOC_DIR = moc
21 | RCC_DIR = rcc
22 | UI_DIR = uis
23 |
24 | HEADERS += \
25 | ffmpegdecoder.h \
26 | videoitem.h \
27 | i420render.h
28 |
29 | SOURCES += main.cpp \
30 | ffmpegdecoder.cpp \
31 | videoitem.cpp \
32 | i420render.cpp
33 |
34 | RESOURCES += qml.qrc
35 |
36 | # Additional import path used to resolve QML modules in Qt Creator's code model
37 | QML_IMPORT_PATH =
38 |
39 | # Additional import path used to resolve QML modules just for Qt Quick Designer
40 | QML_DESIGNER_IMPORT_PATH =
41 |
42 |
--------------------------------------------------------------------------------
/10.08.1.video_decode_by_cpu_display_by_qopengl/10.08.1.video_decode_by_cpu_display_by_qopengl.pro:
--------------------------------------------------------------------------------
1 | #-------------------------------------------------
2 | #
3 | # Project created by QtCreator 2021-04-02T17:31:10
4 | #
5 | #-------------------------------------------------
6 |
7 | QT += core gui
8 |
9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
10 |
11 | TEMPLATE = app
12 |
13 | # The following define makes your compiler emit warnings if you use
14 | # any feature of Qt which has been marked as deprecated (the exact warnings
15 | # depend on your compiler). Please consult the documentation of the
16 | # deprecated API in order to know how to port your code away from it.
17 | DEFINES += QT_DEPRECATED_WARNINGS
18 |
19 | # You can also make your code fail to compile if you use deprecated APIs.
20 | # In order to do so, uncomment the following line.
21 | # You can also select to disable deprecated APIs only up to a certain version of Qt.
22 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
23 |
24 | include(../ffmpeg.pri)
25 |
26 | DESTDIR = ../bin
27 | TARGET = 9_1_decode_qopengl
28 | OBJECTS_DIR = obj
29 | MOC_DIR = moc
30 | RCC_DIR = rcc
31 | UI_DIR = ui
32 |
33 | SOURCES += \
34 | main.cpp \
35 | mainwindow.cpp \
36 | ffmpegdecoder.cpp \
37 | i420render.cpp
38 |
39 | HEADERS += \
40 | mainwindow.h \
41 | ffmpegdecoder.h \
42 | i420render.h
43 |
44 | FORMS += \
45 | mainwindow.ui
46 |
--------------------------------------------------------------------------------
/10.08.2.video_decode_by_cpu_display_by_qopengl/10.08.2.video_decode_by_cpu_display_by_qopengl.pro:
--------------------------------------------------------------------------------
1 | #-------------------------------------------------
2 | #
3 | # Project created by QtCreator 2021-04-02T17:31:10
4 | #
5 | #-------------------------------------------------
6 |
7 | QT += core gui
8 |
9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
10 |
11 | TEMPLATE = app
12 |
13 | CONFIG += c++17
14 |
15 | # The following define makes your compiler emit warnings if you use
16 | # any feature of Qt which has been marked as deprecated (the exact warnings
17 | # depend on your compiler). Please consult the documentation of the
18 | # deprecated API in order to know how to port your code away from it.
19 | DEFINES += QT_DEPRECATED_WARNINGS
20 |
21 | # You can also make your code fail to compile if you use deprecated APIs.
22 | # In order to do so, uncomment the following line.
23 | # You can also select to disable deprecated APIs only up to a certain version of Qt.
24 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
25 |
26 | include(../ffmpeg.pri)
27 |
28 | DESTDIR = ../bin
29 | TARGET = 9_2_decode_qopengl2
30 | OBJECTS_DIR = obj
31 | MOC_DIR = moc
32 | RCC_DIR = rcc
33 | UI_DIR = ui
34 |
35 | SOURCES += \
36 | i420render2.cpp \
37 | main.cpp \
38 | mainwindow.cpp \
39 | ffmpegdecoder.cpp
40 |
41 | HEADERS += \
42 | i420render2.h \
43 | mainwindow.h \
44 | ffmpegdecoder.h
45 |
46 | FORMS += \
47 | mainwindow.ui
48 |
--------------------------------------------------------------------------------
/10.10.3.video_decode_by_cuda_display_by_qml/ffmpegdecoder.h:
--------------------------------------------------------------------------------
1 | #ifndef FFMPEGDECODER_H
2 | #define FFMPEGDECODER_H
3 |
4 | #include
5 | #include
6 |
7 | extern "C"{
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | }
24 |
25 | class FFmpegDecoder : public QThread
26 | {
27 | Q_OBJECT
28 | public:
29 | FFmpegDecoder();
30 | ~FFmpegDecoder();
31 |
32 | void setUrl(QString url);
33 |
34 | static enum AVPixelFormat get_hw_format(AVCodecContext *ctx,
35 | const enum AVPixelFormat *pix_fmts);
36 | static int hw_decoder_init(AVCodecContext *ctx, const enum AVHWDeviceType type);
37 |
38 | int width(){return videoWidth;}
39 | int height(){return videoHeight;}
40 |
41 | uchar* getFrame(){
42 | return out_buffer;
43 | }
44 |
45 | protected:
46 | void run();
47 |
48 | signals:
49 | void sigNewFrame();
50 |
51 | private:
52 | QString _filePath;
53 | uchar* out_buffer;
54 |
55 | int ret=0;
56 |
57 | int videoWidth=0,videoHeight=0;
58 | };
59 |
60 | #endif // FFMPEGDECODER_H
61 |
--------------------------------------------------------------------------------
/10.08.1.video_decode_by_cpu_display_by_qopengl/ffmpegdecoder.h:
--------------------------------------------------------------------------------
1 | #ifndef FFMPEGDECODER_H
2 | #define FFMPEGDECODER_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 |
10 | extern "C"{
11 | #include
12 |
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 |
22 | #include
23 |
24 | #include
25 | }
26 |
27 |
28 | class FFmpegDecoder : public QThread
29 | {
30 | Q_OBJECT
31 | public:
32 | FFmpegDecoder();
33 | ~FFmpegDecoder();
34 |
35 | void setUrl(QString const url);
36 |
37 | int width();
38 | int height();
39 |
40 | ///
41 | /// \brief getFrame 从解码结果缓存队列中取第一帧显示
42 | /// \return 第一帧数据指针
43 | ///
44 | uchar* getFrame(){
45 | return out_buffer;
46 | }
47 |
48 | protected:
49 | void run();
50 |
51 | signals:
52 | void sigFirst(uchar* p,int w,int h);
53 | void newFrame();
54 |
55 | private:
56 | AVFormatContext *fmtCtx =NULL;
57 | const AVCodec *videoCodec =NULL;
58 | AVCodecContext *videoCodecCtx=NULL;
59 | AVPacket *pkt = NULL;
60 | AVFrame *yuvFrame = NULL;
61 | AVFrame *rgbFrame = NULL;
62 |
63 | struct SwsContext *img_ctx=NULL;
64 |
65 | uchar *out_buffer= nullptr;
66 |
67 | int videoStreamIndex =-1;
68 | int numBytes = -1;
69 |
70 | QString _url;
71 |
72 | bool isFirst = true;
73 |
74 | int w,h;
75 | };
76 |
77 | #endif // FFMPEGDECODER_H
78 |
--------------------------------------------------------------------------------
/10.08.2.video_decode_by_cpu_display_by_qopengl/ffmpegdecoder.h:
--------------------------------------------------------------------------------
1 | #ifndef FFMPEGDECODER_H
2 | #define FFMPEGDECODER_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 |
10 | extern "C"{
11 | #include
12 |
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 |
22 | #include
23 |
24 | #include
25 | }
26 |
27 |
28 | class FFmpegDecoder : public QThread
29 | {
30 | Q_OBJECT
31 | public:
32 | FFmpegDecoder();
33 | ~FFmpegDecoder();
34 |
35 | void setUrl(QString const url);
36 |
37 | int width();
38 | int height();
39 |
40 | ///
41 | /// \brief getFrame 从解码结果缓存队列中取第一帧显示
42 | /// \return 第一帧数据指针
43 | ///
44 | uchar* getFrame(){
45 | return out_buffer;
46 | }
47 |
48 | protected:
49 | void run();
50 |
51 | signals:
52 | void sigFirst(uchar* p,int w,int h);
53 | void newFrame();
54 |
55 | private:
56 | AVFormatContext *fmtCtx =NULL;
57 | const AVCodec *videoCodec =NULL;
58 | AVCodecContext *videoCodecCtx=NULL;
59 | AVPacket *pkt = NULL;
60 | AVFrame *yuvFrame = NULL;
61 | AVFrame *rgbFrame = NULL;
62 |
63 | struct SwsContext *img_ctx=NULL;
64 |
65 | uchar *out_buffer= nullptr;
66 |
67 | int videoStreamIndex =-1;
68 | int numBytes = -1;
69 |
70 | QString _url;
71 |
72 | bool isFirst = true;
73 |
74 | int w,h;
75 | };
76 |
77 | #endif // FFMPEGDECODER_H
78 |
--------------------------------------------------------------------------------
/10.08.1.video_decode_by_cpu_display_by_qopengl/mainwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 696
10 | 574
11 |
12 |
13 |
14 | MainWindow
15 |
16 |
17 |
18 | -
19 |
20 |
21 | Url
22 |
23 |
24 |
25 | -
26 |
27 |
28 | C:\\Users\\hyper\\Videos\\Sample.wmv
29 |
30 |
31 |
32 | -
33 |
34 |
35 | Play
36 |
37 |
38 |
39 | -
40 |
41 |
42 |
43 |
44 |
54 |
55 |
56 |
57 |
58 |
59 | I420Render
60 | QOpenGLWidget
61 |
62 |
63 |
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/10.08.2.video_decode_by_cpu_display_by_qopengl/mainwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 696
10 | 574
11 |
12 |
13 |
14 | MainWindow
15 |
16 |
17 |
18 | -
19 |
20 |
21 | Url
22 |
23 |
24 |
25 | -
26 |
27 |
28 | C:\\Users\\hyper\\Videos\\Sample.wmv
29 |
30 |
31 |
32 | -
33 |
34 |
35 | Play
36 |
37 |
38 |
39 | -
40 |
41 |
42 |
43 |
44 |
54 |
55 |
56 |
57 |
58 |
59 | I420Render2
60 | QOpenGLWidget
61 |
62 |
63 |
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/10.07.video_decode_by_cpu_display_by_qwidget/ffmpegwidget.h:
--------------------------------------------------------------------------------
1 | #ifndef FFMPEGWIDGET_H
2 | #define FFMPEGWIDGET_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | #include
12 |
13 | extern "C"{
14 | #include
15 |
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 |
25 | #include
26 |
27 | #include
28 | }
29 |
30 | using namespace std;
31 |
32 | class FFmpegVideo : public QThread
33 | {
34 | Q_OBJECT
35 | public:
36 | explicit FFmpegVideo();
37 | ~FFmpegVideo();
38 |
39 | void setUrl(QString url);
40 |
41 | bool open_input_file();
42 |
43 | protected:
44 | void run();
45 |
46 | signals:
47 | void sendQImage(QImage);
48 |
49 | private:
50 | AVFormatContext *fmtCtx =NULL;
51 | const AVCodec *videoCodec =NULL;
52 | AVCodecContext *videoCodecCtx=NULL;
53 | AVPacket *pkt = NULL;
54 | AVFrame *yuvFrame = NULL;
55 | AVFrame *rgbFrame = NULL;
56 |
57 | struct SwsContext *img_ctx=NULL;
58 |
59 | unsigned char *out_buffer=nullptr;
60 |
61 | int videoStreamIndex =-1;
62 | int numBytes = -1;
63 |
64 | QString _url;
65 | };
66 |
67 | class FFmpegWidget : public QWidget
68 | {
69 | Q_OBJECT
70 | public:
71 | explicit FFmpegWidget(QWidget *parent = nullptr);
72 | ~FFmpegWidget();
73 |
74 | void setUrl(QString url);
75 |
76 | void play();
77 | void stop();
78 |
79 | protected:
80 | void paintEvent(QPaintEvent *);
81 |
82 | private slots:
83 | void receiveQImage(const QImage &rImg);
84 |
85 | private:
86 | FFmpegVideo *ffmpeg;
87 |
88 | QImage img;
89 | };
90 |
91 | #endif // FFMPEGWIDGET_H
92 |
--------------------------------------------------------------------------------
/10.10.1.video_decode_by_cuda_display_by_qwidget/mainwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 800
10 | 600
11 |
12 |
13 |
14 | MainWindow
15 |
16 |
17 |
18 |
19 | 0
20 |
21 |
22 | 0
23 |
24 |
25 | 0
26 |
27 |
28 | 0
29 |
30 |
31 | 0
32 |
33 | -
34 |
35 |
36 | C:\\Users\\hyper\\Videos\\Sample.wmv
37 |
38 |
39 |
40 | -
41 |
42 |
43 | Play
44 |
45 |
46 |
47 | -
48 |
49 |
50 |
51 |
52 |
62 |
63 |
64 |
65 |
66 | FFmpegWidget
67 | QWidget
68 |
69 | 1
70 |
71 |
72 |
73 |
74 |
75 |
--------------------------------------------------------------------------------
/10.10.2.video_decode_by_cuda_display_by_qopengl/mainwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 800
10 | 600
11 |
12 |
13 |
14 | MainWindow
15 |
16 |
17 |
18 |
19 | 0
20 |
21 |
22 | 0
23 |
24 |
25 | 0
26 |
27 |
28 | 0
29 |
30 |
31 | 0
32 |
33 | -
34 |
35 |
36 | C:\\Users\\hyper\\Videos\\Sample.wmv
37 |
38 |
39 |
40 | -
41 |
42 |
43 | Play
44 |
45 |
46 |
47 | -
48 |
49 |
50 |
51 |
52 |
62 |
63 |
64 |
65 |
66 | FFmpegWidget
67 | QWidget
68 |
69 | 1
70 |
71 |
72 |
73 |
74 |
75 |
--------------------------------------------------------------------------------
/ffmpeg.pri:
--------------------------------------------------------------------------------
1 |
2 | # 包含FFmpeg库文件位置
3 |
4 | DEFINES += FFMPEG4
5 |
6 | # windows平台 VS2019
7 | win32{
8 | DEFINES +=_CRT_SECURE_NO_WARNINGS #非安全函数警告
9 | QMAKE_CXXFLAGS += /WX#警告作为错误
10 | if(contains(DEFINES,FFMPEG6)){
11 | #使用6.0版
12 | INCLUDEPATH+= . $$PWD/lib/6.x/include/
13 | LIBS += -L$$PWD/lib/6.x/lib \
14 | -lavcodec -lavdevice -lavfilter -lavformat -lavutil -lpostproc \
15 | -lswresample -lswscale
16 | }
17 | if(contains(DEFINES,FFMPEG5)){
18 | #使用5.1.3版
19 | INCLUDEPATH+= . $$PWD/lib/5.x/include/
20 | LIBS += -L$$PWD/lib/5.x/lib \
21 | -lavcodec -lavdevice -lavfilter -lavformat -lavutil -lpostproc \
22 | -lswresample -lswscale
23 | }
24 | if(contains(DEFINES,FFMPEG4)){
25 | #使用4.4.4版
26 | INCLUDEPATH+= . $$PWD/lib/4.x/include/
27 | LIBS += -L$$PWD/lib/4.x/lib/ \
28 | -lavcodec -lavdevice -lavfilter -lavformat -lavutil -lpostproc \
29 | -lswresample -lswscale
30 | }
31 |
32 | if(contains(DEFINES,SYSTEM)){
33 | #使用系统库
34 | message("no system lib on windows,please use other conf instead.")
35 | }
36 | }
37 |
38 | # linux平台 GCC
39 | unix{
40 | QMAKE_CXXFLAGS += -Werror#警告作为错误
41 | if(contains(DEFINES,FFMPEG6)){
42 | #使用6.0版
43 | INCLUDEPATH+= . $$PWD/lib/6.x/include/ /usr/include/mfx/
44 | LIBS += -L$$PWD/lib/6.x/lib \
45 | -lavcodec -lavdevice -lavfilter -lavformat -lavutil -lpostproc \
46 | -lswresample -lswscale
47 | }
48 | if(contains(DEFINES,FFMPEG5)){
49 | #使用5.1.3版
50 | INCLUDEPATH+= . $$PWD/lib/5.x/include/
51 | LIBS += -L$$PWD/lib/5.x/lib \
52 | -lavcodec -lavdevice -lavfilter -lavformat -lavutil -lpostproc \
53 | -lswresample -lswscale
54 | }
55 | if(contains(DEFINES,FFMPEG4)){
56 | #使用4.4.4版
57 | INCLUDEPATH+= . $$PWD/lib/4.x/include/
58 | LIBS += -L$$PWD/lib/4.x/lib/ \
59 | -lavcodec -lavdevice -lavfilter -lavformat -lavutil -lpostproc \
60 | -lswresample -lswscale
61 | }
62 |
63 | if(contains(DEFINES,SYSTEM)){
64 | #使用系统库
65 | INCLUDEPATH+= . /usr/include/x86_64-linux-gnu/
66 | LIBS += -L/usr/lib/x86_64-linux-gnu/ \
67 | -lavcodec -lavdevice -lavfilter -lavformat -lavutil -lpostproc \
68 | -lswresample -lswscale
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/10.19.audio_video_sync/mainwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 800
10 | 617
11 |
12 |
13 |
14 | MainWindow
15 |
16 |
17 |
18 |
19 | 1
20 |
21 |
22 | 1
23 |
24 |
25 | 1
26 |
27 |
28 | 1
29 |
30 |
31 | 0
32 |
33 | -
34 |
35 |
36 | Play
37 |
38 |
39 |
40 | -
41 |
42 |
43 | Url
44 |
45 |
46 |
47 | -
48 |
49 |
50 | -
51 |
52 |
53 | Stop
54 |
55 |
56 |
57 | -
58 |
59 |
60 | C:\\Users\\hyper\\Videos\\Sample.mkv
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 | FFmpegWidget
71 | QWidget
72 |
73 | 1
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/10.07.video_decode_by_cpu_display_by_qwidget/mainwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 800
10 | 617
11 |
12 |
13 |
14 | MainWindow
15 |
16 |
17 |
18 |
19 | 1
20 |
21 |
22 | 1
23 |
24 |
25 | 1
26 |
27 |
28 | 1
29 |
30 |
31 | 0
32 |
33 | -
34 |
35 |
36 | Play
37 |
38 |
39 |
40 | -
41 |
42 |
43 | Url
44 |
45 |
46 |
47 | -
48 |
49 |
50 | -
51 |
52 |
53 | Stop
54 |
55 |
56 |
57 | -
58 |
59 |
60 | C:\\Users\\hyper\\Videos\\Sample.wmv
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 | FFmpegWidget
71 | QWidget
72 |
73 | 1
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/10.09.video_decode_by_cpu_display_by_qml/ffmpegdecoder.h:
--------------------------------------------------------------------------------
1 | #ifndef FFMPEGDECODER_H
2 | #define FFMPEGDECODER_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | extern "C"{
12 | #include
13 |
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 |
23 | #include
24 |
25 | #include
26 | }
27 |
28 | const static int bufferSize = 1280*720;
29 |
30 | struct YUVData{
31 | YUVData(){
32 | Y.reserve(bufferSize);
33 | U.reserve(bufferSize);
34 | V.reserve(bufferSize);
35 | }
36 | QByteArray Y;
37 | QByteArray U;
38 | QByteArray V;
39 | int yLineSize;
40 | int uLineSize;
41 | int vLineSize;
42 | int height;
43 | };
44 |
45 | class FFmpegDecoder : public QThread
46 | {
47 | Q_OBJECT
48 | public:
49 | FFmpegDecoder();
50 | ~FFmpegDecoder();
51 |
52 | void setUrl(QString const url);
53 |
54 | int width();
55 | int height();
56 |
57 | ///
58 | /// \brief getFrame 从解码结果缓存队列中取第一帧显示
59 | /// \return 第一帧数据指针
60 | ///
61 | YUVData getFrame(){
62 | if(frameBuffer.isEmpty()){
63 | return YUVData{};
64 | }
65 | return frameBuffer.takeFirst();
66 | }
67 |
68 | protected:
69 | void run();
70 |
71 | signals:
72 | void sigFirst(uchar* p,int w,int h);
73 | void newFrame();
74 | void videoInfoReady(int w,int h);
75 |
76 | private:
77 | AVFormatContext *fmtCtx =NULL;
78 | const AVCodec *videoCodec =NULL;
79 | AVCodecContext *videoCodecCtx=NULL;
80 | AVPacket *pkt = NULL;
81 | AVFrame *yuvFrame = NULL;
82 | AVFrame *rgbFrame = NULL;
83 |
84 | int videoStreamIndex =-1;
85 |
86 | QString _url;
87 |
88 | bool isFirst = true;
89 |
90 | int w,h;
91 |
92 | YUVData m_yuvData;
93 |
94 | QContiguousCache frameBuffer;
95 | };
96 |
97 | #endif // FFMPEGDECODER_H
98 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ffmpeg_beginner
2 |
3 | FFmpeg4入门系列教程代码
4 |
5 | FFmpeg5/6对应代码见其他分支
6 |
7 | ## 编译说明
8 |
9 | - 使用FFmpeg-BuildsLatest Auto-Build (2023-09-04 12:49) 15d0b26 测试
10 | - 尽量保证编译结果没有错误、没有警告、没有deprecated方法调用
11 | - 如果提示系统没有mfx头文件,可以从Intel Media SDK下载,下载后把api/include目录重命名为mfx,然后复制到include目录中
12 |
13 | ## 源码说明
14 |
15 | ### 10.02.get_lib_version
16 |
17 | 获取库版本信息并解析输出可读信息
18 |
19 | ### 10.03.get_stream_info
20 |
21 | 输出视频的基本信息(时长、码率、编码方式等等)
22 |
23 | ### 10.04.video_decode_flow
24 |
25 | 视频解码的基本流程
26 |
27 | ### 10.05.video_decode_frame_save
28 |
29 | 解码视频并保存其中的50帧画面为ppm格式图片
30 |
31 | ### 10.06.video_decode_mp42yuv
32 |
33 | 视频解码的基本流程并输出视频信息,将解码后的视频数据保存为YUV格式文件
34 |
35 | 分别解码为YUV420P/YUV420SP
36 |
37 | ### 10.07.video_decode_by_cpu_display_by_qwidget
38 |
39 | 使用CPU解码视频,然后使用Qt的QWidget显示画面
40 |
41 | ### 10.08.video_decode_by_cpu_display_by_qopengl
42 |
43 | 使用CPU解码视频,然后使用Qt的QOpenGL显示画面
44 |
45 | 两种方法仅供参考
46 |
47 | ### 10.09.video_decode_by_cpu_display_by_qml
48 |
49 | 使用CPU解码视频,然后使用QML显示画面
50 |
51 | ### 10.10.video_decode_by_cuda_display_by_qt
52 |
53 | 使用CUDA解码视频并使用Qt的QWidget/QOpenGL/QML显示视频
54 |
55 | ### 10.11.video_encode_yuv2h264
56 |
57 | 将yuv源视频文件编码为h264格式的文件
58 |
59 | ### 10.12.video_encode_h2642mp4
60 |
61 | 将h264编码为mp4格式文件
62 |
63 | ### 10.13.video_encode_camera2h264
64 |
65 | 将摄像头捕获的视频直接编码为H264格式
66 |
67 | ### 10.14.audio_decode_mp32pcm
68 |
69 | 将mp3文件解码为pcm文件
70 |
71 | ### 10.15.audio_decode_swr_mp32pcm
72 |
73 | 将mp3音频重采样解码为pcm
74 |
75 | ### 10.16.audio_player_decode_by_ffmpeg_play_by_qt
76 |
77 | 使用FFmpeg解码音频,使用Qt播放音频
78 |
79 | ### 10.17.audio_player_decode_from_mem_play_by_qt
80 |
81 | 解码内存中的mp3数据并使用Qt播放
82 |
83 | ### 10.18.audio_encode_pcm2mp3
84 |
85 | 将pcm格式文件编码为mp3格式
86 |
87 | ### 10.19.audio_video_sync
88 |
89 | Qt简单视频播放器,带音视频同步
90 |
91 | ### 10.20.video_decode_add_filter_display_by_qwidget
92 |
93 | 使用CPU解码视频,并添加滤镜,然后使用QWidget显示画面
94 |
95 | ### 10.21.video_demuxer_mp42h264mp3
96 |
97 | 将mp4分解为h264和mp3
98 |
99 | ### 10.22.video_demuxer_mp42yuvpcm
100 |
101 | 将mp4分解为h264和mp3,并在此基础上将h264解码为yuv,将mp3解码为pcm
102 |
103 | ### 10.23.video_muxer_mp3h2642mp4
104 |
105 | 将h264和mp3合并为mp4
106 |
107 | ### RTSParser
108 |
109 | 收RTSP流,并解析流中的H264数据
110 |
111 | ### 待添加
112 |
113 | 本系列的目的就是将雷霄华同志的教程进行新版本适配,其在CSDN发布的所有文章涉及的代码都会进行适配
--------------------------------------------------------------------------------
/10.20.video_decode_add_filter_display_by_qwidget/ffmpegwidget.h:
--------------------------------------------------------------------------------
1 | #ifndef FFMPEGWIDGET_H
2 | #define FFMPEGWIDGET_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | #include
12 |
13 | extern "C"{
14 | #include
15 |
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 |
25 | #include
26 | #include
27 | #include
28 |
29 | #include
30 |
31 | #include
32 | }
33 |
34 | using namespace std;
35 |
36 | class FFmpegVideo : public QThread
37 | {
38 | Q_OBJECT
39 | public:
40 | explicit FFmpegVideo();
41 | ~FFmpegVideo();
42 |
43 | void init_variables();
44 | void free_variables();
45 |
46 | void setUrl(QString url);
47 | bool open_input_file();
48 |
49 | bool initFilter();
50 |
51 | void setCL(int c,int l);
52 |
53 | protected:
54 | void run();
55 |
56 | signals:
57 | void sendQImage(QImage);
58 |
59 | private:
60 | AVFormatContext *fmtCtx =NULL;
61 | const AVCodec *videoCodec =NULL;
62 | AVCodecContext *videoCodecCtx=NULL;
63 | AVPacket *pkt = NULL;
64 | AVFrame *yuvFrame = NULL;
65 | AVFrame *rgbFrame = NULL;
66 |
67 | AVFilterContext *bufSinkCtx;
68 | AVFilterContext *bufSrcCtx;
69 | AVFilterGraph *filterGraph;
70 |
71 | QString filterDescr="eq=contrast=1:brightness=0";
72 | QString _url;
73 |
74 | struct SwsContext *img_ctx=NULL;
75 |
76 | unsigned char *out_buffer=nullptr;
77 |
78 | int videoWidth=0,videoHeight=0;
79 |
80 | int videoStreamIndex =-1;
81 | int numBytes = -1;
82 |
83 | bool runFlag=true;
84 | int ret=-1;
85 | };
86 |
87 | class FFmpegWidget : public QWidget
88 | {
89 | Q_OBJECT
90 | public:
91 | explicit FFmpegWidget(QWidget *parent = nullptr);
92 | ~FFmpegWidget();
93 |
94 | void play(QString url);
95 | void stop();
96 |
97 | void setFilterDescr(int c,int b);
98 |
99 | protected:
100 | void paintEvent(QPaintEvent *);
101 |
102 | private slots:
103 | void receiveQImage(const QImage &rImg);
104 |
105 | private:
106 | FFmpegVideo *ffmpeg;
107 |
108 | QImage img;
109 | };
110 |
111 | #endif // FFMPEGWIDGET_H
112 |
--------------------------------------------------------------------------------
/10.10.3.video_decode_by_cuda_display_by_qml/main.qml:
--------------------------------------------------------------------------------
1 | import QtQuick 2.11
2 | import QtQuick.Window 2.11
3 | import QtQuick.Dialogs.qml 1.0
4 | import QtQuick.Extras 1.4
5 | import QtMultimedia 5.9
6 | import QtQuick.Controls 2.3
7 | import QtQuick.Layouts 1.3
8 | import VideoItem 1.0
9 |
10 | Window {
11 | objectName: "mainWindow"
12 | width: 1280
13 | height: 720
14 | visible: true
15 | title: qsTr("Mpplayer")
16 |
17 | property string url: textField.text //地址变量
18 |
19 | Item{
20 | id:root
21 | anchors.fill: parent
22 | VideoItem{//视频模块
23 | id: videoitem
24 | anchors.fill: parent
25 | }
26 |
27 | Label {
28 | id: label
29 | x: 24
30 | y: 372
31 | width: 51
32 | height: 31
33 | text: qsTr("Url")
34 | transformOrigin: Item.Center
35 | }
36 |
37 | TextField {
38 | id: textField
39 | x: 81
40 | y: 363
41 | width: 507
42 | height: 40
43 | text: qsTr("C:\\Users\\hyper\\Videos\\Sample.wmv")
44 | }
45 |
46 | Button {
47 | id: button
48 | x: 24
49 | y: 416
50 | text: qsTr("Play1")
51 |
52 | onClicked: {
53 | videoitem.setUrl(url)
54 | console.log(url)
55 | videoitem.start()
56 | }
57 | }
58 |
59 | Button {
60 | id: button1
61 | x: 139
62 | y: 416
63 | text: qsTr("Play2")
64 | onClicked: {
65 | videoitem.setUrl(url)
66 | console.log(url)
67 | videoitem.start()
68 | }
69 | }
70 |
71 | Button {
72 | id: button2
73 | x: 258
74 | y: 416
75 | text: qsTr("Play3")
76 | onClicked: {
77 | videoitem.setUrl(url)
78 | console.log(url)
79 | videoitem.start()
80 | }
81 | }
82 |
83 | Button {
84 | id: button3
85 | x: 390
86 | y: 416
87 | text: qsTr("Play4")
88 | onClicked: {
89 | videoitem.setUrl(url)
90 | console.log(url)
91 | videoitem.start()
92 | }
93 | }
94 |
95 | Button {
96 | id: button4
97 | x: 515
98 | y: 416
99 | text: qsTr("Stop")
100 | onClicked: {
101 | videoitem.stop();
102 | }
103 | }
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/10.10.1.video_decode_by_cuda_display_by_qwidget/ffmpegvideo.h:
--------------------------------------------------------------------------------
1 | #ifndef FFMPEGVIDEO_H
2 | #define FFMPEGVIDEO_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | #include
12 |
13 | extern "C"{
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include
29 | }
30 |
31 | using namespace std;
32 |
33 | class FFmpegVideo : public QThread
34 | {
35 | Q_OBJECT
36 | public:
37 | explicit FFmpegVideo();
38 | ~FFmpegVideo();
39 |
40 | void setPath(QString url);
41 |
42 | void ffmpeg_init_variables();
43 | void ffmpeg_free_variables();
44 | bool open_input_file();
45 | static enum AVPixelFormat get_hw_format(AVCodecContext *ctx,
46 | const enum AVPixelFormat *pix_fmts);
47 | static int hw_decoder_init(AVCodecContext *ctx, const enum AVHWDeviceType type);
48 |
49 | void stopThread();
50 |
51 | protected:
52 | void run();
53 |
54 | signals:
55 | void sendQImage(const QImage &img);
56 |
57 | private:
58 | AVFormatContext *fmtCtx =NULL;
59 | const AVCodec *videoCodec =NULL;
60 | AVCodecContext *videoCodecCtx=NULL;
61 | AVPacket *pkt = NULL;
62 | AVFrame *yuvFrame = NULL;
63 | AVFrame *rgbFrame = NULL;
64 | AVFrame *nv12Frame = NULL;
65 | AVStream *videoStream = NULL;
66 |
67 | uchar *out_buffer;
68 | struct SwsContext *img_ctx=NULL;
69 |
70 | QString _filePath;
71 |
72 | int videoStreamIndex =-1;
73 | int numBytes = -1;
74 |
75 | int ret =0;
76 |
77 | bool initFlag=false,openFlag=false,stopFlag=false;
78 | };
79 |
80 |
81 | class FFmpegWidget : public QWidget
82 | {
83 | Q_OBJECT
84 | public:
85 | explicit FFmpegWidget(QWidget *parent = nullptr);
86 | ~FFmpegWidget();
87 |
88 | void play(QString url);
89 | void stop();
90 |
91 | protected:
92 | void paintEvent(QPaintEvent *);
93 |
94 | private slots:
95 | void receiveQImage(const QImage &rImg);
96 |
97 | private:
98 | FFmpegVideo *ffmpeg;
99 |
100 | QImage img;
101 | };
102 |
103 | #endif // FFMPEGVIDEO_H
104 |
--------------------------------------------------------------------------------
/10.10.2.video_decode_by_cuda_display_by_qopengl/ffmpegvideo.h:
--------------------------------------------------------------------------------
1 | #ifndef FFMPEGVIDEO_H
2 | #define FFMPEGVIDEO_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | #include
12 |
13 | extern "C"{
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include
29 | }
30 |
31 | using namespace std;
32 |
33 | class FFmpegVideo : public QThread
34 | {
35 | Q_OBJECT
36 | public:
37 | explicit FFmpegVideo();
38 | ~FFmpegVideo();
39 |
40 | void setPath(QString url);
41 |
42 | void ffmpeg_init_variables();
43 | void ffmpeg_free_variables();
44 | bool open_input_file();
45 | static enum AVPixelFormat get_hw_format(AVCodecContext *ctx,
46 | const enum AVPixelFormat *pix_fmts);
47 | static int hw_decoder_init(AVCodecContext *ctx, const enum AVHWDeviceType type);
48 |
49 | void stopThread();
50 |
51 | protected:
52 | void run();
53 |
54 | signals:
55 | void sendQImage(const QImage &img);
56 |
57 | private:
58 | AVFormatContext *fmtCtx =NULL;
59 | const AVCodec *videoCodec =NULL;
60 | AVCodecContext *videoCodecCtx=NULL;
61 | AVPacket *pkt = NULL;
62 | AVFrame *yuvFrame = NULL;
63 | AVFrame *rgbFrame = NULL;
64 | AVFrame *nv12Frame = NULL;
65 | AVStream *videoStream = NULL;
66 |
67 | uchar *out_buffer;
68 | struct SwsContext *img_ctx=NULL;
69 |
70 | QString _filePath;
71 |
72 | int videoStreamIndex =-1;
73 | int numBytes = -1;
74 |
75 | int ret =0;
76 |
77 | bool initFlag=false,openFlag=false,stopFlag=false;
78 | };
79 |
80 |
81 | class FFmpegWidget : public QWidget
82 | {
83 | Q_OBJECT
84 | public:
85 | explicit FFmpegWidget(QWidget *parent = nullptr);
86 | ~FFmpegWidget();
87 |
88 | void play(QString url);
89 | void stop();
90 |
91 | protected:
92 | void paintEvent(QPaintEvent *);
93 |
94 | private slots:
95 | void receiveQImage(const QImage &rImg);
96 |
97 | private:
98 | FFmpegVideo *ffmpeg;
99 |
100 | QImage img;
101 | };
102 |
103 | #endif // FFMPEGVIDEO_H
104 |
--------------------------------------------------------------------------------
/10.09.video_decode_by_cpu_display_by_qml/videoitem.cpp:
--------------------------------------------------------------------------------
1 | #include "videoitem.h"
2 | #include "i420render.h"
3 | #include
4 | #include
5 |
6 | //************VideoItemRender************//
7 | class VideoFboItem : public QQuickFramebufferObject::Renderer
8 | {
9 | public:
10 | VideoFboItem(){
11 | m_render.init();
12 | }
13 |
14 | void render() override{
15 | m_render.paint();
16 | m_window->resetOpenGLState();
17 | }
18 | QOpenGLFramebufferObject *createFramebufferObject(const QSize &size) override{
19 | QOpenGLFramebufferObjectFormat format;
20 | format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
21 | format.setSamples(4);
22 | m_render.resize(size.width(), size.height());
23 | return new QOpenGLFramebufferObject(size, format);
24 | }
25 | void synchronize(QQuickFramebufferObject *item) override{
26 | VideoItem *pItem = qobject_cast(item);
27 | if (pItem)
28 | {
29 | if (!m_window)
30 | {
31 | m_window = pItem->window();
32 | }
33 | if (pItem->infoDirty())
34 | {
35 | m_render.updateTextureInfo(pItem->videoWidth(), pItem->videoHeght());
36 | pItem->makeInfoDirty(false);
37 | }
38 | ba = pItem->getFrame();
39 | m_render.updateTextureData(ba);
40 | }
41 | }
42 | private:
43 | I420Render m_render;
44 | QQuickWindow *m_window = nullptr;
45 |
46 | YUVData ba;
47 | };
48 |
49 | //************VideoItem************//
50 | VideoItem::VideoItem(QQuickItem *parent) : QQuickFramebufferObject (parent)
51 | {
52 | m_decoder = new FFmpegDecoder;
53 | connect(m_decoder,&FFmpegDecoder::videoInfoReady,this,&VideoItem::onVideoInfoReady);
54 |
55 | startTimer(24);
56 | }
57 |
58 | void VideoItem::timerEvent(QTimerEvent *)
59 | {
60 | update();
61 | }
62 |
63 | YUVData VideoItem::getFrame()
64 | {
65 | return m_decoder->getFrame();
66 | }
67 |
68 | void VideoItem::setUrl(const QString &url)
69 | {
70 | m_decoder->setUrl(url);
71 | }
72 |
73 | void VideoItem::start()
74 | {
75 | m_decoder->start();
76 | }
77 |
78 | void VideoItem::stop()
79 | {
80 | if(m_decoder->isRunning()){
81 | m_decoder->quit();
82 | m_decoder->wait(1000);
83 | }
84 | }
85 |
86 | void VideoItem::onVideoInfoReady(int width, int height)
87 | {
88 | if (m_videoWidth != width)
89 | {
90 | m_videoWidth = width;
91 | makeInfoDirty(true);
92 | }
93 | if (m_videoHeight != height)
94 | {
95 | m_videoHeight = height;
96 | makeInfoDirty(true);
97 | }
98 | }
99 |
100 | QQuickFramebufferObject::Renderer *VideoItem::createRenderer() const
101 | {
102 | return new VideoFboItem;
103 | }
104 |
105 |
--------------------------------------------------------------------------------
/10.10.3.video_decode_by_cuda_display_by_qml/videoitem.cpp:
--------------------------------------------------------------------------------
1 | #include "videoitem.h"
2 | #include
3 | #include
4 |
5 | #include "nv12render.h"
6 |
7 | class VideoFboItem
8 | :public QQuickFramebufferObject::Renderer
9 | {
10 | public:
11 | ///
12 | /// \brief VideoFboItem 构造函数,调用成员变量的构造函数
13 | ///
14 | VideoFboItem()
15 | {
16 | //qDebug()<<"VideoFboItem";
17 | }
18 |
19 | ///
20 | /// \brief ~VideoFboItem 析构函数,释放资源
21 | ///
22 | ~VideoFboItem() override{
23 | }
24 |
25 | ///
26 | /// \brief synchronize 数据同步函数,获取界面解码后的帧数据和宽度高度
27 | /// \param item 父界面的对象指针
28 | ///
29 | void synchronize(QQuickFramebufferObject *item) override{
30 | VideoItem* pItem= dynamic_cast(item);
31 | if(pItem){
32 | //qDebug()<<"synchroinze: "<getFrame(&ptr,&videoW,&videoH);
34 | }
35 | }
36 |
37 | ///
38 | /// \brief render 调用OpenGL的纹理绘制函数绘制图片到界面
39 | ///
40 | void render() override{
41 | //qDebug()<<"render: "<stop();
74 | delete m_timer;
75 | stop();
76 | delete m_decoder;
77 | }
78 |
79 | QQuickFramebufferObject::Renderer *VideoItem::createRenderer() const
80 | {
81 | //qDebug()<<"Renderer";
82 | return new VideoFboItem;
83 | }
84 |
85 | void VideoItem::getFrame(uchar **ptr, int *w, int *h)
86 | {
87 | //qDebug()<<"get frame ptr: "<getFrame();
89 | *w = (int)m_decoder->width();
90 | *h = (int)m_decoder->height();
91 |
92 | return;
93 | }
94 |
95 | void VideoItem::setUrl(QString url)
96 | {
97 | if(m_url != url){
98 | stop();
99 | }
100 |
101 | m_url=url;
102 | m_decoder->setUrl(url);
103 | }
104 |
105 | void VideoItem::start()
106 | {
107 | stop();
108 | m_decoder->start();
109 | }
110 |
111 | void VideoItem::stop()
112 | {
113 | if(m_decoder->isRunning()){
114 | m_decoder->requestInterruption();
115 | m_decoder->quit();
116 | m_decoder->wait();
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/10.19.audio_video_sync/ffmpegwidget.h:
--------------------------------------------------------------------------------
1 | #ifndef FFMPEGWIDGET_H
2 | #define FFMPEGWIDGET_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 |
19 | #include
20 |
21 | extern "C"{
22 | #include
23 |
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include