Skip to content

Commit

Permalink
[引入mpv播放器支持]:引入了mpv播放器的支持。
Browse files Browse the repository at this point in the history
- 添加了mpv相关的CMakeLists.txt配置,使得mpv可以作为可选模块编译进项目中。
- 更新了install-dependencies/action.yml,增加了mpv的安装步骤,以便在macOS上通过Homebrew安装mpv。
- 对cmake.yml和qmake.yml进行了修改,加入了对mpv编译选项的配置。
- 修改了CMakeLists.txt,引入了BUILD_MPV选项,并根据此选项配置了项目。
- 为examples目录添加了mpvplayer子目录,并创建了相关的CMakeLists.txt、mainwindow.cc/.hpp等文件,实现了基于mpv的播放器界面。
- 更新了player和transcoder的CMakeLists.txt,以支持mpv选项。
- 为mpvplayer添加了控制widget、日志窗口、字幕延迟对话框等组件。
- 在src目录下添加了mpv子目录,实现了mpv播放器的核心功能,包括与mpv的交互、渲染以及事件处理。
- 更新了utils.cpp和utils.h,增加了设置OpenGL表面格式版本的功能。
- 根据是否启用mpv选项,调整了src.pro,以包含或排除mpv子目录。
  • Loading branch information
RealChuan committed Jun 5, 2024
1 parent 388aaa4 commit 1891851
Show file tree
Hide file tree
Showing 92 changed files with 2,752 additions and 103 deletions.
5 changes: 3 additions & 2 deletions .github/actions/install-dependencies/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ runs:
if: startsWith(runner.os, 'macOS')
shell: bash
run: |
brew install ninja nasm python-setuptools
brew install ninja nasm python-setuptools mpv
ninja --version
cmake --version
clang --version
Expand All @@ -97,7 +97,8 @@ runs:
run: |
sudo apt-get update
sudo apt-get install ninja-build nasm autopoint gperf libgl1-mesa-dev \
libxinerama-dev libxcursor-dev xorg-dev libglu1-mesa-dev
libxinerama-dev libxcursor-dev xorg-dev libglu1-mesa-dev \
mpv libmpv-dev
ninja --version
cmake --version
gcc --version
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
-S . `
-B ./build `
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} `
-DBUILD_MPV=OFF `
-G "${{ matrix.generators }}"
cmake --build ./build --config ${{ matrix.build_type }}
- name: Configure and build on ubuntu or macos
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/qmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
shell: pwsh
run: |
..\scripts\windows\setVsDev.ps1 -VersionRange "[16.0,17.0)" -Arch "x64"
& qmake ./../.
& qmake "CONFIG-=BUILD_MPV" ./../.
& jom
working-directory: build
- name: ubuntu-build
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ project(
HOMEPAGE_URL "https://github.com/RealChuan/Qt-Ffmpeg"
LANGUAGES CXX)

option(BUILD_MPV "build mpv" ON)

include(cmake/common.cmake)

find_package(Qt6 REQUIRED COMPONENTS Widgets Network Core5Compat Concurrent
Expand Down
8 changes: 6 additions & 2 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
add_subdirectory(player)
add_subdirectory(transcoder)
add_subdirectory(ffmpegplayer)
add_subdirectory(ffmpegtranscoder)

if(BUILD_MPV)
add_subdirectory(mpvplayer)
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ void ControlWidget::setPlayButtonChecked(bool checked)
d_ptr->setPlayButtonIcon();
}

void ControlWidget::setVolumeMax(int max)
{
d_ptr->volumeSlider->setMaximum(max);
}

void ControlWidget::setVolume(int value)
{
if (value < d_ptr->volumeSlider->minimum()) {
Expand All @@ -208,6 +213,16 @@ void ControlWidget::setDuration(int value)
setPosition(0);
}

#ifdef MPV_ON
void ControlWidget::setChapters(const Mpv::Chapters &chapters)
{
QVector<qint64> nodes;
for (const auto &chapter : std::as_const(chapters)) {
nodes.append(chapter.milliseconds / 1000);
}
d_ptr->slider->setNodes(nodes);
}
#else
void ControlWidget::setChapters(const Ffmpeg::Chapters &chapters)
{
QVector<qint64> nodes;
Expand All @@ -216,6 +231,7 @@ void ControlWidget::setChapters(const Ffmpeg::Chapters &chapters)
}
d_ptr->slider->setNodes(nodes);
}
#endif

void ControlWidget::setPosition(int value)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#ifndef CONTROLWIDGET_HPP
#define CONTROLWIDGET_HPP

