Skip to content

Commit

Permalink
RGBエンコードに対応。(--output-csp rgb)
Browse files Browse the repository at this point in the history
  • Loading branch information
rigaya committed Aug 6, 2024
1 parent b73c759 commit 5b3972a
Show file tree
Hide file tree
Showing 28 changed files with 1,821 additions and 999 deletions.
2 changes: 2 additions & 0 deletions NVEnc/NVEnc.en.lng
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ AuofcgLBQualityPreset=Quality
AuofcgLBEncCodec=Codec
AuofcgLBSlices=Slices
AuofcgLBOutBitDepth=Output bitdepth
AuofcgLBOutputCsp=Output colorspace
AuofcgLBMultiPass=Multi pass
AuofcgLBBrefMode=B Ref mode
AuofcgLBWeightP=WeightP
Expand Down Expand Up @@ -744,6 +745,7 @@ AuofrmTTfcgNUMaxkbps=Max bitrate (kbps).
AuofrmTTfcgNUVBRTragetQuality=Set Encode quality.
AuofrmTTfcgCXInterlaced=Set target video is progressive or interlaced.
AuofrmTTfcgCXOutBitDepth=Output bit depth.
AuofrmTTfcgCXOutputCsp=Output colorspace.
AuofrmTTfcgCXHEVCTier=Codec tier.
AuofrmTTfxgCXHEVCLevel=Codec level.
AuofrmTTfcgCXCodecLevelAV1=Codec level.
Expand Down
2 changes: 2 additions & 0 deletions NVEnc/NVEnc.ja.lng
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ AuofcgLBQualityPreset=品質
AuofcgLBEncCodec=出力形式
AuofcgLBSlices=スライス数
AuofcgLBOutBitDepth=出力ビット深度
AuofcgLBOutputCsp=出力色フォーマット
AuofcgLBMultiPass=マルチパス
AuofcgLBBrefMode=Bフレーム参照モード
AuofcgLBWeightP=重み付きPフレーム
Expand Down Expand Up @@ -743,6 +744,7 @@ AuofrmTTfcgNUMaxkbps=最大ビットレート(kbps)。
AuofrmTTfcgNUVBRTragetQuality=エンコード品質と速度の調整を行います。
AuofrmTTfcgCXInterlaced=エンコード対象がプログレッシブあるいはインターレースかを指定します。
AuofrmTTfcgCXOutBitDepth=出力ビット深度を指定します。
AuofrmTTfcgCXOutputCsp=出力色フォーマットを指定します。\n\nyuv420 ... 通常はこちらを使用します。
AuofrmTTfcgCXHEVCTier=コーデックのTier。
AuofrmTTfxgCXHEVCLevel=コーデックのレベル。
AuofrmTTfcgCXCodecLevelAV1=コーデックのレベル。
Expand Down
2 changes: 2 additions & 0 deletions NVEnc/NVEnc.zh.lng
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ AuofcgLBQualityPreset=质量
AuofcgLBEncCodec=导出格式
AuofcgLBSlices=分片数
AuofcgLBOutBitDepth=导出比特位深
AuofcgLBOutputCsp=输出色彩空间
AuofcgLBMultiPass=多通道编码
AuofcgLBBrefMode=B帧参考模式
AuofcgLBWeightP=加权P帧
Expand Down Expand Up @@ -743,6 +744,7 @@ AuofrmTTfcgNUMaxkbps=最大码率(kbps)。
AuofrmTTfcgNUVBRTragetQuality=调整编码质量和速度。
AuofrmTTfcgCXInterlaced=指定编码对象为逐行扫描或隔行扫描。
AuofrmTTfcgCXOutBitDepth=指定导出比特位深。
AuofrmTTfcgCXOutputCsp=指定输出色彩空间。
AuofrmTTfcgCXHEVCTier=编码器等级。
AuofrmTTfxgCXHEVCLevel=编码器级别。
AuofrmTTfcgCXCodecLevelAV1=编码器级别。
Expand Down
5 changes: 5 additions & 0 deletions NVEnc/NVEnc_readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ NVIDIA グラフィックドライバ 551.23
今後の更新で設定ファイルの互換性がなくなるかもしれません。

