Skip to content

Commit

Permalink
libplaceboのcustom shaderを使用したフィルタを追加。 (--vpp-libplacebo-shader, #623)
Browse files Browse the repository at this point in the history
  • Loading branch information
rigaya committed Oct 26, 2024
1 parent 440c6cf commit 2e5d754
Show file tree
Hide file tree
Showing 10 changed files with 849 additions and 21 deletions.
65 changes: 64 additions & 1 deletion NVEncC_Options.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
- [--vpp-pmd \[\<param1\>=\<value1\>\]\[,\<param2\>=\<value2\>\],...](#--vpp-pmd-param1value1param2value2)
- [--vpp-gauss \<int\>](#--vpp-gauss-int)
- [--vpp-subburn \[\<param1\>=\<value1\>\]\[,\<param2\>=\<value2\>\],...](#--vpp-subburn-param1value1param2value2)
- [--vpp-libplacebo-shader \[\<param1\>=\<value1\>\]\[,\<param2\>=\<value2\>\],...](#--vpp-libplacebo-shader-param1value1param2value2)
- [--vpp-resize \<string\> or \[\<param1\>=\<value1\>\]\[,\<param2\>=\<value2\>\],...](#--vpp-resize-string-or-param1value1param2value2)
- [--vpp-unsharp \[\<param1\>=\<value1\>\]\[,\<param2\>=\<value2\>\],...](#--vpp-unsharp-param1value1param2value2)
- [--vpp-edgelevel \[\<param1\>=\<value1\>\]\[,\<param2\>=\<value2\>\],...](#--vpp-edgelevel-param1value1param2value2)
Expand Down Expand Up @@ -1655,6 +1656,7 @@ Vpp filters will be applied in fixed order, regardless of the order in the comma
- [--vpp-pmd](#--vpp-pmd-param1value1param2value2)
- [--vpp-gauss](#--vpp-gauss-int)
- [--vpp-subburn](#--vpp-subburn-param1value1param2value2)
- [--vpp-libplacebo-shader](#--vpp-libplacebo-shader-param1value1param2value2)
- [--vpp-resize](#--vpp-resize-string-or-param1value1param2value2)
- [--vpp-unsharp](#--vpp-unsharp-param1value1param2value2)
- [--vpp-edgelevel](#--vpp-edgelevel-param1value1param2value2)
Expand Down Expand Up @@ -2551,6 +2553,68 @@ The npp dlls can be downloaded from [this link](https://github.com/rigaya/NVEnc/
--vpp-subburn filename="subtitle.sjis.ass",charcode=sjis,shaping=complex
```
### --vpp-libplacebo-shader [&lt;param1&gt;=&lt;value1&gt;][,&lt;param2&gt;=&lt;value2&gt;],...
Apply custom shaders in the specified path using [libplacebo](https://code.videolan.org/videolan/libplacebo).
- **Parameters**
- shader=&lt;string&gt;
Target shader file path.
- res=&lt;int&gt;x&lt;int&gt;
Output resolution of the filter.
- colorsystem=&lt;int&gt;
Color system to use. Default: bt709.
```
unknown, bt601, bt709, smpte240m, bt2020nc, bt2020c, bt2100pq, bt2100hlg, dolbyvision, ycgco, rgb, xyz
```
- transfer=&lt;string&gt;
Output transfer function.
```
unknown, srgb, bt1886, linear,
gamma18, gamma20, gamma22, gamma24, gamma26, gamma28,
prophoto, st428, pq, hlg, vlog, slog1, slog2
```
- resampler=&lt;string&gt;
Filter function to use when resample is required. Default: libplacebo-ewa-lanczos.
```
libplacebo-spline16, libplacebo-spline36, libplacebo-spline64, libplacebo-nearest,
libplacebo-bilinear, libplacebo-gaussian, libplacebo-sinc, libplacebo-lanczos,
libplacebo-ginseng, libplacebo-ewa-jinc, libplacebo-ewa-lanczos,
libplacebo-ewa-lanczossharp, libplacebo-ewa-lanczos4sharpest,
libplacebo-ewa-ginseng, libplacebo-ewa-hann, libplacebo-ewa-hanning,
libplacebo-bicubic, libplacebo-triangle, libplacebo-hermite, libplacebo-catmull-rom,
libplacebo-mitchell, libplacebo-mitchell-clamp, libplacebo-robidoux,
libplacebo-robidouxsharp, libplacebo-ewa-robidoux, libplacebo-ewa-robidouxsharp
```
- radius=&lt;float&gt;
Adjust the function's radius. Default: auto. Must be between 0.0 and 16.0.
- clamp=&lt;float&gt;
Clamping coefficient for negative weights. Default: 0.0. Must be between 0.0 and 1.0.
- taper=&lt;float&gt;
Additional taper coefficient. Default: 0.0. Must be between 0.0 and 1.0.
- blur=&lt;float&gt;
Additional blur coefficient. Default: 0.0. Must be between 0.0 and 100.0.
- antiring=&lt;float&gt;
Antiringing strength. Default: 0.0. Must be between 0.0 and 1.0.
- linear=&lt;bool&gt;
linearize image bdfore processing.
- **Examples**
```
Example: Apply a custom shader with specific parameters
--vpp-libplacebo-shader-params
```
### --vpp-resize &lt;string&gt; or [&lt;param1&gt;=&lt;value1&gt;][,&lt;param2&gt;=&lt;value2&gt;],...
Specify the resizing algorithm.
Expand Down Expand Up @@ -2691,7 +2755,6 @@ Specify the resizing algorithm.
--vpp-resize algo=libplacebo-sinc,pl-radius=3.0,pl-antiring=0.5
```
### --vpp-unsharp [&lt;param1&gt;=&lt;value1&gt;][,&lt;param2&gt;=&lt;value2&gt;],...
unsharp filter, for edge and detail enhancement.
Expand Down
64 changes: 64 additions & 0 deletions NVEncC_Options.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@
- [--vpp-pmd \[\<param1\>=\<value1\>\]\[,\<param2\>=\<value2\>\],...](#--vpp-pmd-param1value1param2value2)
- [--vpp-gauss \<int\>](#--vpp-gauss-int)
- [--vpp-subburn \[\<param1\>=\<value1\>\]\[,\<param2\>=\<value2\>\],...](#--vpp-subburn-param1value1param2value2)
- [--vpp-libplacebo-shader \[\<param1\>=\<value1\>\]\[,\<param2\>=\<value2\>\],...](#--vpp-libplacebo-shader-param1value1param2value2)
- [--vpp-resize \<string\> or \[\<param1\>=\<value1\>\]\[,\<param2\>=\<value2\>\],...](#--vpp-resize-string-or-param1value1param2value2)
- [--vpp-unsharp \[\<param1\>=\<value1\>\]\[,\<param2\>=\<value2\>\],...](#--vpp-unsharp-param1value1param2value2)
- [--vpp-edgelevel \[\<param1\>=\<value1\>\]\[,\<param2\>=\<value2\>\],...](#--vpp-edgelevel-param1value1param2value2)
Expand Down Expand Up @@ -1649,6 +1650,7 @@ vppフィルタの適用順は固定で、コマンドラインの順序によ
- [--vpp-pmd](#--vpp-pmd-param1value1param2value2)
- [--vpp-gauss](#--vpp-gauss-int)
- [--vpp-subburn](#--vpp-subburn-param1value1param2value2)
- [--vpp-libplacebo-shader](#--vpp-libplacebo-shader-param1value1param2value2)
- [--vpp-resize](#--vpp-resize-string-or-param1value1param2value2)
- [--vpp-unsharp](#--vpp-unsharp-param1value1param2value2)
- [--vpp-edgelevel](#--vpp-edgelevel-param1value1param2value2)
Expand Down Expand Up @@ -2608,6 +2610,68 @@ nppc64_10.dll, nppif64_10.dll, nppig64_10.dllをNVEncC64と同じフォルダに
例3: Shift-JISな文字コードのassファイルの焼きこみ
--vpp-subburn filename="subtitle.sjis.ass",charcode=sjis,shaping=complex
```
### --vpp-libplacebo-shader [&lt;param1&gt;=&lt;value1&gt;][,&lt;param2&gt;=&lt;value2&gt;],...
[libplacebo](https://code.videolan.org/videolan/libplacebo)を使用して指定されたパスのカスタムシェーダーを適用します。
- **パラメータ**
- shader=&lt;string&gt;
対象のshaderファイルのパス。
- res=&lt;int&gt;x&lt;int&gt;
フィルタの出力解像度。
- colorsystem=&lt;int&gt;
使用する色空間を指定。デフォルトはbt709。
```
unknown, bt601, bt709, smpte240m, bt2020nc, bt2020c, bt2100pq, bt2100hlg, dolbyvision, ycgco, rgb, xyz
```
- transfer=&lt;string&gt;
出力のトランスファ関数を指定。
```
unknown, srgb, bt1886, linear,
gamma18, gamma20, gamma22, gamma24, gamma26, gamma28,
prophoto, st428, pq, hlg, vlog, slog1, slog2
```
- resampler=&lt;string&gt;
リサンプルが必要な場合に使用するフィルタ関数を指定。デフォルトは libplacebo-ewa-lanczos 。
```
libplacebo-spline16, libplacebo-spline36, libplacebo-spline64, libplacebo-nearest,
libplacebo-bilinear, libplacebo-gaussian, libplacebo-sinc, libplacebo-lanczos,
libplacebo-ginseng, libplacebo-ewa-jinc, libplacebo-ewa-lanczos,
libplacebo-ewa-lanczossharp, libplacebo-ewa-lanczos4sharpest,
libplacebo-ewa-ginseng, libplacebo-ewa-hann, libplacebo-ewa-hanning,
libplacebo-bicubic, libplacebo-triangle, libplacebo-hermite, libplacebo-catmull-rom,
libplacebo-mitchell, libplacebo-mitchell-clamp, libplacebo-robidoux,
libplacebo-robidouxsharp, libplacebo-ewa-robidoux, libplacebo-ewa-robidouxsharp
```
- radius=&lt;float&gt;
Adjust the function's radius. Default: auto. Must be between 0.0 and 16.0.
- clamp=&lt;float&gt;
Clamping coefficient for negative weights. Default: 0.0. Must be between 0.0 and 1.0.
- taper=&lt;float&gt;
Additional taper coefficient. Default: 0.0. Must be between 0.0 and 1.0.
- blur=&lt;float&gt;
Additional blur coefficient. Default: 0.0. Must be between 0.0 and 100.0.
- antiring=&lt;float&gt;
Antiringing strength. Default: 0.0. Must be between 0.0 and 1.0.
- linear=&lt;bool&gt;
linearize image before processing.
- 使用例
```
Example: Apply a custom shader with specific parameters
--vpp-libplacebo-shader-params
```
### --vpp-resize &lt;string&gt; or [&lt;param1&gt;=&lt;value1&gt;][,&lt;param2&gt;=&lt;value2&gt;],...
リサイズのアルゴリズムを指定する。
Expand Down
57 changes: 43 additions & 14 deletions NVEncCore/NVEncCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1422,6 +1422,7 @@ bool NVEncCore::enableCuvidResize(const InEncodeVideoParam *inputParam) {
|| inputParam->vpp.colorspace.enable
|| inputParam->vpp.libplacebo_tonemapping.enable
|| inputParam->vpp.subburn.size() > 0
|| inputParam->vpp.libplacebo_shader.size() > 0
|| inputParam->vpp.pad.enable
|| inputParam->vpp.selectevery.enable
|| inputParam->vpp.decimate.enable
Expand Down Expand Up @@ -2329,28 +2330,21 @@ RGY_ERR NVEncCore::InitFilters(const InEncodeVideoParam *inputParam) {
}

//リサイザの出力すべきサイズ
int resizeWidth = croppedWidth;
int resizeHeight = croppedHeight;
m_uEncWidth = resizeWidth;
m_uEncHeight = resizeHeight;
if (inputParam->vpp.pad.enable) {
m_uEncWidth += inputParam->vpp.pad.right + inputParam->vpp.pad.left;
m_uEncHeight += inputParam->vpp.pad.bottom + inputParam->vpp.pad.top;
}
int resizeWidth = 0;
int resizeHeight = 0;

//指定のリサイズがあればそのサイズに設定する
if (inputParam->input.dstWidth > 0 && inputParam->input.dstHeight > 0) {
m_uEncWidth = inputParam->input.dstWidth;
m_uEncHeight = inputParam->input.dstHeight;
resizeWidth = m_uEncWidth;
resizeHeight = m_uEncHeight;
resizeWidth = inputParam->input.dstWidth;
resizeHeight = inputParam->input.dstHeight;
if (inputParam->vpp.pad.enable) {
resizeWidth -= (inputParam->vpp.pad.right + inputParam->vpp.pad.left);
resizeHeight -= (inputParam->vpp.pad.bottom + inputParam->vpp.pad.top);
}
}
bool resizeRequired = false;
if (croppedWidth != resizeWidth || croppedHeight != resizeHeight) {
if ((resizeWidth > 0 && resizeHeight > 0) &&
(croppedWidth != resizeWidth || croppedHeight != resizeHeight)) {
resizeRequired = true;
}
//avhw読みではデコード直後にリサイズが可能
Expand Down Expand Up @@ -2424,6 +2418,7 @@ RGY_ERR NVEncCore::InitFilters(const InEncodeVideoParam *inputParam) {
|| inputParam->vpp.libplacebo_tonemapping.enable
|| inputParam->vpp.pad.enable
|| inputParam->vpp.subburn.size() > 0
|| inputParam->vpp.libplacebo_shader.size() > 0
|| inputParam->vpp.rff.enable
|| inputParam->vpp.decimate.enable
|| inputParam->vpp.mpdecimate.enable
Expand Down Expand Up @@ -3088,8 +3083,40 @@ RGY_ERR NVEncCore::InitFilters(const InEncodeVideoParam *inputParam) {
return RGY_ERR_UNSUPPORTED;
#endif
}
//libplacebo-shader
for (const auto& shader : inputParam->vpp.libplacebo_shader) {
unique_ptr<NVEncFilter> filter(new NVEncFilterLibplaceboShader());
shared_ptr<NVEncFilterParamLibplaceboShader> param(new NVEncFilterParamLibplaceboShader());
param->shader = shader;
param->frameIn = inputFrame;
param->frameOut = inputFrame;
if (shader.width > 0) {
param->frameOut.width = shader.width;
}
if (shader.height > 0) {
param->frameOut.height = shader.height;
}
param->dx11 = m_dev->dx11();
param->vk = m_dev->vulkan();
param->baseFps = m_encFps;
param->bOutOverwrite = false;
NVEncCtxAutoLock(cxtlock(m_dev->vidCtxLock()));
auto sts = filter->init(param, m_pNVLog);
if (sts != RGY_ERR_NONE) {
return sts;
}
//フィルタチェーンに追加
m_vpFilters.push_back(std::move(filter));
//パラメータ情報を更新
m_pLastFilterParam = std::dynamic_pointer_cast<NVEncFilterParam>(param);
//入力フレーム情報を更新
inputFrame = param->frameOut;
m_encFps = param->baseFps;
}

//リサイズ
if (resizeRequired) {
if (resizeWidth > 0 && resizeHeight > 0 &&
(inputFrame.width != resizeWidth || inputFrame.height != resizeHeight)) {
unique_ptr<NVEncFilter> filterCrop(new NVEncFilterResize());
shared_ptr<NVEncFilterParamResize> param(new NVEncFilterParamResize());
if (inputParam->vpp.resize_algo == RGY_VPP_RESIZE_AUTO) {
Expand Down Expand Up @@ -3471,6 +3498,8 @@ RGY_ERR NVEncCore::InitFilters(const InEncodeVideoParam *inputParam) {
filter->setCheckPerformance(inputParam->vpp.checkPerformance);
}
}
m_uEncWidth = inputFrame.width;
m_uEncHeight = inputFrame.height;
m_encVUI = inputParam->common.out_vui;
if (m_rgbAsYUV444) {
m_encVUI.descriptpresent = 1;
Expand Down
Loading

0 comments on commit 2e5d754

Please sign in to comment.