#ifdef MPV_ON
#include <mpv/mediainfo.hpp>
#else
#include <ffmpeg/mediainfo.hpp>
#endif

#include <QWidget>

Expand All @@ -17,8 +21,11 @@ class ControlWidget : public QWidget

void setDuration(int value);
[[nodiscard]] auto duration() const -> int;
#ifdef MPV_ON
void setChapters(const Mpv::Chapters &chapters);
#else
void setChapters(const Ffmpeg::Chapters &chapters);

#endif
[[nodiscard]] auto sliderGlobalPos() const -> QPoint;

void setSourceFPS(float fps);
Expand All @@ -27,6 +34,7 @@ class ControlWidget : public QWidget
void clickPlayButton();
void setPlayButtonChecked(bool checked);

void setVolumeMax(int max);
void setVolume(int value);
[[nodiscard]] auto volume() const -> int;

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 6 additions & 2 deletions examples/examples.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@ TEMPLATE = subdirs
CONFIG += ordered

SUBDIRS += \
player \
transcoder
ffmpegplayer \
ffmpegtranscoder

contains(CONFIG, BUILD_MPV) {
SUBDIRS += mpvplayer
}
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
set(PROJECT_SOURCES
../common/controlwidget.cc
../common/controlwidget.hpp
../common/openwebmediadialog.cc
../common/openwebmediadialog.hpp
../common/playlistmodel.cpp
../common/playlistmodel.h
../common/playlistview.cc
../common/playlistview.hpp
../common/qmediaplaylist_p.h
../common/qmediaplaylist.cpp
../common/qmediaplaylist.h
../common/qplaylistfileparser_p.h
../common/qplaylistfileparser.cpp
../common/slider.cpp
../common/slider.h
../common/titlewidget.cc
../common/titlewidget.hpp
colorspacedialog.cc
colorspacedialog.hpp
controlwidget.cc
controlwidget.hpp
main.cpp
mainwindow.cpp
mainwindow.h
openwebmediadialog.cc
openwebmediadialog.hpp
playlistmodel.cpp
playlistmodel.h
playlistview.cc
playlistview.hpp
qmediaplaylist_p.h
qmediaplaylist.cpp
qmediaplaylist.h
qplaylistfileparser_p.h
qplaylistfileparser.cpp
slider.cpp
slider.h
titlewidget.cc
titlewidget.hpp)
mainwindow.h)

qt_add_executable(Player MANUAL_FINALIZATION ${PROJECT_SOURCES})
qt_add_executable(FfmpegPlayer MANUAL_FINALIZATION ${PROJECT_SOURCES})
target_link_libraries(
Player
FfmpegPlayer
PRIVATE ffmpeg
thirdparty
dump
utils
Qt6::Widgets
Qt6::Multimedia
Qt6::OpenGLWidgets)
target_link_libraries(Player PRIVATE PkgConfig::ffmpeg)
target_link_libraries(FfmpegPlayer PRIVATE PkgConfig::ffmpeg)
if(CMAKE_HOST_APPLE)
target_link_libraries(
Player
FfmpegPlayer
PRIVATE ${Foundation_LIBRARY}
${CoreAudio_LIBRARY}
${AVFoundation_LIBRARY}
Expand All @@ -52,4 +52,4 @@ if(CMAKE_HOST_APPLE)
${CoreVideo_LIBRARY}
${CoreServices_LIBRARY})
endif()
qt_finalize_executable(Player)
qt_finalize_executable(FfmpegPlayer)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "colorspacedialog.hpp"
#include "slider.h"

#include <examples/common/slider.h>

#include <QtWidgets>

Expand Down
File renamed without changes.
43 changes: 43 additions & 0 deletions examples/ffmpegplayer/ffmpegplayer.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
include(../../common.pri)

QT += core gui widgets network multimedia openglwidgets core5compat

TEMPLATE = app

TARGET = FfmpegPlayer

LIBS += \
-l$$replaceLibName(ffmpeg) \
-l$$replaceLibName(thirdparty) \
-l$$replaceLibName(dump) \
-l$$replaceLibName(utils)

include(../../src/3rdparty/3rdparty.pri)

SOURCES += \
../common/controlwidget.cc \
../common/openwebmediadialog.cc \
../common/playlistmodel.cpp \
../common/playlistview.cc \
../common/qmediaplaylist.cpp \
../common/qplaylistfileparser.cpp \
../common/slider.cpp \
../common/titlewidget.cc \
colorspacedialog.cc \
main.cpp \
mainwindow.cpp

