Skip to content

Commit

Permalink
色域转换;
Browse files Browse the repository at this point in the history
  • Loading branch information
RealChuan committed Nov 21, 2023
1 parent aba6939 commit b51ff04
Show file tree
Hide file tree
Showing 21 changed files with 567 additions and 206 deletions.
21 changes: 7 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,16 @@
2. 在WidgetRender中,尽可能使用QImage::Format_RGB32和QImage::Format_ARGB32_Premultiplied图像格式。如下原因:
1. Avoid most rendering directly to most of these formats using QPainter. Rendering is best optimized to the Format_RGB32 and Format_ARGB32_Premultiplied formats, and secondarily for rendering to the Format_RGB16, Format_RGBX8888, Format_RGBA8888_Premultiplied, Format_RGBX64 and Format_RGBA64_Premultiplied formats.

### 如何根据AVColorPrimaries、AVColorTransferCharacteristic、AVColorSpace调整图像?
### AVFrame 图像调整

1. 根据`AVColorSpace`进行色彩空间转换;
2. 根据`AVColorTransferCharacteristic`进行gamma、PQ、HLG等调整;
3. 根据`AVColorPrimaries`进行色域转换;
4. 根据`AVColorRange`进行色彩范围调整;

#### 1. opengl 渲染的情况下,该怎么样修改shader?

1. 参考[MPV video_shaders](https://github.com/mpv-player/mpv/blob/master/video/out/gpu/video_shaders.c),效果也不是很好;应该是哪里有遗漏。
2. HDR metadata获取

```cpp
AVFrameSideData *mdm = av_frame_get_side_data(src, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA);
AVFrameSideData *clm = av_frame_get_side_data(src, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL);
AVFrameSideData *dhp = av_frame_get_side_data(src, AV_FRAME_DATA_DYNAMIC_HDR_PLUS);
pl_map_hdr_metadata(&dst->params.color.hdr, &(struct pl_av_hdr_metadata) {
.mdm = (void *)(mdm ? mdm->data : NULL),
.clm = (void *)(clm ? clm->data : NULL),
.dhp = (void *)(dhp ? dhp->data : NULL),
});
```
1. 参考[MPV video_shaders](https://github.com/mpv-player/mpv/blob/master/video/out/gpu/video_shaders.c)

#### 2. 非opengl渲染的情况下,又该怎么样添加filter实现图像补偿?

Expand Down
2 changes: 1 addition & 1 deletion examples/player/colorspacedialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ColorSpaceDialog : public QDialog
~ColorSpaceDialog() override;

void setColorSpace(const Ffmpeg::ColorSpaceTrc &colorTrc);
[[nodiscard]] Ffmpeg::ColorSpaceTrc colorSpace() const;
[[nodiscard]] auto colorSpace() const -> Ffmpeg::ColorSpaceTrc;

signals:
void colorSpaceChanged();
Expand Down
77 changes: 59 additions & 18 deletions examples/player/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class MainWindow::MainWindowPrivate
controlWidget->setVisible(visible);
}

bool setTitleWidgetVisible(bool visible)
auto setTitleWidgetVisible(bool visible) -> bool
{
if (videoRender.isNull()) {
return false;
Expand Down Expand Up @@ -203,6 +203,7 @@ class MainWindow::MainWindowPrivate
QSplitter *splitter;

Ffmpeg::Tonemap::Type tonemapType = Ffmpeg::Tonemap::Type::AUTO;
Ffmpeg::ColorUtils::Primaries::Type primarisType = Ffmpeg::ColorUtils::Primaries::Type::AUTO;
};

MainWindow::MainWindow(QWidget *parent)
Expand Down Expand Up @@ -325,6 +326,7 @@ void MainWindow::onRenderChanged(QAction *action)
// 为什么切换成widget还是有使用GPU 0-3D,而且使用量是切换为opengl的两倍!!!
d_ptr->videoRender.reset(videoRender);
d_ptr->videoRender->setTonemapType(d_ptr->tonemapType);
d_ptr->videoRender->setDestPrimaries(d_ptr->primarisType);
}

void MainWindow::playlistPositionChanged(int currentItem)
Expand Down Expand Up @@ -453,7 +455,7 @@ void MainWindow::onProcessEvents()
}
}

