Skip to content

Commit

Permalink
[功能更新与优化] 统一跨平台播放器控件实现,并新增基于 Qt 的 QPlayer 示例。
Browse files Browse the repository at this point in the history
- 更新了`.github/actions/install-dependencies/action.yml`文件,将Qt版本从`6.8.0`升级到`6.8.1`。
- 在`CMakeLists.txt`中添加了`include(cmake/build_info.cmake)`,以便构建时包含构建信息。
- 更新了`README.en.md`和`README.md`文件,修改了字幕处理函数的名称,并添加了QPlayer的参考链接。
- 修改了`cmake/qt.cmake`文件,更新了Qt的安装路径,以匹配新版本的Qt。
- 添加了新目录`examples/qplayer`,用于构建基于Qt的媒体播放器示例。
- 在`examples/CMakeLists.txt`中添加了对`qplayer`目录的支持。
- 在`examples/ffmpegplayer`和`examples/ffmpegtranscoder`目录中,更新了CMakeLists.txt文件,添加了对`commonstr.hpp`的引用,并更新了Qt模块的引用。
- 在`examples/mpvplayer`目录中,更新了CMakeLists.txt和相关源文件,以使用新的Qt模块引用。
- 在`src/3rdparty/`、`src/dump/`、`src/ffmpeg/`、`src/mediaconfig/`、`src/mpv/`、`src/utils/`目录中,更新了CMakeLists.txt文件,将Qt6的模块引用更新为Qt的模块引用。
- 更新了`scripts/windows/setVsDev.ps1`脚本,以支持不同架构的Visual Studio开发环境设置。
- 更新了`vcpkg.json`文件,调整了FFmpeg的特征配置。
  • Loading branch information
RealChuan committed Dec 30, 2024
1 parent 14df42c commit b537102
Show file tree
Hide file tree
Showing 45 changed files with 1,172 additions and 307 deletions.
2 changes: 1 addition & 1 deletion .github/actions/install-dependencies/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ inputs:
qt_ver:
description: 'qt version'
required: false
default: '6.8.0'
default: '6.8.1'
type: string

runs:
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,5 @@ include_directories(src)
add_subdirectory(src)
add_subdirectory(tests)
add_subdirectory(examples)