【メモ】
2024.08.06 (7.61)
- RGB出力機能を追加。(--output-csp rgb)
- YUVA420出力機能を追加。(--output-csp yuva420)
- HEVC 8bit YUVA420 専用

2024.08.04 (7.60)
- --vpp-resize ngx-vsrを使用すると、その後の処理が正常に動作しない問題を修正。
- ivf形式で出力する際は、timebaseをfpsの逆数に設定するように。
Expand Down
22 changes: 14 additions & 8 deletions NVEnc/encode/auo_video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ int get_aviutl_color_format(int use_highbit, RGY_CSP csp) {
}

switch (chromafmt) {
case RGY_CHROMAFMT_YUVA444:
case RGY_CHROMAFMT_RGB:
return CF_RGB;
case RGY_CHROMAFMT_YUV444:
return CF_YC48;
case RGY_CHROMAFMT_YUV420:
Expand All @@ -99,10 +100,14 @@ void get_csp_and_bitdepth(bool& use_highbit, RGY_CSP& csp, const CONF_GUIEX *con
enc_prm.yuv444 = true;
}
use_highbit = enc_prm.outputDepth > 8;
if (use_highbit) {
csp = (enc_prm.yuv444) ? RGY_CSP_YUV444_16 : RGY_CSP_P010;
if (enc_prm.rgb) {
csp = RGY_CSP_RGB;
} else {
csp = (enc_prm.yuv444) ? RGY_CSP_YUV444 : RGY_CSP_NV12;
if (use_highbit) {
csp = (enc_prm.yuv444) ? RGY_CSP_YUV444_16 : RGY_CSP_P010;
} else {
csp = (enc_prm.yuv444) ? RGY_CSP_YUV444 : RGY_CSP_NV12;
}
}
}

Expand Down Expand Up @@ -385,7 +390,7 @@ static int send_frame(
simd = RGY_SIMD::AVX | RGY_SIMD::POPCNT | RGY_SIMD::SSE42 | RGY_SIMD::SSE41 | RGY_SIMD::SSSE3 | RGY_SIMD::SSE2;
} else {
//SIMDの要求する値で割り切れない場合は、一時バッファを使用してpitchがあるようにする
tempBufForNonModWidthPitch = ALIGN(oip->w, 128) * ((input_csp == RGY_CSP_YC48) ? 6 : 2);
tempBufForNonModWidthPitch = ALIGN(oip->w, 128) * ((input_csp == RGY_CSP_YC48) ? 6 : ((input_csp == RGY_CSP_RGB24R) ? 3 : 2));
tempBufForNonModWidth = std::unique_ptr<uint8_t, aligned_malloc_deleter>(
(uint8_t*)_aligned_malloc(tempBufForNonModWidthPitch * oip->h, 128), aligned_malloc_deleter());
}
Expand Down Expand Up @@ -426,6 +431,7 @@ static int send_frame(
case RGY_CSP_YUV444_12:
case RGY_CSP_YUV444_14:
case RGY_CSP_YUV444_16:
case RGY_CSP_RGB:
dst_array[2] = (uint8_t*)dst_array[1] + prmsm->pitch * prmsm->h;
case RGY_CSP_NV12:
case RGY_CSP_P010:
Expand All @@ -435,7 +441,7 @@ static int send_frame(
//コピーフレームの場合は、映像バッファの中身を更新せず、そのままパイプに流す
if (!copy_frame) {
uint8_t* ptr_src = (uint8_t*)frame;
int src_pitch = (input_csp == RGY_CSP_YC48) ? oip->w * 6 : oip->w * 2;
int src_pitch = (input_csp == RGY_CSP_YC48) ? oip->w * 6 : ((input_csp == RGY_CSP_RGB24R) ? oip->w * 3 : oip->w * 2);
if (tempBufForNonModWidth) { //SIMDの要求する値で割り切れない場合は、一時バッファを使用してpitchがあるようにする
for (int j = 0; j < oip->h; j++) {
auto dst = tempBufForNonModWidth.get() + tempBufForNonModWidthPitch * j;
Expand All @@ -449,7 +455,7 @@ static int send_frame(
convert->run((enc_prm.input.picstruct & RGY_PICSTRUCT_INTERLACED) ? 1 : 0,
dst_array, (const void**)&ptr_src, oip->w,
src_pitch,
(input_csp == RGY_CSP_YC48) ? src_pitch : src_pitch >> 1,
(input_csp == RGY_CSP_YC48) ? src_pitch : ((input_csp == RGY_CSP_RGB24R) ? src_pitch : src_pitch >> 1),
prmsm->pitch, oip->h, oip->h, dummy);
}
prmsm->timestamp[sendFrame & 1] = (int64_t)i * 4;
Expand Down Expand Up @@ -583,7 +589,7 @@ static DWORD video_output_inside(CONF_GUIEX *conf, const OUTPUT_INFO *oip, PRM_E

//YUY2/YC48->NV12/YUV444, RGBコピー用関数
const int input_csp_idx = get_aviutl_color_format(output_highbit_depth, rgy_output_csp);
const RGY_CSP input_csp = (input_csp_idx == CF_YC48) ? RGY_CSP_YC48 : RGY_CSP_YUY2;
const RGY_CSP input_csp = (input_csp_idx == CF_YC48) ? RGY_CSP_YC48 : ((input_csp_idx == CF_RGB) ? RGY_CSP_RGB24R : RGY_CSP_YUY2);

//自動フィールドシフト関連
if (pe->muxer_to_be_used != MUXER_DISABLED) {
Expand Down
3 changes: 2 additions & 1 deletion NVEnc/frm/auo_mes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ static const char * AUO_MES_ID_NAME_STR[] = {
"AuofcgLBEncCodec",
"AuofcgLBSlices",
"AuofcgLBOutBitDepth",
"AuofcgLBOutputCsp",
"AuofcgLBMultiPass",
"AuofcgLBBrefMode",
"AuofcgLBWeightP",
Expand Down Expand Up @@ -788,6 +789,7 @@ static const char * AUO_MES_ID_NAME_STR[] = {
"AuofrmTTfcgNUVBRTragetQuality",
"AuofrmTTfcgCXInterlaced",
"AuofrmTTfcgCXOutBitDepth",
"AuofrmTTfcgCXOutputCsp",
"AuofrmTTfcgCXHEVCTier",
"AuofrmTTfxgCXHEVCLevel",
"AuofrmTTfcgCXCodecLevelAV1",
Expand Down Expand Up @@ -833,7 +835,6 @@ static const char * AUO_MES_ID_NAME_STR[] = {
"AuofrmTTfcgAMPLimitFileSize",
"AuofrmTTfcgBTApplyPreset",
"AuofrmTTfcgCXNalHrd",
"AuofrmTTfcgCXOutputCsp",
"AuofrmTTfcgCXInputRangeYUVLimited",
"AuofrmTTfcgCXInputRangeYUVFull",
"AuofrmTTfcgCXInputRangeRGB",
Expand Down
3 changes: 2 additions & 1 deletion NVEnc/frm/auo_mes.h
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ enum AuoMes {
AuofcgLBEncCodec,
AuofcgLBSlices,
AuofcgLBOutBitDepth,
AuofcgLBOutputCsp,
AuofcgLBMultiPass,
AuofcgLBBrefMode,
AuofcgLBWeightP,
Expand Down Expand Up @@ -879,6 +880,7 @@ enum AuoMes {
AuofrmTTfcgNUVBRTragetQuality,
AuofrmTTfcgCXInterlaced,
AuofrmTTfcgCXOutBitDepth,
AuofrmTTfcgCXOutputCsp,
AuofrmTTfcgCXHEVCTier,
AuofrmTTfxgCXHEVCLevel,
AuofrmTTfcgCXCodecLevelAV1,
Expand Down Expand Up @@ -926,7 +928,6 @@ enum AuoMes {
AuofrmTTfcgAMPLimitFileSize,
AuofrmTTfcgBTApplyPreset,
AuofrmTTfcgCXNalHrd,
AuofrmTTfcgCXOutputCsp,
AuofrmTTfcgCXInputRangeYUVLimited,
AuofrmTTfcgCXInputRangeYUVFull,
AuofrmTTfcgCXInputRangeRGB,
Expand Down
13 changes: 13 additions & 0 deletions NVEnc/frm/frmConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,7 @@ System::Void frmConfig::InitComboBox() {
setComboBox(fcgCXHEVCMaxCUSize, list_hevc_cu_size);
setComboBox(fcgCXHEVCMinCUSize, list_hevc_cu_size);
setComboBox(fcgCXOutBitDepth, list_bitdepth);
setComboBox(fcgCXOutputCsp, list_output_csp, "yuva420");
setComboBox(fcgCXCodecProfileAV1, av1_profile_names);
setComboBox(fcgCXCodecLevelAV1, list_av1_level);
setComboBox(fcgCXAQ, list_aq);
Expand Down Expand Up @@ -1198,6 +1199,7 @@ System::Void frmConfig::LoadLangText() {
LOAD_CLI_TEXT(fcgLBEncCodec);
LOAD_CLI_TEXT(fcgLBSlices);
LOAD_CLI_TEXT(fcgLBOutBitDepth);
LOAD_CLI_TEXT(fcgLBOutputCsp);
LOAD_CLI_TEXT(fcgLBMultiPass);
LOAD_CLI_TEXT(fcgLBBrefMode);
LOAD_CLI_TEXT(fcgLBWeightP);
Expand Down Expand Up @@ -1442,6 +1444,14 @@ System::Void frmConfig::ConfToFrm(CONF_GUIEX *cnf) {
fcgCBLossless->Checked = 0 != encPrm.lossless;
SetCXIndex(fcgCXOutBitDepth, get_cx_index(list_bitdepth, encPrm.outputDepth));

RGY_CSP outputCsp = RGY_CSP_YV12;
if (encPrm.rgb) {
outputCsp = RGY_CSP_RGB;
} else if (encPrm.yuv444) {
outputCsp = RGY_CSP_YUV444;
}
SetCXIndex(fcgCXOutputCsp, get_cx_index(list_output_csp, outputCsp));

//QPDetail
fcgCBQPMin->Checked = encPrm.qpMin.enable;
fcgCBQPMax->Checked = encPrm.qpMax.enable;
Expand Down Expand Up @@ -1704,6 +1714,8 @@ System::String^ frmConfig::FrmToConf(CONF_GUIEX *cnf) {
encPrm.preset = list_nvenc_preset_names_ver10[fcgCXQualityPreset->SelectedIndex].value;
encPrm.multipass = (NV_ENC_MULTI_PASS)list_nvenc_multipass_mode[fcgCXMultiPass->SelectedIndex].value;
encPrm.brefMode = list_bref_mode[fcgCXBrefMode->SelectedIndex].value;
encPrm.yuv444 = list_output_csp[fcgCXOutputCsp->SelectedIndex].value == RGY_CSP_YUV444 || list_output_csp[fcgCXOutputCsp->SelectedIndex].value == RGY_CSP_RGB;
encPrm.rgb = list_output_csp[fcgCXOutputCsp->SelectedIndex].value == RGY_CSP_RGB;

int nLookaheadDepth = (int)fcgNULookaheadDepth->Value;
if (nLookaheadDepth > 0) {
Expand Down Expand Up @@ -2185,6 +2197,7 @@ System::Void frmConfig::SetHelpToolTips() {
SET_TOOL_TIP_EX(fcgNUVBRTragetQuality);
SET_TOOL_TIP_EX(fcgCXInterlaced);
SET_TOOL_TIP_EX(fcgCXOutBitDepth);
SET_TOOL_TIP_EX(fcgCXOutputCsp);
SET_TOOL_TIP_EX(fcgCXHEVCTier);
SET_TOOL_TIP_EX(fxgCXHEVCLevel);
SET_TOOL_TIP_EX(fcgCXCodecProfileAV1);
Expand Down
Loading

0 comments on commit 5b3972a

Please sign in to comment.