HEADERS += \
../common/controlwidget.hpp \
../common/openwebmediadialog.hpp \
../common/playlistmodel.h \
../common/playlistview.hpp \
../common/qmediaplaylist.h \
../common/qmediaplaylist_p.h \
../common/qplaylistfileparser_p.h \
../common/slider.h \
../common/titlewidget.hpp \
colorspacedialog.hpp \
mainwindow.h

DESTDIR = $$APP_OUTPUT_PATH
5 changes: 2 additions & 3 deletions examples/player/main.cpp → examples/ffmpegplayer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <3rdparty/qtsingleapplication/qtsingleapplication.h>
#include <dump/breakpad.hpp>
#include <examples/appinfo.hpp>
#include <ffmpeg/videorender/videorendercreate.hpp>
#include <utils/logasync.h>
#include <utils/utils.h>

Expand All @@ -12,7 +11,7 @@
#include <QNetworkProxyFactory>
#include <QStyle>

#define AppName "Player"
#define AppName "FfmpegPlayer"

void setAppInfo()
{
Expand All @@ -36,7 +35,7 @@ auto main(int argc, char *argv[]) -> int
#endif
Utils::setHighDpiEnvironmentVariable();

Ffmpeg::VideoRenderCreate::setSurfaceFormatVersion(3, 3);
Utils::setSurfaceFormatVersion(3, 3);

SharedTools::QtSingleApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
SharedTools::QtSingleApplication app(AppName, argc, argv);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include "mainwindow.h"
#include "colorspacedialog.hpp"
#include "controlwidget.hpp"
#include "openwebmediadialog.hpp"
#include "playlistmodel.h"
#include "playlistview.hpp"
#include "qmediaplaylist.h"
#include "titlewidget.hpp"

#include <examples/common/controlwidget.hpp>
#include <examples/common/openwebmediadialog.hpp>
#include <examples/common/playlistmodel.h>
#include <examples/common/playlistview.hpp>
#include <examples/common/qmediaplaylist.h>
#include <examples/common/titlewidget.hpp>
#include <ffmpeg/averror.h>
#include <ffmpeg/event/errorevent.hpp>
#include <ffmpeg/event/seekevent.hpp>
Expand Down Expand Up @@ -299,8 +299,7 @@ void MainWindow::onOpenLocalMedia()
{
const auto path = QStandardPaths::standardLocations(QStandardPaths::MoviesLocation)
.value(0, QDir::homePath());
const auto filter = tr("Media (*.mp4 *.flv *.ts *.avi *.rmvb *.mkv *.wmv *.mp3 *.wav *.flac "
"*.ape *.m4a *.aac *.ogg *.ac3 *.mpg)");
const auto filter = tr("Media (*)");
const auto urls = QFileDialog::getOpenFileUrls(this,
tr("Open Media"),
QUrl::fromUserInput(path),
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ set(PROJECT_SOURCES
videoencoderwidget.cc
videoencoderwidget.hpp)

qt_add_executable(Transcoder MANUAL_FINALIZATION ${PROJECT_SOURCES})
qt_add_executable(FfmpegTranscoder MANUAL_FINALIZATION ${PROJECT_SOURCES})
target_link_libraries(
Transcoder
FfmpegTranscoder
PRIVATE ffmpeg
thirdparty
dump
utils
Qt6::Widgets
Qt6::Multimedia
Qt6::OpenGLWidgets)
target_link_libraries(Transcoder PRIVATE PkgConfig::ffmpeg)
target_link_libraries(FfmpegTranscoder PRIVATE PkgConfig::ffmpeg)

if(CMAKE_HOST_APPLE)
target_link_libraries(
Transcoder
FfmpegTranscoder
PRIVATE ${Foundation_LIBRARY}
${CoreAudio_LIBRARY}
${AVFoundation_LIBRARY}
Expand All @@ -61,4 +61,4 @@ if(CMAKE_HOST_APPLE)
${CoreServices_LIBRARY})
endif()

qt_finalize_executable(Transcoder)
qt_finalize_executable(FfmpegTranscoder)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ QT += core gui widgets network multimedia openglwidgets core5compat

TEMPLATE = app

TARGET = Transcoder
TARGET = FfmpegTranscoder

LIBS += \
-l$$replaceLibName(ffmpeg) \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <QNetworkProxyFactory>
#include <QStyle>

#define AppName "Transcoder"
#define AppName "FfmpegTranscoderr"

void setAppInfo()
{
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 1891851

Please sign in to comment.