Skip to content

Commit

Permalink
画像を焼き込むフィルタを追加。 ( --vpp-overlay, #444 )
Browse files Browse the repository at this point in the history
  • Loading branch information
rigaya committed Jan 15, 2023
1 parent 00e21df commit 3426bf7
Show file tree
Hide file tree
Showing 13 changed files with 1,316 additions and 6 deletions.
22 changes: 22 additions & 0 deletions NVEncC_Options.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@
- [--vpp-edgelevel \[\<param1\>=\<value1\>\]\[,\<param2\>=\<value2\>\],...](#--vpp-edgelevel-param1value1param2value2)
- [--vpp-warpsharp \[\<param1\>=\<value1\>\]\[,\<param2\>=\<value2\>\],...](#--vpp-warpsharp-param1value1param2value2)
- [--vpp-tweak \[\<param1\>=\<value1\>\]\[,\<param2\>=\<value2\>\],...](#--vpp-tweak-param1value1param2value2)
- [--vpp-overlay \[\<param1\>=\<value1\>\]\[,\<param2\>=\<value2\>\],...](#--vpp-overlay-param1value1param2value2)
- [--vpp-deband \[\<param1\>=\<value1\>\]\[,\<param2\>=\<value2\>\],...](#--vpp-deband-param1value1param2value2)
- [--vpp-pad \<int\>,\<int\>,\<int\>,\<int\>](#--vpp-pad-intintintint)
- [--vpp-perf-monitor](#--vpp-perf-monitor)
Expand Down Expand Up @@ -1478,6 +1479,7 @@ Vpp filters will be applied in fixed order, regardless of the order in the comma
- [--vpp-edgelevel](#--vpp-edgelevel-param1value1param2value2)
- [--vpp-warpsharp](#--vpp-warpsharp-param1value1param2value2)
- [--vpp-tweak](#--vpp-tweak-param1value1param2value2)
- [--vpp-overlay](#--vpp-overlay-param1value1param2value2)
- [--vpp-deband](#--vpp-deband-param1value1param2value2)
- [--vpp-padding](#--vpp-pad-intintintint)

Expand Down Expand Up @@ -2176,6 +2178,26 @@ Example:
--vpp-tweak brightness=0.1,contrast=1.5,gamma=0.75
```

### --vpp-overlay [&lt;param1&gt;=&lt;value1&gt;][,&lt;param2&gt;=&lt;value2&gt;],...
Overlay image on top of base video.

**Parameters**
- filename=&lt;string&gt;
source file path of the image.

- pos=&lt;int&gt;x&lt;int&gt;
position to add image.

- size=&lt;int&gt;x&lt;int&gt;
size of image.

- alpha=&lt;float&gt; (default: 1.0 (0.0 - 1.0))
alpha value of overlay.

- alpha_mode=&lt;string&gt;
- override ... set value of alpha
- mul ... multiple original value

### --vpp-deband [&lt;param1&gt;=&lt;value1&gt;][,&lt;param2&gt;=&lt;value2&gt;],...

**Parameters**
Expand Down
24 changes: 24 additions & 0 deletions NVEncC_Options.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@
- [--vpp-edgelevel \[\<param1\>=\<value1\>\]\[,\<param2\>=\<value2\>\],...](#--vpp-edgelevel-param1value1param2value2)
- [--vpp-warpsharp \[\<param1\>=\<value1\>\]\[,\<param2\>=\<value2\>\],...](#--vpp-warpsharp-param1value1param2value2)
- [--vpp-tweak \[\<param1\>=\<value1\>\]\[,\<param2\>=\<value2\>\],...](#--vpp-tweak-param1value1param2value2)
- [--vpp-overlay \[\<param1\>=\<value1\>\]\[,\<param2\>=\<value2\>\],...](#--vpp-overlay-param1value1param2value2)
- [--vpp-deband \[\<param1\>=\<value1\>\]\[,\<param2\>=\<value2\>\],...](#--vpp-deband-param1value1param2value2)
- [--vpp-pad \<int\>,\<int\>,\<int\>,\<int\>](#--vpp-pad-intintintint)
- [--vpp-perf-monitor](#--vpp-perf-monitor)
Expand Down Expand Up @@ -1473,6 +1474,7 @@ vppフィルタの適用順は固定で、コマンドラインの順序によ
- [--vpp-edgelevel](#--vpp-edgelevel-param1value1param2value2)
- [--vpp-warpsharp](#--vpp-warpsharp-param1value1param2value2)
- [--vpp-tweak](#--vpp-tweak-param1value1param2value2)
- [--vpp-overlay](#--vpp-overlay-param1value1param2value2)
- [--vpp-deband](#--vpp-deband-param1value1param2value2)
- [--vpp-padding](#--vpp-pad-intintintint)

Expand Down Expand Up @@ -2218,6 +2220,28 @@ unsharpフィルタ。輪郭・ディテール強調用のフィルタ。
--vpp-tweak brightness=0.1,contrast=1.5,gamma=0.75
```

### --vpp-overlay [&lt;param1&gt;=&lt;value1&gt;][,&lt;param2&gt;=&lt;value2&gt;],...
指定の画像を動画上に焼き込む。

**パラメータ**
- filename=&lt;string&gt;
焼き込む画像のパス。

- pos=&lt;int&gt;x&lt;int&gt;
焼き込み位置。

- size=&lt;int&gt;x&lt;int&gt;
焼き込む画像のサイズ。未指定の場合は、リサイズせず焼き込みを行う。

- alpha=&lt;float&gt; (デフォルト: 1.0 (0.0 - 1.0))
焼き込み際の不透明度。

- alpha_mode=&lt;string&gt;
- override ... alphaで指定の不透明度で上書きする。 (デフォルト)
- mul ... alphaで指定した不透明度を乗算する。

- loop=&lt;bool&gt; (default=false)

### --vpp-deband [&lt;param1&gt;=&lt;value1&gt;][,&lt;param2&gt;=&lt;value2&gt;],...

**パラメータ**
Expand Down
28 changes: 27 additions & 1 deletion NVEncCore/NVEncCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
#include "NVEncFilterColorspace.h"
#include "NVEncFilterSubburn.h"
#include "NVEncFilterSelectEvery.h"
#include "NVEncFilterOverlay.h"
#include "helper_cuda.h"
#include "helper_nvenc.h"

Expand Down Expand Up @@ -1271,7 +1272,8 @@ bool NVEncCore::enableCuvidResize(const InEncodeVideoParam *inputParam) {
|| inputParam->vpp.pad.enable
|| inputParam->vpp.selectevery.enable
|| inputParam->vpp.decimate.enable
|| inputParam->vpp.mpdecimate.enable);
|| inputParam->vpp.mpdecimate.enable
|| inputParam->vpp.overlay.enable);
}

#pragma warning(push)
Expand Down Expand Up @@ -2116,6 +2118,7 @@ RGY_ERR NVEncCore::InitFilters(const InEncodeVideoParam *inputParam) {
|| inputParam->vpp.decimate.enable
|| inputParam->vpp.mpdecimate.enable
|| inputParam->vpp.selectevery.enable
|| inputParam->vpp.overlay.enable
) {
//swデコードならGPUに上げる必要がある
if (m_pFileReader->getInputCodec() == RGY_CODEC_UNKNOWN) {
Expand Down Expand Up @@ -2727,6 +2730,29 @@ RGY_ERR NVEncCore::InitFilters(const InEncodeVideoParam *inputParam) {
inputFrame = param->frameOut;
m_encFps = param->baseFps;
}
//overlay
if (inputParam->vpp.overlay.enable) {
unique_ptr<NVEncFilter> filter(new NVEncFilterOverlay());
shared_ptr<NVEncFilterParamOverlay> param(new NVEncFilterParamOverlay());
param->overlay = inputParam->vpp.overlay;
param->threadPrm = inputParam->ctrl.threadParams.get(RGYThreadType::CSP);
param->frameIn = inputFrame;
param->frameOut = inputFrame;
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;
}
//deband
if (inputParam->vpp.deband.enable) {
unique_ptr<NVEncFilter> filter(new NVEncFilterDeband());
Expand Down
13 changes: 13 additions & 0 deletions NVEncCore/NVEncCore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,12 @@ if exist rgy_rev.h.%PID%.tmp del rgy_rev.h.%PID%.tmp &gt; nul 2&gt;&amp;1</Comma
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="gpu_info.cpp" />
<ClCompile Include="NVEncFilterOverlay.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="rgy_level_h264.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
Expand Down Expand Up @@ -885,6 +891,12 @@ if exist rgy_rev.h.%PID%.tmp del rgy_rev.h.%PID%.tmp &gt; nul 2&gt;&amp;1</Comma
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
</CudaCompile>
<CudaCompile Include="NVEncFilterOverlay.cu">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</CudaCompile>
<CudaCompile Include="NVEncFilterSmooth.cu">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
Expand Down Expand Up @@ -951,6 +963,7 @@ if exist rgy_rev.h.%PID%.tmp del rgy_rev.h.%PID%.tmp &gt; nul 2&gt;&amp;1</Comma
<ClInclude Include="FrameQueue.h" />
<ClInclude Include="gpuz_info.h" />
<ClInclude Include="gpu_info.h" />
<ClInclude Include="NVEncFilterOverlay.h" />
<ClInclude Include="rgy_level_h264.h" />
<ClInclude Include="rgy_level_hevc.h" />
<ClInclude Include="logo.h" />
Expand Down
9 changes: 9 additions & 0 deletions NVEncCore/NVEncCore.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@
<ClCompile Include="rgy_level_av1.cpp">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="NVEncFilterOverlay.cpp">
<Filter>ソース ファイル</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="gpu_info.h">
Expand Down Expand Up @@ -518,6 +521,9 @@
<ClInclude Include="rgy_level_av1.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="NVEncFilterOverlay.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<CudaCompile Include="NVEncFilterCrop.cu">
Expand Down Expand Up @@ -589,5 +595,8 @@
<CudaCompile Include="NVEncFilterConvolution3d.cu">
<Filter>ソース ファイル</Filter>
</CudaCompile>
<CudaCompile Include="NVEncFilterOverlay.cu">
<Filter>ソース ファイル</Filter>
</CudaCompile>
</ItemGroup>
</Project>
Loading

0 comments on commit 3426bf7

Please sign in to comment.