Skip to content

Commit

Permalink
重複フレームを削除するフィルタを追加。 ( --vpp-decimate )
Browse files Browse the repository at this point in the history
  • Loading branch information
rigaya committed May 6, 2020
1 parent ef893ee commit 2e244a8
Show file tree
Hide file tree
Showing 12 changed files with 982 additions and 7 deletions.
23 changes: 23 additions & 0 deletions NVEncC_Options.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,29 @@ example3: using hdr2sdr (hable tone-mapping) and setting the coefs (this is exam
--vpp-colorspace hdr2sdr=hable,source_peak=1000.0,ldr_nits=100.0,a=0.22,b=0.3,c=0.1,d=0.2,e=0.01,f=0.3
```

### --vpp-decimate [<param1>=<value1>][,<param2>=<value2>],...
Drop duplicated frame in cycles set.

**parameters**
- cycle=<int> (default: 5)
num of frame from which a frame will be droppped.

- thredup=<float> (default: 1.1, 0.0 - 100.0)
duplicate threshold.

- thresc=<float> (default: 15.0, 0.0 - 100.0)
scene change threshold.

- blockx=<int>
- blocky=<int>
block size of x and y direction, default = 32. block size could be 16, 32, 64.

- chroma=<bool>
consdier chroma (default: on).

- log=<bool>
output log file (default: off).

### --vpp-select-every <int>[,<param1>=<int>]
select one frame per specified frames and create output.

Expand Down
24 changes: 24 additions & 0 deletions NVEncC_Options.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,30 @@ yadifによるインタレ解除を行う。
--vpp-colorspace hdr2sdr=hable,source_peak=1000.0,ldr_nits=100.0,a=0.22,b=0.3,c=0.1,d=0.2,e=0.01,f=0.3
```

### --vpp-decimate [<param1>=<value1>][,<param2>=<value2>],...
重複フレームを削除します。

**パラメータ**
- cycle=<int> (デフォルト: 5)
ドロップするフレームの周期。ここで設定したフレーム数の中から1枚フレームをドロップする。

- thredup=<float> (デフォルト: 1.1, 0.0 - 100.0)
重複と判定する閾値。

- thresc=<float> (デフォルト: 15.0, 0.0 - 100.0)
シーンチェンジと判定する閾値。

- blockx=<int>
- blocky=<int>
重複判定の計算を行うブロックサイズ。デフォルト: 32。
ブロックサイズは 16, 32, 64のいずれかから選択可能。

- chroma=<bool>
色差成分を考慮した判定を行う。(デフォルト: on)

- log=<bool>
判定結果のログファイルの出力。 (デフォルト: off)

### --vpp-select-every <int>[,<param1>=<int>]
指定stepフレームごとに1フレームを選択してフレームを間引きます。フレームレートが1/stepになります。

Expand Down
157 changes: 156 additions & 1 deletion NVEncCore/NVEncCmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,25 @@ tstring encoder_help() {
_T(" --vpp-pad <int>,<int>,<int>,<int>\n")
_T(" add padding to left,top,right,bottom (in pixels)\n"));
str += strsprintf(_T("\n")
_T(" --vpp-decimate [<param1>=<value>][,<param2>=<value>][...]\n")
_T(" drop duplicated frame.\n")
_T(" params\n")
_T(" cycle=<int> num of frame from which a frame will be droppped.\n")
_T(" (default=%d)\n")
_T(" thredup=<float> duplicate threshold. (default=%.1f, 0 - 100)\n")
_T(" thresc=<float> scene change threshold. (default=%.1f, 0 - 100)\n")
_T(" blockx=<int> block size of x direction (default=%d).\n")
_T(" blocky=<int> block size of y direction (default=%d).\n")
_T(" block size could be 16, 32, 64.\n")
_T(" chroma=<bool> consdier chroma (default: %s)\n")
_T(" log=<bool> output log file (default: %s).\n"),
FILTER_DEFAULT_DECIMATE_CYCLE,
FILTER_DEFAULT_DECIMATE_THRE_DUP, FILTER_DEFAULT_DECIMATE_THRE_SC,
FILTER_DEFAULT_DECIMATE_BLOCK_X, FILTER_DEFAULT_DECIMATE_BLOCK_Y,
FILTER_DEFAULT_DECIMATE_PREPROCESSED ? _T("on") : _T("off"),
FILTER_DEFAULT_DECIMATE_CHROMA ? _T("on") : _T("off"),
FILTER_DEFAULT_DECIMATE_LOG ? _T("on") : _T("off"));
str += strsprintf(
_T(" --vpp-select-every <int>[,offset=<int>]\n")
_T(" select one frame per specified frames and create output.\n"));
str += strsprintf(_T("\n")
Expand Down Expand Up @@ -2971,7 +2990,6 @@ int parse_one_option(const TCHAR *option_name, const TCHAR* strInput[], int& i,
}
return 0;
}

if (IS_OPTION("vpp-select-every")) {
pParams->vpp.selectevery.enable = true;
if (i+1 >= nArgNum || strInput[i+1][0] == _T('-')) {
Expand Down Expand Up @@ -3028,6 +3046,124 @@ int parse_one_option(const TCHAR *option_name, const TCHAR* strInput[], int& i,
}
return 0;
}
if (IS_OPTION("vpp-decimate")) {
pParams->vpp.decimate.enable = true;
if (i + 1 >= nArgNum || strInput[i + 1][0] == _T('-')) {
return 0;
}
i++;
const auto paramList = std::vector<std::string>{ "cycle", "thresc", "thredup", "blockx", "blocky", "chroma", "log" /*, "pp"*/ };

for (const auto &param : split(strInput[i], _T(","))) {
auto pos = param.find_first_of(_T("="));
if (pos != std::string::npos) {
auto param_arg = param.substr(0, pos);
auto param_val = param.substr(pos + 1);
param_arg = tolowercase(param_arg);
if (param_arg == _T("enable")) {
bool b = false;
if (!cmd_string_to_bool(&b, param_val)) {
pParams->vpp.selectevery.enable = b;
} else {
print_cmd_error_invalid_value(tstring(option_name) + _T(" ") + param_arg + _T("="), param_val);
return 1;
}
continue;
}
if (param_arg == _T("cycle")) {
try {
pParams->vpp.decimate.cycle = std::stoi(param_val);
} catch (...) {
print_cmd_error_invalid_value(tstring(option_name) + _T(" ") + param_arg + _T("="), param_val);
return 1;
}
continue;
}
if (param_arg == _T("thresc")) {
try {
pParams->vpp.decimate.threSceneChange = std::stof(param_val);
} catch (...) {
print_cmd_error_invalid_value(tstring(option_name) + _T(" ") + param_arg + _T("="), param_val);
return 1;
}
continue;
}
if (param_arg == _T("thredup")) {
try {
pParams->vpp.decimate.threDuplicate = std::stof(param_val);
} catch (...) {
print_cmd_error_invalid_value(tstring(option_name) + _T(" ") + param_arg + _T("="), param_val);
return 1;
}
continue;
}
if (param_arg == _T("blockx")) {
int value = 0;
if (get_list_value(list_vpp_decimate_block, param_val.c_str(), &value)) {
pParams->vpp.decimate.blockX = value;
} else {
print_cmd_error_invalid_value(tstring(option_name) + _T(" ") + param_arg + _T("="), param_val, list_vpp_decimate_block);
return 1;
}
continue;
}
if (param_arg == _T("blocky")) {
int value = 0;
if (get_list_value(list_vpp_decimate_block, param_val.c_str(), &value)) {
pParams->vpp.decimate.blockY = value;
} else {
print_cmd_error_invalid_value(tstring(option_name) + _T(" ") + param_arg + _T("="), param_val, list_vpp_decimate_block);
return 1;
}
continue;
}
if (param_arg == _T("pp")) {
bool b = false;
if (!cmd_string_to_bool(&b, param_val)) {
pParams->vpp.decimate.preProcessed = b;
} else {
print_cmd_error_invalid_value(tstring(option_name) + _T(" ") + param_arg + _T("="), param_val);
return 1;
}
continue;
}
if (param_arg == _T("chroma")) {
bool b = false;
if (!cmd_string_to_bool(&b, param_val)) {
pParams->vpp.decimate.chroma = b;
} else {
print_cmd_error_invalid_value(tstring(option_name) + _T(" ") + param_arg + _T("="), param_val);
return 1;
}
continue;
}
if (param_arg == _T("log")) {
bool b = false;
if (!cmd_string_to_bool(&b, param_val)) {
pParams->vpp.decimate.log = b;
} else {
print_cmd_error_invalid_value(tstring(option_name) + _T(" ") + param_arg + _T("="), param_val);
return 1;
}
continue;
}
print_cmd_error_unknown_opt_param(option_name, param_arg, paramList);
return 1;
} else {
if (param == _T("log")) {
pParams->vpp.decimate.log = true;
continue;
}
if (param == _T("chroma")) {
pParams->vpp.decimate.chroma = true;
continue;
}
print_cmd_error_unknown_opt_param(option_name, param, paramList);
return 1;
}
}
return 0;
}
if (IS_OPTION("vpp-perf-monitor")) {
pParams->vpp.checkPerformance = true;
return 0;
Expand Down Expand Up @@ -4022,6 +4158,25 @@ tstring gen_cmd(const InEncodeVideoParam *pParams, const NV_ENC_CODEC_CONFIG cod
cmd << _T(" --vpp-select-every ") << tmp.str().substr(1);
}
}
if (pParams->vpp.decimate != encPrmDefault.vpp.decimate) {
tmp.str(tstring());
if (!pParams->vpp.decimate.enable && save_disabled_prm) {
tmp << _T(",enable=false");
}
if (pParams->vpp.decimate.enable || save_disabled_prm) {
ADD_NUM(_T("cycle"), vpp.decimate.cycle);
ADD_FLOAT(_T("thredup"), vpp.decimate.threDuplicate, 3);
ADD_FLOAT(_T("thresc"), vpp.decimate.threSceneChange, 2);
ADD_LST(_T("blockx"), vpp.decimate.blockX, list_vpp_decimate_block);
ADD_LST(_T("blocky"), vpp.decimate.blockX, list_vpp_decimate_block);
ADD_BOOL(_T("pp"), vpp.decimate.preProcessed);
ADD_BOOL(_T("chroma"), vpp.decimate.chroma);
ADD_BOOL(_T("log"), vpp.decimate.log);
}
if (!tmp.str().empty()) {
cmd << _T(" --vpp-select-every ") << tmp.str().substr(1);
}
}
OPT_BOOL(_T("--vpp-perf-monitor"), _T("--no-vpp-perf-monitor"), vpp.checkPerformance);

OPT_BOOL(_T("--ssim"), _T(""), ssim);
Expand Down
29 changes: 28 additions & 1 deletion NVEncCore/NVEncCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
#include "NVEncFilterDenoisePmd.h"
#include "NVEncFilterSmooth.h"
#include "NVEncFilterDeband.h"
#include "NVEncFilterDecimate.h"
#include "NVEncFilterAfs.h"
#include "NVEncFilterNnedi.h"
#include "NVEncFilterYadif.h"
Expand Down Expand Up @@ -1232,7 +1233,9 @@ bool NVEncCore::enableCuvidResize(const InEncodeVideoParam *inputParam) {
|| inputParam->vpp.transform.enable
|| inputParam->vpp.colorspace.enable
|| inputParam->vpp.subburn.size() > 0
|| inputParam->vpp.pad.enable);
|| inputParam->vpp.pad.enable
|| inputParam->vpp.selectevery.enable
|| inputParam->vpp.decimate.enable);
}

