From 04c306ae8b69ea9b66b9c2ae4acb23666def5b10 Mon Sep 17 00:00:00 2001 From: rigaya Date: Wed, 18 Oct 2023 21:14:10 +0900 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E8=A4=87=E3=81=97=E3=81=9F=E3=82=BF?= =?UTF-8?q?=E3=82=A4=E3=83=A0=E3=82=B9=E3=82=BF=E3=83=B3=E3=83=97=E3=81=AE?= =?UTF-8?q?=E3=81=82=E3=82=8B=E5=A3=8A=E3=82=8C=E3=81=9F=E5=85=A5=E5=8A=9B?= =?UTF-8?q?=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E3=81=A7=E3=81=AF=E3=80=81?= =?UTF-8?q?=E5=95=8F=E9=A1=8C=E3=81=AE=E3=83=95=E3=83=AC=E3=83=BC=E3=83=A0?= =?UTF-8?q?=E3=82=92=E9=96=93=E5=BC=95=E3=81=84=E3=81=A6=E5=87=A6=E7=90=86?= =?UTF-8?q?=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E3=80=82=20(=20#5?= =?UTF-8?q?17=20)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NVEncCore/NVEncCore.cpp | 11 +++++++++++ NVEncCore/NVEncCore.h | 1 + NVEncCore/rgy_cmd.cpp | 11 +++++++++++ NVEncCore/rgy_prm.cpp | 1 + NVEncCore/rgy_prm.h | 2 ++ 5 files changed, 26 insertions(+) diff --git a/NVEncCore/NVEncCore.cpp b/NVEncCore/NVEncCore.cpp index 50fab9c7..17133c8d 100644 --- a/NVEncCore/NVEncCore.cpp +++ b/NVEncCore/NVEncCore.cpp @@ -295,6 +295,7 @@ NVEncCore::NVEncCore() : m_dovirpu(), m_encTimestamp(), m_encodeFrameID(0), + m_videoIgnoreTimestampError(DEFAULT_VIDEO_IGNORE_TIMESTAMP_ERROR), m_vpFilters(), m_pLastFilterParam(), #if ENABLE_SSIM @@ -3185,6 +3186,7 @@ NVENCSTATUS NVEncCore::InitEncode(InEncodeVideoParam *inputParam) { inputParam->applyDOVIProfile(); m_nAVSyncMode = inputParam->common.AVSyncMode; m_nProcSpeedLimit = inputParam->ctrl.procSpeedLimit; + m_videoIgnoreTimestampError = inputParam->common.videoIgnoreTimestampError; if (inputParam->ctrl.lowLatency) { m_pipelineDepth = 1; } @@ -3936,6 +3938,7 @@ NVENCSTATUS NVEncCore::Encode() { return; }; + int ignoreVideoTimestampErrorCount = 0; uint32_t nInputFramePosIdx = UINT32_MAX; auto check_pts = [&](FrameBufferDataIn *pInputFrame) { vector> decFrames; @@ -4029,18 +4032,26 @@ NVENCSTATUS NVEncCore::Encode() { nOutFirstPts += (outPtsSource - nOutEstimatedPts); //今後の位置合わせのための補正 outPtsSource = nOutEstimatedPts; PrintMes(RGY_LOG_DEBUG, _T("check_pts: changed to nOutFirstPts %lld, outPtsSource %lld.\n"), nOutFirstPts, outPtsSource); + ignoreVideoTimestampErrorCount = 0; } else { if (m_nAVSyncMode & RGY_AVSYNC_FORCE_CFR) { //間引きが必要 PrintMes(RGY_LOG_WARN, _T("check_pts(%d): timestamp of video frame is smaller than previous frame, skipping frame: previous pts %lld, current pts %lld.\n"), pInputFrame->getFrameInfo().inputFrameId, nLastPts, outPtsSource); return decFrames; + } else if (ignoreVideoTimestampErrorCount < m_videoIgnoreTimestampError) { + //間引き + PrintMes(RGY_LOG_WARN, _T("check_pts(%d): timestamp of video frame is smaller than previous frame, skipping frame: previous pts %lld, current pts %lld.\n"), pInputFrame->getFrameInfo().inputFrameId, nLastPts, outPtsSource); + return decFrames; } else { const auto origPts = outPtsSource; outPtsSource = nLastPts + std::max(1, nOutFrameDuration / 8); PrintMes(RGY_LOG_WARN, _T("check_pts(%d): timestamp of video frame is smaller than previous frame, changing pts: %lld -> %lld (previous pts %lld).\n"), pInputFrame->getFrameInfo().inputFrameId, origPts, outPtsSource, nLastPts); } + ignoreVideoTimestampErrorCount++; } + } else { + ignoreVideoTimestampErrorCount = 0; } #endif //#if ENABLE_AVSW_READER //次のフレームのptsの予想 diff --git a/NVEncCore/NVEncCore.h b/NVEncCore/NVEncCore.h index 241a9b65..947c04f7 100644 --- a/NVEncCore/NVEncCore.h +++ b/NVEncCore/NVEncCore.h @@ -207,6 +207,7 @@ class NVEncCore : public NVEncCtrl { unique_ptr m_dovirpu; std::unique_ptr m_encTimestamp; int64_t m_encodeFrameID; + int m_videoIgnoreTimestampError; vector> m_vpFilters; shared_ptr m_pLastFilterParam; diff --git a/NVEncCore/rgy_cmd.cpp b/NVEncCore/rgy_cmd.cpp index 8015592a..414651d8 100644 --- a/NVEncCore/rgy_cmd.cpp +++ b/NVEncCore/rgy_cmd.cpp @@ -4129,6 +4129,16 @@ int parse_one_common_option(const TCHAR *option_name, const TCHAR *strInput[], i if (IS_OPTION("audio-ignore-notrack-error")) { return 0; } + if (IS_OPTION("video-ignore-timestamp-error")) { + i++; + uint32_t value = 0; + if (1 != _stscanf_s(strInput[i], _T("%d"), &value)) { + print_cmd_error_invalid_value(option_name, strInput[i]); + return 1; + } + common->videoIgnoreTimestampError = value; + return 0; + } if (IS_OPTION("audio-samplerate")) { try { auto ret = set_audio_prm([](AudioSelect *pAudioSelect, int trackId, const TCHAR *prmstr) { @@ -6373,6 +6383,7 @@ tstring gen_cmd(const RGYParamCommon *param, const RGYParamCommon *defaultPrm, b } } OPT_NUM(_T("--audio-ignore-decode-error"), audioIgnoreDecodeError); + OPT_NUM(_T("--video-ignore-timestamp-error"), videoIgnoreTimestampError); tmp.str(tstring()); for (int i = 0; i < param->nSubtitleSelectCount; i++) { diff --git a/NVEncCore/rgy_prm.cpp b/NVEncCore/rgy_prm.cpp index e36a4bcd..9f339ddd 100644 --- a/NVEncCore/rgy_prm.cpp +++ b/NVEncCore/rgy_prm.cpp @@ -1411,6 +1411,7 @@ RGYParamCommon::RGYParamCommon() : chapterNoTrim(false), caption2ass(FORMAT_INVALID), audioIgnoreDecodeError(DEFAULT_IGNORE_DECODE_ERROR), + videoIgnoreTimestampError(DEFAULT_VIDEO_IGNORE_TIMESTAMP_ERROR), muxOpt(), allowOtherNegativePts(false), disableMp4Opt(false), diff --git a/NVEncCore/rgy_prm.h b/NVEncCore/rgy_prm.h index 95867900..2e994bc4 100644 --- a/NVEncCore/rgy_prm.h +++ b/NVEncCore/rgy_prm.h @@ -41,6 +41,7 @@ static const int OUTPUT_BUF_SIZE = 16 * 1024 * 1024; static const int RGY_DEFAULT_PERF_MONITOR_INTERVAL = 500; static const int DEFAULT_IGNORE_DECODE_ERROR = 10; +static const int DEFAULT_VIDEO_IGNORE_TIMESTAMP_ERROR = 10; #if ENCODER_NVENC #define ENABLE_VPP_FILTER_COLORSPACE (ENABLE_NVRTC) @@ -1474,6 +1475,7 @@ struct RGYParamCommon { bool chapterNoTrim; C2AFormat caption2ass; int audioIgnoreDecodeError; + int videoIgnoreTimestampError; RGYOptList muxOpt; bool allowOtherNegativePts; bool disableMp4Opt;