include(cmake/build_info.cmake)
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,6 @@ transcodeCtx->audioPts += frame->nb_samples;
qt.dbus.integration: Could not connect "org.freedesktop.IBus" to globalEngineChanged(QString)
```

- 在Windows和Unix下,ControlWidget和TitleWidget的控制方式不同

1. Windows下使用 `mpv_set_property(d_ptr->mpv, "wid", MPV_FORMAT_INT64, &wid);`,使用layout布局,会使得视频窗口在最前面,遮挡ControlWidget和TitleWidget,所以将ControlWidget和TitleWidget悬浮在视频窗口上方,使用 `eventFilter`去处理大部分情况下ControlWidget和TitleWidget的显示,写的非常啰嗦,但是为了能够使用D3D11渲染,更棒的性能,只能这样处理,也是值得的;
2. Unix下使用QOpenGLWidget,使用layout布局更加方便;

- MacOS打包需要[install_name_tool](/mac/change_lib_dependencies.rb),依赖拷贝脚本文件来自[iina](https://github.com/iina/iina/blob/develop/other/change_lib_dependencies.rb);

**当前 `brew`安装的 `mpv`中,`libmpv.dylib`的依赖是 `@loader_path/`,所以对脚本进行了一些修改;**
Expand All @@ -125,6 +120,10 @@ transcodeCtx->audioPts += frame->nb_samples;

依赖会拷贝到 `packet/Qt-Mpv.app/Contents/Frameworks/`

# QPlayer

- 参考 [Media Player Example](https://doc.qt.io/qt-6/qtmultimedia-player-example.html)

## QT-BUG

- 动态切换Video Render,从opengl切换到widget,还是有GPU 0-3D占用,而且使用量是opengl的2倍!!!QT-BUG?
Expand Down
6 changes: 4 additions & 2 deletions cmake/qt.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
if(CMAKE_HOST_WIN32)
list(APPEND CMAKE_PREFIX_PATH "C:\\Qt\\6.8.0\\msvc2022_64")
list(APPEND CMAKE_PREFIX_PATH "C:\\Qt\\6.8.1\\msvc2022_64")
elseif(CMAKE_HOST_APPLE)

elseif(CMAKE_HOST_LINUX)
list(APPEND CMAKE_PREFIX_PATH "/opt/Qt/6.8.0/gcc_64")
list(APPEND CMAKE_PREFIX_PATH "/opt/Qt/6.8.1/gcc_64")
endif()

add_definitions(-DQT_DEPRECATED_WARNINGS)
1 change: 1 addition & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
add_subdirectory(ffmpegplayer)
add_subdirectory(ffmpegtranscoder)
add_subdirectory(qplayer)

if(BUILD_MPV)
add_subdirectory(mpvplayer)
Expand Down
12 changes: 12 additions & 0 deletions examples/common/commonstr.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include <QCoreApplication>

namespace Common {

struct Tr
{
Q_DECLARE_TR_FUNCTIONS(Common)
};

} // namespace Common
7 changes: 2 additions & 5 deletions examples/common/controlwidget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,6 @@ ControlWidget::ControlWidget(QWidget *parent)
: QWidget{parent}
, d_ptr(new ControlWidgetPrivate(this))
{
setWindowFlags(windowFlags() | Qt::FramelessWindowHint | Qt::Tool);
setAttribute(Qt::WA_TranslucentBackground); //设置窗口背景透明

d_ptr->setupUI();
buildConnect();
d_ptr->initModelButton();
Expand Down Expand Up @@ -213,7 +210,7 @@ void ControlWidget::setDuration(int value)
setPosition(0);
}

#ifdef MPV_ON
#if defined(MPV_ON)
void ControlWidget::setChapters(const Mpv::Chapters &chapters)
{
QVector<qint64> nodes;
Expand All @@ -222,7 +219,7 @@ void ControlWidget::setChapters(const Mpv::Chapters &chapters)
}
d_ptr->slider->setNodes(nodes);
}
#else
#elif defined(FFMPEG_ON)
void ControlWidget::setChapters(const Ffmpeg::Chapters &chapters)
{
QVector<qint64> nodes;
Expand Down
8 changes: 4 additions & 4 deletions examples/common/controlwidget.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef CONTROLWIDGET_HPP
#define CONTROLWIDGET_HPP

#ifdef MPV_ON
#if defined(MPV_ON)
#include <mpv/mediainfo.hpp>
#else
#elif defined(FFMPEG_ON)
#include <ffmpeg/mediainfo.hpp>
#endif

Expand All @@ -21,9 +21,9 @@ class ControlWidget : public QWidget

void setDuration(int value);
[[nodiscard]] auto duration() const -> int;
#ifdef MPV_ON
#if defined(MPV_ON)
void setChapters(const Mpv::Chapters &chapters);
#else
#elif defined(FFMPEG_ON)
void setChapters(const Ffmpeg::Chapters &chapters);
#endif
[[nodiscard]] auto sliderGlobalPos() const -> QPoint;
Expand Down
2 changes: 0 additions & 2 deletions examples/common/titlewidget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ TitleWidget::TitleWidget(QWidget *parent)
: QWidget{parent}
, d_ptr(new TitleWidgetPrivate(this))
{
setWindowFlags(windowFlags() | Qt::FramelessWindowHint | Qt::Tool);
setAttribute(Qt::WA_TranslucentBackground);

setupUI();
buildConnect();
Expand Down
3 changes: 2 additions & 1 deletion examples/examples.pro
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ CONFIG += ordered

SUBDIRS += \
ffmpegplayer \
ffmpegtranscoder
ffmpegtranscoder \
qplayer

win32 {
exists("C:/3rd/x64/mpv/include"){
Expand Down
8 changes: 5 additions & 3 deletions examples/ffmpegplayer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
set(PROJECT_SOURCES
../common/commonstr.hpp
../common/controlwidget.cc
../common/controlwidget.hpp
../common/equalizerdialog.cpp
Expand All @@ -24,16 +25,17 @@ set(PROJECT_SOURCES
mainwindow.h)

qt_add_executable(FfmpegPlayer MANUAL_FINALIZATION ${PROJECT_SOURCES})
target_compile_definitions(FfmpegPlayer PRIVATE "FFMPEG_ON")
target_link_libraries(
FfmpegPlayer
PRIVATE ffmpeg
mediaconfig
thirdparty
dump
utils
Qt6::Widgets
Qt6::Multimedia
Qt6::OpenGLWidgets)
Qt::Widgets
Qt::Multimedia
Qt::OpenGLWidgets)
target_link_libraries(FfmpegPlayer PRIVATE PkgConfig::ffmpeg)
if(CMAKE_HOST_APPLE)
target_link_libraries(
Expand Down
3 changes: 3 additions & 0 deletions examples/ffmpegplayer/ffmpegplayer.pro
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ TEMPLATE = app

TARGET = FfmpegPlayer

DEFINES += FFMPEG_ON

LIBS += \
-l$$replaceLibName(ffmpeg) \
-l$$replaceLibName(mediaconfig) \
Expand All @@ -30,6 +32,7 @@ SOURCES += \
mainwindow.cpp

HEADERS += \
../common/commonstr.hpp \
../common/controlwidget.hpp \
../common/equalizerdialog.h \
../common/openwebmediadialog.hpp \
Expand Down
Loading

0 comments on commit b537102

Please sign in to comment.