Skip to content

Commit

Permalink
rffを展開するフィルタを追加。(--vpp-rff)
Browse files Browse the repository at this point in the history
  • Loading branch information
rigaya committed Nov 4, 2023
1 parent b0560a3 commit 9d0ac4a
Show file tree
Hide file tree
Showing 19 changed files with 590 additions and 26 deletions.
5 changes: 5 additions & 0 deletions QSVEnc/QSVEnc_readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,11 @@ API v1.1 … Intel Media SDK v2.0


【どうでもいいメモ】
2023.11.04 (7.52)
[QSVEncC]
- rffを展開するフィルタを追加。(--vpp-rff)
- QSVEnc 7.50で、--b-pyramidがデフォルトで無効になっていたのを元に戻す。

2023.10.28 (7.51)
[QSVEncC]
- ICQモードをデフォルトに。
Expand Down
6 changes: 6 additions & 0 deletions QSVEncC_Options.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
- [Vpp Options](#vpp-options)
- [Vpp Filtering order](#vpp-filtering-order)
- [--vpp-colorspace \[\<param1\>=\<value1\>\[,\<param2\>=\<value2\>\]...\]](#--vpp-colorspace-param1value1param2value2)
- [--vpp-rff](#--vpp-rff)
- [--vpp-delogo \<string\>\[,\<param1\>=\<value1\>\]\[,\<param2\>=\<value2\>\],...](#--vpp-delogo-stringparam1value1param2value2)
- [--vpp-afs \[\<param1\>=\<value1\>\[,\<param2\>=\<value2\>\]...\]](#--vpp-afs-param1value1param2value2)
- [--vpp-nnedi \[\<param1\>=\<value1\>\[,\<param2\>=\<value2\>\]...\]](#--vpp-nnedi-param1value1param2value2)
Expand Down Expand Up @@ -1591,6 +1592,7 @@ Vpp filters will be applied in fixed order, regardless of the order in the comma

- filter list
- [--vpp-colorspace](#--vpp-colorspace-param1value1param2value2)
- [--vpp-rff](#--vpp-rff)
- [--vpp-delogo](#--vpp-delogo-stringparam1value1param2value2)
- [--vpp-afs](#--vpp-afs-param1value1param2value2)
- [--vpp-nnedi](#--vpp-nnedi-param1value1param2value2)
Expand Down Expand Up @@ -1715,6 +1717,10 @@ Values for parameters will be copied from input file for "input".
--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-rff
Reflect the Repeat Field Flag. The avsync error caused by rff could be solved. Available only when [--avhw](#--avhw-string), [--avsw](#--avsw-string) is used.
rff of 2 or more will not be supported (only supports rff = 1). Also, it can not be used with [--trim](#--trim-intintintintintint).
### --vpp-delogo &lt;string&gt;[,&lt;param1&gt;=&lt;value1&gt;][,&lt;param2&gt;=&lt;value2&gt;],...
Expand Down
6 changes: 6 additions & 0 deletions QSVEncC_Options.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
- [vppオプション](#vppオプション)
- [vppフィルタの適用順](#vppフィルタの適用順)
- [--vpp-colorspace \[\<param1\>=\<value1\>\[,\<param2\>=\<value2\>\]...\]](#--vpp-colorspace-param1value1param2value2)
- [--vpp-rff](#--vpp-rff)
- [--vpp-delogo \<string\>\[,\<param1\>=\<value1\>\]\[,\<param2\>=\<value2\>\]...](#--vpp-delogo-stringparam1value1param2value2)
- [--vpp-afs \[\<param1\>=\<value1\>\[,\<param2\>=\<value2\>\]...\]](#--vpp-afs-param1value1param2value2)
- [--vpp-nnedi \[\<param1\>=\<value1\>\[,\<param2\>=\<value2\>\]...\]](#--vpp-nnedi-param1value1param2value2)
Expand Down Expand Up @@ -1604,6 +1605,7 @@ vppフィルタの適用順は固定で、コマンドラインの順序によ

- フィルター一覧
- [--vpp-colorspace](#--vpp-colorspace-param1value1param2value2)
- [--vpp-rff](#--vpp-rff)
- [--vpp-delogo](#--vpp-delogo-stringparam1value1param2value2)
- [--vpp-afs](#--vpp-afs-param1value1param2value2)
- [--vpp-nnedi](#--vpp-nnedi-param1value1param2value2)
Expand Down Expand Up @@ -1727,6 +1729,10 @@ vppフィルタの適用順は固定で、コマンドラインの順序によ
--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-rff
Repeat Field Flagを反映して、フレームを再構築する。rffによる音ズレ問題が解消できる。[--avhw](#--avhw-string), [--avsw](#--avsw-string)使用時のみ有効。
rff=1の場合のみの対応。(rff > 1には対応しない) また、[--trim](#--trim-intintintintintint)とは併用できない。
### --vpp-delogo &lt;string&gt;[,&lt;param1&gt;=&lt;value1&gt;][,&lt;param2&gt;=&lt;value2&gt;]...
ロゴファイルとロゴ消しのオプションを指定する。ロゴファイルは、".lgd",".ldp",".ldp2"に対応。
Expand Down
7 changes: 7 additions & 0 deletions QSVPipeline/QSVPipeline.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,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|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="rgy_filter_rff.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_filter_smooth.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
Expand Down Expand Up @@ -1006,6 +1012,7 @@ if exist rgy_rev.h.%PID%.tmp del rgy_rev.h.%PID%.tmp &gt; nul 2&gt;&amp;1</Comma
<ClInclude Include="rgy_filter_mpdecimate.h" />
<ClInclude Include="rgy_filter_nnedi.h" />
<ClInclude Include="rgy_filter_overlay.h" />
<ClInclude Include="rgy_filter_rff.h" />
<ClInclude Include="rgy_filter_smooth.h" />
<ClInclude Include="rgy_filter_ssim.h" />
<ClInclude Include="rgy_filter_subburn.h" />
Expand Down
6 changes: 6 additions & 0 deletions QSVPipeline/QSVPipeline.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,9 @@
<ClCompile Include="rgy_memmem_avx512bw.cpp">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="rgy_filter_rff.cpp">
<Filter>ソース ファイル</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="qsv_prm.h">
Expand Down Expand Up @@ -644,6 +647,9 @@
<ClInclude Include="rgy_memmem.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="rgy_filter_rff.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="rgy_filter.cl">
Expand Down
3 changes: 3 additions & 0 deletions QSVPipeline/qsv_mfx_dec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ RGY_ERR QSVMfxDec::SetParam(
memset(&m_mfxDecParams, 0, sizeof(m_mfxDecParams));
m_mfxDecParams.mfx.CodecId = codec_rgy_to_enc(inputCodec);
m_mfxDecParams.IOPattern = (uint16_t)((m_memType != SYSTEM_MEMORY) ? MFX_IOPATTERN_OUT_VIDEO_MEMORY : MFX_IOPATTERN_OUT_SYSTEM_MEMORY);
// RFF使用時に、フィールドの情報を取得するために必要
// RFFのときに MFX_PICSTRUCT_PROGRESSIVE に加え、MFX_PICSTRUCT_FIELD_TFFまたはMFX_PICSTRUCT_FIELD_BFF、MFX_PICSTRUCT_FIELD_REPEATEDが設定される
m_mfxDecParams.mfx.ExtendedPicStruct = 1;
sts = err_to_rgy(m_mfxDec->DecodeHeader(&inputHeader.bitstream(), &m_mfxDecParams));
if (sts != RGY_ERR_NONE && inputCodec == RGY_CODEC_AV1) {
// AV1ではそのままのヘッダだと、DecodeHeaderに失敗する場合がある QSVEnc #122
Expand Down
43 changes: 39 additions & 4 deletions QSVPipeline/qsv_pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ RGY_DISABLE_WARNING_POP
#include "rgy_input_avcodec.h"
#include "rgy_filter.h"
#include "rgy_filter_colorspace.h"
#include "rgy_filter_rff.h"
#include "rgy_filter_afs.h"
#include "rgy_filter_nnedi.h"
#include "rgy_filter_yadif.h"
Expand Down Expand Up @@ -1792,7 +1793,7 @@ RGY_ERR CQSVPipeline::InitInput(sInputParams *inputParam, std::vector<std::uniqu

auto sts = initReaders(m_pFileReader, m_AudioReaders, &inputParam->input, inputCspOfRawReader,
m_pStatus, &inputParam->common, &inputParam->ctrl, HWDecCodecCsp, subburnTrackId,
(ENABLE_VPP_FILTER_RFF) ? inputParam->vpp.rff : false,
(ENABLE_VPP_FILTER_RFF) ? inputParam->vpp.rff.enable : false,
(ENABLE_VPP_FILTER_AFS) ? inputParam->vpp.afs.enable : false,
m_poolPkt.get(), m_poolFrame.get(),
nullptr, m_pPerfMonitor.get(), m_pQSVLog);
Expand Down Expand Up @@ -1838,14 +1839,17 @@ RGY_ERR CQSVPipeline::InitInput(sInputParams *inputParam, std::vector<std::uniqu
auto pAVCodecReader = std::dynamic_pointer_cast<RGYInputAvcodec>(m_pFileReader);
if ((m_nAVSyncMode & (RGY_AVSYNC_VFR | RGY_AVSYNC_FORCE_CFR))
#if ENABLE_VPP_FILTER_RFF
|| inputParam->vpp.rff
|| inputParam->vpp.rff.enable
#endif
) {
tstring err_target;
if (m_nAVSyncMode & RGY_AVSYNC_VFR) err_target += _T("avsync vfr, ");
if (m_nAVSyncMode & RGY_AVSYNC_FORCE_CFR) err_target += _T("avsync forcecfr, ");
#if ENABLE_VPP_FILTER_RFF
if (inputParam->vpp.rff) err_target += _T("vpp-rff, ");
if (inputParam->vpp.rff.enable) {
err_target += _T("vpp-rff, ");
m_nAVSyncMode = RGY_AVSYNC_VFR;
}
#endif
err_target = err_target.substr(0, err_target.length()-2);

Expand Down Expand Up @@ -1877,7 +1881,7 @@ RGY_ERR CQSVPipeline::InitInput(sInputParams *inputParam, std::vector<std::uniqu
m_nAVSyncMode |= RGY_AVSYNC_VFR;
const auto timebaseStreamIn = to_rgy(pAVCodecReader->GetInputVideoStream()->time_base);
if ((timebaseStreamIn.inv() * m_inputFps.inv()).d() == 1 || timebaseStreamIn.n() > 1000) { //fpsを割り切れるtimebaseなら
if (!inputParam->vpp.afs.enable && !inputParam->vpp.rff) {
if (!inputParam->vpp.afs.enable && !inputParam->vpp.rff.enable) {
m_outputTimebase = m_inputFps.inv() * rgy_rational<int>(1, 8);
}
}
Expand Down Expand Up @@ -2069,6 +2073,7 @@ std::vector<VppType> CQSVPipeline::InitFiltersCreateVppList(const sInputParams *
}
filterPipeline.push_back((requireOpenCL) ? VppType::CL_COLORSPACE : VppType::MFX_COLORSPACE);
}
if (inputParam->vpp.rff.enable) filterPipeline.push_back(VppType::CL_RFF);
if (inputParam->vpp.delogo.enable) filterPipeline.push_back(VppType::CL_DELOGO);
if (inputParam->vpp.afs.enable) filterPipeline.push_back(VppType::CL_AFS);
if (inputParam->vpp.nnedi.enable) filterPipeline.push_back(VppType::CL_NNEDI);
Expand Down Expand Up @@ -2228,6 +2233,29 @@ RGY_ERR CQSVPipeline::AddFilterOpenCL(std::vector<std::unique_ptr<RGYFilter>>& c
clfilters.push_back(std::move(filter));
return RGY_ERR_NONE;
}
//rff
if (vppType == VppType::CL_RFF) {
unique_ptr<RGYFilter> filter(new RGYFilterRff(m_cl));
shared_ptr<RGYFilterParamRff> param(new RGYFilterParamRff());
param->rff = params->vpp.rff;
param->frameIn = inputFrame;
param->frameOut = inputFrame;
param->baseFps = m_encFps;
param->inFps = m_inputFps;
param->timebase = m_outputTimebase;
param->outFilename = params->common.outputFilename;
param->bOutOverwrite = true;
auto sts = filter->init(param, m_pQSVLog);
if (sts != RGY_ERR_NONE) {
return sts;
}
//入力フレーム情報を更新
inputFrame = param->frameOut;
m_encFps = param->baseFps;
//登録
clfilters.push_back(std::move(filter));
return RGY_ERR_NONE;
}
//delogo
if (vppType == VppType::CL_DELOGO) {
unique_ptr<RGYFilter> filter(new RGYFilterDelogo(m_cl));
Expand Down Expand Up @@ -2838,6 +2866,13 @@ RGY_ERR CQSVPipeline::InitFilters(sInputParams *inputParam) {
PrintMes(RGY_LOG_ERROR, _T("Activating 2 or more deinterlacer is not supported.\n"));
return RGY_ERR_UNSUPPORTED;
}
//vpp-rffの制約事項
if (inputParam->vpp.rff.enable) {
if (trim_active(&m_trimParam)) {
PrintMes(RGY_LOG_ERROR, _T("vpp-rff cannot be used with trim.\n"));
return RGY_ERR_UNSUPPORTED;
}
}
//picStructの設定
m_encPicstruct = (deinterlacer > 0) ? RGY_PICSTRUCT_FRAME : inputParam->input.picstruct;

Expand Down
27 changes: 25 additions & 2 deletions QSVPipeline/qsv_pipeline_ctrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -871,9 +871,25 @@ class PipelineTaskMFXDecode : public PipelineTask {
}
if (surfDecOut != nullptr && lastSyncP != nullptr) {
auto taskSurf = useTaskSurf(surfDecOut);
const auto picstruct = taskSurf.mfx()->surf()->Info.PicStruct;
auto flags = RGY_FRAME_FLAG_NONE;
// RFFの場合、MFX_PICSTRUCT_PROGRESSIVEに加えて、MFX_PICSTRUCT_FIELD_TFFまたはMFX_PICSTRUCT_FIELD_BFF、MFX_PICSTRUCT_FIELD_REPEATEDが立っている
// picstructにはprogressiveを設定し、flagsにRFF関係の情報を設定しなおす
// この情報の取得には、m_mfxDecParams.mfx.ExtendedPicStruct = 1 としてデコーダを初期化する必要がある
if ((picstruct & MFX_PICSTRUCT_PROGRESSIVE) && (picstruct & (MFX_PICSTRUCT_FIELD_TFF| MFX_PICSTRUCT_FIELD_BFF))) {
taskSurf.frame()->setPicstruct(RGY_PICSTRUCT_FRAME);
if (picstruct & MFX_PICSTRUCT_FIELD_REPEATED) {
flags |= RGY_FRAME_FLAG_RFF;
}
}
if (picstruct & MFX_PICSTRUCT_FIELD_TFF) {
flags |= RGY_FRAME_FLAG_RFF_TFF;
}
if (picstruct & MFX_PICSTRUCT_FIELD_BFF) {
flags |= RGY_FRAME_FLAG_RFF_BFF;
}
taskSurf.frame()->setInputFrameId(m_decFrameOutCount++);

auto flags = RGY_FRAME_FLAG_NONE;
if (getDataFlag(surfDecOut->Data.TimeStamp) & RGY_FRAME_FLAG_RFF) {
flags |= RGY_FRAME_FLAG_RFF;
}
Expand Down Expand Up @@ -993,6 +1009,9 @@ class PipelineTaskCheckPTS : public PipelineTask {
//CFR仮定ではなく、オリジナルの時間を見る
const auto srcTimestamp = taskSurf->surf().frame()->timestamp();
outPtsSource = rational_rescale(srcTimestamp, m_srcTimebase, m_outputTimebase);
if (taskSurf->surf().frame()->duration() > 0) {
taskSurf->surf().frame()->setDuration(rational_rescale(taskSurf->surf().frame()->duration(), m_srcTimebase, m_outputTimebase));
}
}
PrintMes(RGY_LOG_TRACE, _T("check_pts(%d/%d): nOutEstimatedPts %lld, outPtsSource %lld, outDuration %d\n"), taskSurf->surf().frame()->inputFrameId(), m_inFrames, m_tsOutEstimated, outPtsSource, outDuration);
if (m_tsOutFirst < 0) {
Expand Down Expand Up @@ -1785,9 +1804,13 @@ class PipelineTaskOpenCL : public PipelineTask {
#define clFrameOutInteropRelease { if (clFrameOutInterop) clFrameOutInterop->release(); }
//フィルタリングするならここ
for (uint32_t ifilter = filterframes.front().second; ifilter < m_vpFilters.size() - 1; ifilter++) {
// コピーを作ってそれをfilter関数に渡す
// vpp-rffなどoverwirteするフィルタのときに、filterframes.pop_front -> push がうまく動作しない
RGYFrameInfo input = filterframes.front().first;

int nOutFrames = 0;
RGYFrameInfo *outInfo[16] = { 0 };
auto sts_filter = m_vpFilters[ifilter]->filter(&filterframes.front().first, (RGYFrameInfo **)&outInfo, &nOutFrames);
auto sts_filter = m_vpFilters[ifilter]->filter(&input, (RGYFrameInfo **)&outInfo, &nOutFrames);
if (sts_filter != RGY_ERR_NONE) {
PrintMes(RGY_LOG_ERROR, _T("Error while running filter \"%s\".\n"), m_vpFilters[ifilter]->name().c_str());
clFrameOutInteropRelease;
Expand Down
1 change: 1 addition & 0 deletions QSVPipeline/qsv_prm.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ enum class VppType : int {
CL_MPDECIMATE,
CL_YADIF,
CL_COLORSPACE,
CL_RFF,
CL_DELOGO,
CL_TRANSFORM,

Expand Down
Loading

0 comments on commit 9d0ac4a

Please sign in to comment.