Skip to content

Commit

Permalink
重複したタイムスタンプのある壊れた入力ファイルでは、問題のフレームを間引いて処理するように。 ( #517 )
Browse files Browse the repository at this point in the history
  • Loading branch information
rigaya committed Oct 18, 2023
1 parent 674e7f7 commit 04c306a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 0 deletions.
11 changes: 11 additions & 0 deletions NVEncCore/NVEncCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -3936,6 +3938,7 @@ NVENCSTATUS NVEncCore::Encode() {
return;
};

int ignoreVideoTimestampErrorCount = 0;
uint32_t nInputFramePosIdx = UINT32_MAX;
auto check_pts = [&](FrameBufferDataIn *pInputFrame) {
vector<unique_ptr<FrameBufferDataIn>> decFrames;
Expand Down Expand Up @@ -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<int64_t>(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の予想
Expand Down
1 change: 1 addition & 0 deletions NVEncCore/NVEncCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ class NVEncCore : public NVEncCtrl {
unique_ptr<DOVIRpu> m_dovirpu;
std::unique_ptr<RGYTimestamp> m_encTimestamp;
int64_t m_encodeFrameID;
int m_videoIgnoreTimestampError;

vector<unique_ptr<NVEncFilter>> m_vpFilters;
shared_ptr<NVEncFilterParam> m_pLastFilterParam;
Expand Down
11 changes: 11 additions & 0 deletions NVEncCore/rgy_cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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++) {
Expand Down
1 change: 1 addition & 0 deletions NVEncCore/rgy_prm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions NVEncCore/rgy_prm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -1474,6 +1475,7 @@ struct RGYParamCommon {
bool chapterNoTrim;
C2AFormat caption2ass;
int audioIgnoreDecodeError;
int videoIgnoreTimestampError;
RGYOptList muxOpt;
bool allowOtherNegativePts;
bool disableMp4Opt;
Expand Down

0 comments on commit 04c306a

Please sign in to comment.