Skip to content

Commit

Permalink
ログ出力機能の強化。
Browse files Browse the repository at this point in the history
  • Loading branch information
rigaya committed Nov 22, 2023
1 parent 14e0147 commit f46dedd
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 38 deletions.
12 changes: 8 additions & 4 deletions NVEncC_Options.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,9 @@
- [--log \<string\>](#--log-string)
- [--log-level \[\<param1\>=\]\<value\>\[,\<param2\>=\<value\>\]...](#--log-level-param1valueparam2value)
- [--log-opt \<param1\>=\<value\>\[,\<param2\>=\<value\>\]...](#--log-opt-param1valueparam2value)
- [--log-framelist](#--log-framelist)
- [--log-packets](#--log-packets)
- [--log-framelist \[\<string\>\]](#--log-framelist-string)
- [--log-packets \[\<string\>\]](#--log-packets-string)
- [--log-mux-ts \[\<string\>\]](#--log-mux-ts-string)
- [--thread-affinity \[\<string1\>=\]{\<string2\>\[#\<int\>\[:\<int\>\]...\] or 0x\<hex\>}](#--thread-affinity-string1string2intint-or-0xhex)
- [--thread-priority \[\<string1\>=\]\<string2\>\[#\<int\>\[:\<int\>\]...\]](#--thread-priority-string1string2intint)
- [--thread-throttling \[\<string1\>=\]\<string2\>\[#\<int\>\[:\<int\>\]...\]](#--thread-throttling-string1string2intint)
Expand Down Expand Up @@ -2608,12 +2609,15 @@ additional options for log output.
- addtime (default=off)
Add time of to each line of the log.
### --log-framelist
### --log-framelist [&lt;string&gt;]
FOR DEBUG ONLY! Output debug log for avsw/avhw reader.
### --log-packets
### --log-packets [&lt;string&gt;]
FOR DEBUG ONLY! Output debug log for packets read in avsw/avhw reader.
### --log-mux-ts [&lt;string&gt;]
FOR DEBUG ONLY! Output debug log for packets written.
### --thread-affinity [&lt;string1&gt;=]{&lt;string2&gt;[#&lt;int&gt;[:&lt;int&gt;]...] or 0x&lt;hex&gt;}
Set thread affinity to the process or threads of the application.
Expand Down
11 changes: 7 additions & 4 deletions NVEncC_Options.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,9 @@
- [--log \<string\>](#--log-string)
- [--log-level \[\<param1\>=\]\<value\>\[,\<param2\>=\<value\>\]...](#--log-level-param1valueparam2value)
- [--log-opt \<param1\>=\<value\>\[,\<param2\>=\<value\>\]...](#--log-opt-param1valueparam2value)
- [--log-framelist](#--log-framelist)
- [--log-packets](#--log-packets)
- [--log-framelist \[\<string\>\]](#--log-framelist-string)
- [--log-packets \[\<string\>\]](#--log-packets-string)
- [--log-mux-ts \[\<string\>\]](#--log-mux-ts-string)
- [--thread-affinity \[\<string1\>=\]{\<string2\>\[#\<int\>\[:\<int\>\]...\] or 0x\<hex\>}](#--thread-affinity-string1string2intint-or-0xhex)
- [--thread-priority \[\<string1\>=\]\<string2\>\[#\<int\>\[:\<int\>\]...\]](#--thread-priority-string1string2intint)
- [--thread-throttling \[\<string1\>=\]\<string2\>\[#\<int\>\[:\<int\>\]...\]](#--thread-throttling-string1string2intint)
Expand Down Expand Up @@ -2675,12 +2676,14 @@ file以外のプロトコルを使用する場合には、この出力バッフ
- addtime (デフォルト=off)
ログの各行に時刻を表示するように。
### --log-framelist
### --log-framelist [&lt;string&gt;]
avsw/avhw読み込み時のデバッグ情報出力。
### --log-packets
### --log-packets [&lt;string&gt;]
avsw/avhw読み込み時のデバッグ情報出力。
### --log-mux-ts [&lt;string&gt;]
デバッグ情報出力。
### --thread-affinity [&lt;string1&gt;=]{&lt;string2&gt;[#&lt;int&gt;[:&lt;int&gt;]...] or 0x&lt;hex&gt;}
NVEncCのプロセスやスレッドのスレッドアフィニティを設定する。具体的な指定方法は例を確認してください。
Expand Down
67 changes: 55 additions & 12 deletions NVEncCore/rgy_cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5097,7 +5097,7 @@ int parse_one_ctrl_option(const TCHAR *option_name, const TCHAR *strInput[], int
if (param_arg == _T("framelist")) {
bool b = false;
if (!cmd_string_to_bool(&b, param_val)) {
ctrl->logAddTime = b;
ctrl->logFramePosList.enable = b;
} else {
print_cmd_error_invalid_value(tstring(option_name) + _T(" ") + param_arg + _T("="), param_val);
return 1;
Expand All @@ -5107,7 +5107,17 @@ int parse_one_ctrl_option(const TCHAR *option_name, const TCHAR *strInput[], int
if (param_arg == _T("packets")) {
bool b = false;
if (!cmd_string_to_bool(&b, param_val)) {
ctrl->logAddTime = b;
ctrl->logPacketsList.enable = b;
} else {
print_cmd_error_invalid_value(tstring(option_name) + _T(" ") + param_arg + _T("="), param_val);
return 1;
}
continue;
}
if (param_arg == _T("mux-ts")) {
bool b = false;
if (!cmd_string_to_bool(&b, param_val)) {
ctrl->logMuxVidTs.enable = b;
} else {
print_cmd_error_invalid_value(tstring(option_name) + _T(" ") + param_arg + _T("="), param_val);
return 1;
Expand All @@ -5121,10 +5131,13 @@ int parse_one_ctrl_option(const TCHAR *option_name, const TCHAR *strInput[], int
ctrl->logAddTime = true;
continue;
} else if (param == _T("framelist")) {
ctrl->logFramePosList = true;
ctrl->logFramePosList.enable = true;
continue;
} else if (param == _T("packets")) {
ctrl->logPacketsList = true;
ctrl->logPacketsList.enable = true;
continue;
} else if (param == _T("mux-ts")) {
ctrl->logMuxVidTs.enable = true;
continue;
} else {
print_cmd_error_unknown_opt_param(option_name, param, paramList);
Expand All @@ -5142,16 +5155,30 @@ int parse_one_ctrl_option(const TCHAR *option_name, const TCHAR *strInput[], int
return parse_log_level_param(option_name, strInput[i], ctrl->loglevel);
}
if (IS_OPTION("log-framelist")) {
ctrl->logFramePosList = true;
ctrl->logFramePosList.enable = true;
if (i + 1 >= nArgNum || strInput[i + 1][0] == _T('-')) {
return 0;
}
i++;
ctrl->logFramePosList.filename = strInput[i];
return 0;
}
if (IS_OPTION("log-packets")) {
ctrl->logPacketsList = true;
ctrl->logPacketsList.enable = true;
if (i + 1 >= nArgNum || strInput[i + 1][0] == _T('-')) {
return 0;
}
i++;
ctrl->logPacketsList.filename = strInput[i];
return 0;
}
if (IS_OPTION("log-mux-ts")) {
ctrl->logMuxVidTs.enable = true;
if (i + 1 >= nArgNum || strInput[i + 1][0] == _T('-')) {
return 0;
}
i++;
ctrl->logMuxVidTsFile = _tcsdup(strInput[i]);
ctrl->logMuxVidTs.filename = strInput[i];
return 0;
}
if (IS_OPTION("max-procfps")) {
Expand Down Expand Up @@ -6629,9 +6656,24 @@ tstring gen_cmd(const RGYParamControl *param, const RGYParamControl *defaultPrm,
cmd << _T(" --log-opt ") << tmp.str().substr(1);
}
}
OPT_BOOL(_T("--log-framelist"), _T(""), logFramePosList);
OPT_BOOL(_T("--log-packets"), _T(""), logPacketsList);
OPT_CHAR_PATH(_T("--log-mux-ts"), logMuxVidTsFile);
if (param->logFramePosList.enable) {
cmd << _T(" --log-framelist");
if (param->logFramePosList.filename.length() > 0) {
cmd << _T(" \"") << param->logFramePosList.filename << _T("\"");
}
}
if (param->logPacketsList.enable) {
cmd << _T(" --log-packets");
if (param->logPacketsList.filename.length() > 0) {
cmd << _T(" \"") << param->logPacketsList.filename << _T("\"");
}
}
if (param->logMuxVidTs.enable) {
cmd << _T(" --log-mux-ts");
if (param->logMuxVidTs.filename.length() > 0) {
cmd << _T(" \"") << param->logMuxVidTs.filename << _T("\"");
}
}
OPT_BOOL(_T("--skip-hwenc-check"), _T(""), skipHWEncodeCheck);
OPT_BOOL(_T("--skip-hwdec-check"), _T(""), skipHWDecodeCheck);
OPT_STR_PATH(_T("--avsdll"), avsdll);
Expand Down Expand Up @@ -7433,8 +7475,9 @@ tstring gen_cmd_help_ctrl() {
_T(" additional options for log output.\n")
_T(" params\n")
_T(" addtime add time to log lines.\n")
_T(" --log-framelist output debug info for avsw/avhw reader.\n")
_T(" --log-packets output debug info for avsw/avhw reader.\n"));
_T(" --log-framelist [<string>] output debug info for avsw/avhw reader.\n")
_T(" --log-packets [<string>] output debug info for avsw/avhw reader.\n")
_T(" --log-mux-ts [<string>] output debug info for avsw/avhw reader.\n"));

str += strsprintf(_T("\n")
_T(" --option-file <string> read commanline options written in file.\n"));
Expand Down
7 changes: 4 additions & 3 deletions NVEncCore/rgy_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,8 @@ static RGY_ERR initOtherReaders(
inputInfoAVAudioReader.AVSyncMode = RGY_AVSYNC_ASSUME_CFR;
inputInfoAVAudioReader.seekSec = common->seekSec;
inputInfoAVAudioReader.seekToSec = common->seekToSec;
inputInfoAVAudioReader.logFramePosList = (ctrl->logFramePosList) ? src.filename + _T(".framelist.csv") : _T("");
inputInfoAVAudioReader.logFramePosList = ctrl->logFramePosList.getFilename(src.filename, _T(".framelist.csv"));
inputInfoAVAudioReader.logPackets = ctrl->logPacketsList.getFilename(src.filename, _T(".packets.csv"));
inputInfoAVAudioReader.threadInput = 0;
inputInfoAVAudioReader.threadParamInput = ctrl->threadParams.get(RGYThreadType::INPUT);
inputInfoAVAudioReader.timestampPassThrough = common->timestampPassThrough;
Expand Down Expand Up @@ -616,8 +617,8 @@ RGY_ERR initReaders(
inputInfoAVCuvid.AVSyncMode = RGY_AVSYNC_ASSUME_CFR;
inputInfoAVCuvid.seekSec = common->seekSec;
inputInfoAVCuvid.seekToSec = common->seekToSec;
inputInfoAVCuvid.logFramePosList = (ctrl->logFramePosList) ? common->outputFilename + _T(".framelist.csv") : _T("");
inputInfoAVCuvid.logPackets = (ctrl->logPacketsList) ? common->outputFilename + _T(".packets.csv") : _T("");
inputInfoAVCuvid.logFramePosList = ctrl->logFramePosList.getFilename(common->inputFilename, _T(".framelist.csv"));
inputInfoAVCuvid.logPackets = ctrl->logPacketsList.getFilename(common->inputFilename, _T(".packets.csv"));
inputInfoAVCuvid.threadInput = ctrl->threadInput;
inputInfoAVCuvid.threadParamInput = ctrl->threadParams.get(RGYThreadType::INPUT);
inputInfoAVCuvid.queueInfo = (perfMonitor) ? perfMonitor->GetQueueInfoPtr() : nullptr;
Expand Down
7 changes: 5 additions & 2 deletions NVEncCore/rgy_input_avcodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1470,6 +1470,7 @@ RGY_ERR RGYInputAvcodec::Init(const TCHAR *strFileName, VideoInfo *inputInfo, co
}
if (input_prm->logPackets.length() > 0) {
m_fpPacketList.reset(_tfopen(input_prm->logPackets.c_str(), _T("w")));
fprintf(m_fpPacketList.get(), " stream id, codec, pts, dts, duration, flags, pos\n");
}

// input-probesizeやinput-analyzeが小さすぎて動画情報を得られなかったときのためのretryループ (デフォルトでは無効)
Expand Down Expand Up @@ -2479,9 +2480,11 @@ std::tuple<int, std::unique_ptr<AVPacket, RGYAVDeleter<AVPacket>>> RGYInputAvcod
continue;
}
if (m_fpPacketList) {
fprintf(m_fpPacketList.get(), "stream %2d, %12s, pts, %s\n",
fprintf(m_fpPacketList.get(), "stream %2d, %12s, %s, %s,%5lld,%2d, %12lld\n",
pkt->stream_index, avcodec_get_name(m_Demux.format.formatCtx->streams[pkt->stream_index]->codecpar->codec_id),
pkt->pts == AV_NOPTS_VALUE ? "Unknown" : strsprintf("%lld", pkt->pts).c_str());
pkt->pts == AV_NOPTS_VALUE ? " Unknown" : strsprintf("%12lld", pkt->pts).c_str(),
pkt->dts == AV_NOPTS_VALUE ? " Unknown" : strsprintf("%12lld", pkt->dts).c_str(),
pkt->duration, pkt->flags, pkt->pos);
}
if (pkt->stream_index == m_Demux.video.index) {
if (pkt->flags & AV_PKT_FLAG_CORRUPT) {
Expand Down
14 changes: 8 additions & 6 deletions NVEncCore/rgy_input_avcodec.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,19 @@ class FramePosList {
if (filename == nullptr) {
return 1;
}
FILE *fp = NULL;
if (0 != _tfopen_s(&fp, filename, _T("wb"))) {
FILE *fp = nullptr;
if (0 != _tfopen_s(&fp, filename, _T("wb")) || fp == nullptr) {
return 1;
}
fprintf(fp, "pts,dts,duration,duration2,poc,flags,pic_struct,repeat_pict,pict_type\r\n");
fprintf(fp, " poc, T,flags,repeat, pts, dts,duration,duration2,pic_struct\r\n");
for (int i = 0; i < nList; i++) {
fprintf(fp, "%lld,%lld,%d,%d,%d,%d,%d,%d,%d\r\n",
fprintf(fp, "%8d,%2s,%2d,%2d,%12lld, %12lld, %6d, %6d, %s\r\n",
m_list[i].data.poc,
(m_list[i].data.pict_type == 1) ? "I" : ((m_list[i].data.pict_type == 2) ? "P" : ((m_list[i].data.pict_type == 3) ? "B" : "X")),
(int)m_list[i].data.flags, m_list[i].data.repeat_pict,
(lls)m_list[i].data.pts, (lls)m_list[i].data.dts,
m_list[i].data.duration, m_list[i].data.duration2,
m_list[i].data.poc,
(int)m_list[i].data.flags, (int)m_list[i].data.pic_struct, (int)m_list[i].data.repeat_pict, (int)m_list[i].data.pict_type);
tchar_to_string(picstrcut_to_str((RGY_PICSTRUCT)m_list[i].data.pic_struct)).c_str());
}
fclose(fp);
return 0;
Expand Down
2 changes: 1 addition & 1 deletion NVEncCore/rgy_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ RGY_ERR initWriters(
writerPrm.audioResampler = common->audioResampler;
writerPrm.audioIgnoreDecodeError = common->audioIgnoreDecodeError;
writerPrm.queueInfo = (pPerfMonitor) ? pPerfMonitor->GetQueueInfoPtr() : nullptr;
writerPrm.muxVidTsLogFile = (ctrl->logMuxVidTsFile) ? ctrl->logMuxVidTsFile : _T("");
writerPrm.muxVidTsLogFile = ctrl->logMuxVidTs.getFilename(common->outputFilename, _T(".muxts.log"));
writerPrm.bitstreamTimebase = av_make_q(outputTimebase);
writerPrm.chapterNoTrim = common->chapterNoTrim;
writerPrm.attachments = common->attachmentSource;
Expand Down
23 changes: 20 additions & 3 deletions NVEncCore/rgy_prm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1473,6 +1473,23 @@ bool GPUAutoSelectMul::operator!=(const GPUAutoSelectMul &x) const {
return !(*this == x);
}

RGYDebugLogFile::RGYDebugLogFile() : enable(false), filename() {}

bool RGYDebugLogFile::operator==(const RGYDebugLogFile &x) const {
return enable == x.enable
&& filename == x.filename;
}
bool RGYDebugLogFile::operator!=(const RGYDebugLogFile &x) const {
return !(*this == x);
}
tstring RGYDebugLogFile::getFilename(const tstring& outputFilename, const tstring& defaultAppendix) const {
if (!enable) return tstring();
if (filename.length() > 0) {
return filename;
}
return outputFilename + defaultAppendix;
}

RGYParamInput::RGYParamInput() :
resizeResMode(RGYResizeResMode::Normal) {

Expand Down Expand Up @@ -1552,9 +1569,9 @@ RGYParamControl::RGYParamControl() :
logfile(), //ログ出力先
loglevel(RGY_LOG_INFO), //ログ出力レベル
logAddTime(false),
logFramePosList(false), //framePosList出力
logPacketsList(false),
logMuxVidTsFile(nullptr),
logFramePosList(), //framePosList出力
logPacketsList(),
logMuxVidTs(),
threadOutput(RGY_OUTPUT_THREAD_AUTO),
threadAudio(RGY_AUDIO_THREAD_AUTO),
threadInput(RGY_INPUT_THREAD_AUTO),
Expand Down
16 changes: 13 additions & 3 deletions NVEncCore/rgy_prm.h
Original file line number Diff line number Diff line change
Expand Up @@ -1455,6 +1455,16 @@ struct GPUAutoSelectMul {
bool operator!=(const GPUAutoSelectMul &x) const;
};

struct RGYDebugLogFile {
bool enable;
tstring filename;

RGYDebugLogFile();
bool operator==(const RGYDebugLogFile &x) const;
bool operator!=(const RGYDebugLogFile &x) const;
tstring getFilename(const tstring& outputFilename, const tstring& defaultAppendix) const;
};

struct RGYParamInput {
RGYResizeResMode resizeResMode;

Expand Down Expand Up @@ -1537,9 +1547,9 @@ struct RGYParamControl {
tstring logfile; //ログ出力先
RGYParamLogLevel loglevel; //ログ出力レベル
bool logAddTime;
bool logFramePosList; //framePosList出力
bool logPacketsList;
TCHAR *logMuxVidTsFile;
RGYDebugLogFile logFramePosList; //framePosList出力
RGYDebugLogFile logPacketsList;
RGYDebugLogFile logMuxVidTs;
int threadOutput;
int threadAudio;
int threadInput;
Expand Down

0 comments on commit f46dedd

Please sign in to comment.