#pragma warning(push)
Expand Down Expand Up @@ -1970,6 +1973,7 @@ RGY_ERR NVEncCore::InitFilters(const InEncodeVideoParam *inputParam) {
|| inputParam->vpp.pad.enable
|| inputParam->vpp.subburn.size() > 0
|| inputParam->vpp.rff
|| inputParam->vpp.decimate.enable
|| inputParam->vpp.selectevery.enable
) {
//swデコードならGPUに上げる必要がある
Expand Down Expand Up @@ -2195,6 +2199,29 @@ RGY_ERR NVEncCore::InitFilters(const InEncodeVideoParam *inputParam) {
inputFrame = param->frameOut;
m_encFps = param->baseFps;
}
//decimate
if (inputParam->vpp.decimate.enable) {
unique_ptr<NVEncFilter> filter(new NVEncFilterDecimate());
shared_ptr<NVEncFilterParamDecimate> param(new NVEncFilterParamDecimate());
param->frameIn = inputFrame;
param->frameOut = inputFrame;
param->baseFps = m_encFps;
param->decimate = inputParam->vpp.decimate;
param->outfilename = inputParam->common.outputFilename;
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;
}
//select-every
if (inputParam->vpp.selectevery.enable) {
unique_ptr<NVEncFilter> filter(new NVEncFilterSelectEvery());
Expand Down
7 changes: 7 additions & 0 deletions NVEncCore/NVEncCore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,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="NVEncFilterDecimate.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="NVEncFilterDelogo.cu">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
Expand Down Expand Up @@ -1170,6 +1176,7 @@ if exist rgy_rev.h.%PID%.tmp del rgy_rev.h.%PID%.tmp &gt; nul 2&gt;&amp;1</Comma
<ClInclude Include="NVEncFilterColorspace.h" />
<ClInclude Include="NVEncFilterColorspaceFunc.h" />
<ClInclude Include="NVEncFilterDeband.h" />
<ClInclude Include="NVEncFilterDecimate.h" />
<ClInclude Include="NVEncFilterDelogo.h" />
<ClInclude Include="NVEncFilterDenoiseKnn.h" />
<ClInclude Include="NVEncFilterDenoisePmd.h" />
Expand Down
6 changes: 6 additions & 0 deletions NVEncCore/NVEncCore.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,9 @@
<ClInclude Include="rgy_chapter.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="NVEncFilterDecimate.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<CudaCompile Include="NVEncFilterCrop.cu">
Expand Down Expand Up @@ -505,6 +508,9 @@
<CudaCompile Include="NVEncFilterTransform.cu">
<Filter>ソース ファイル</Filter>
</CudaCompile>
<CudaCompile Include="NVEncFilterDecimate.cu">
<Filter>ソース ファイル</Filter>
</CudaCompile>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="ram_speed_x64.asm">
Expand Down

0 comments on commit 2e244a8

Please sign in to comment.