bool MainWindow::eventFilter(QObject *watched, QEvent *event)
auto MainWindow::eventFilter(QObject *watched, QEvent *event) -> bool
{
if (!d_ptr->videoRender.isNull() && watched == d_ptr->videoRender->widget()) {
switch (event->type()) {
Expand Down Expand Up @@ -621,6 +623,29 @@ void MainWindow::initMenu()
connect(colorSpaceAction, &QAction::triggered, this, &MainWindow::onShowColorSpace);
d_ptr->menu->addAction(colorSpaceAction);

tonemapMenu();
destPrimarisMenu();
renderMenu();

connect(d_ptr->audioTracksGroup, &QActionGroup::triggered, this, [this](QAction *action) {
d_ptr->playerPtr->addEvent(
Ffmpeg::EventPtr(new Ffmpeg::SelectedMediaTrackEvent(action->property("index").toInt(),
Ffmpeg::Event::AudioTarck)));
});
connect(d_ptr->videoTracksGroup, &QActionGroup::triggered, this, [this](QAction *action) {
d_ptr->playerPtr->addEvent(
Ffmpeg::EventPtr(new Ffmpeg::SelectedMediaTrackEvent(action->property("index").toInt(),
Ffmpeg::Event::VideoTrack)));
});
connect(d_ptr->subTracksGroup, &QActionGroup::triggered, this, [this](QAction *action) {
d_ptr->playerPtr->addEvent(
Ffmpeg::EventPtr(new Ffmpeg::SelectedMediaTrackEvent(action->property("index").toInt(),
Ffmpeg::Event::SubtitleTrack)));
});
}

void MainWindow::tonemapMenu()
{
auto *tonemapGroup = new QActionGroup(this);
tonemapGroup->setExclusive(true);
auto *tonemapMenu = new QMenu(tr("Tonemap"), this);
Expand All @@ -645,7 +670,39 @@ void MainWindow::initMenu()
d_ptr->videoRender->setTonemapType(d_ptr->tonemapType);
});
tonemapGroup->checkedAction()->trigger();
}

void MainWindow::destPrimarisMenu()
{
auto *destPrimarisGroup = new QActionGroup(this);
destPrimarisGroup->setExclusive(true);
auto *destPrimarisMenu = new QMenu(tr("Dest Primaris"), this);
auto destPrimaris = QMetaEnum::fromType<Ffmpeg::ColorUtils::Primaries::Type>();
for (int i = 0; i < destPrimaris.keyCount(); ++i) {
auto value = destPrimaris.value(i);
auto *action = new QAction(destPrimaris.key(i), this);
action->setCheckable(true);
action->setData(value);
destPrimarisGroup->addAction(action);
destPrimarisMenu->addAction(action);
if (value == Ffmpeg::ColorUtils::Primaries::Type::AUTO) {
action->setChecked(true);
}
}
d_ptr->menu->addMenu(destPrimarisMenu);
connect(destPrimarisGroup, &QActionGroup::triggered, this, [this](QAction *action) {
d_ptr->primarisType = static_cast<Ffmpeg::ColorUtils::Primaries::Type>(
action->data().toInt());
if (d_ptr->videoRender.isNull()) {
return;
}
d_ptr->videoRender->setDestPrimaries(d_ptr->primarisType);
});
destPrimarisGroup->checkedAction()->trigger();
}

void MainWindow::renderMenu()
{
auto *widgetAction = new QAction(tr("Widget"), this);
widgetAction->setCheckable(true);
widgetAction->setData(Ffmpeg::VideoRenderCreate::Widget);
Expand All @@ -668,22 +725,6 @@ void MainWindow::initMenu()
renderMenu->addAction(widgetAction);
renderMenu->addAction(openglAction);
d_ptr->menu->addMenu(renderMenu);

connect(d_ptr->audioTracksGroup, &QActionGroup::triggered, this, [this](QAction *action) {
d_ptr->playerPtr->addEvent(
Ffmpeg::EventPtr(new Ffmpeg::SelectedMediaTrackEvent(action->property("index").toInt(),
Ffmpeg::Event::AudioTarck)));
});
connect(d_ptr->videoTracksGroup, &QActionGroup::triggered, this, [this](QAction *action) {
d_ptr->playerPtr->addEvent(
Ffmpeg::EventPtr(new Ffmpeg::SelectedMediaTrackEvent(action->property("index").toInt(),
Ffmpeg::Event::VideoTrack)));
});
connect(d_ptr->subTracksGroup, &QActionGroup::triggered, this, [this](QAction *action) {
d_ptr->playerPtr->addEvent(
Ffmpeg::EventPtr(new Ffmpeg::SelectedMediaTrackEvent(action->property("index").toInt(),
Ffmpeg::Event::SubtitleTrack)));
});
}

void MainWindow::initPlayListMenu()
Expand Down
3 changes: 3 additions & 0 deletions examples/player/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ private slots:
void setupUI();
void buildConnect();
void initMenu();
void tonemapMenu();
void destPrimarisMenu();
void renderMenu();
void initPlayListMenu();
void addToPlaylist(const QList<QUrl> &urls);

Expand Down
4 changes: 2 additions & 2 deletions ffmpeg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ set(PROJECT_SOURCES
clock.hpp
codeccontext.cpp
codeccontext.h
colorspace.cc
colorspace.hpp
colorutils.cc
colorutils.hpp
decoder.cc
decoder.h
ffmepg_global.h
Expand Down
117 changes: 0 additions & 117 deletions ffmpeg/colorspace.cc

This file was deleted.

25 changes: 0 additions & 25 deletions ffmpeg/colorspace.hpp

This file was deleted.

Loading

0 comments on commit b51ff04

Please sign in to comment.