rigaya様
NVEncのアップデート、いつもありがとうございます。
私の用途には殆ど影響がなかったのでずっと4.69を使っていたのですが、この度nnediとdecimateを組で使わないときれいにエンコード&24fps化が出来ないtsファイルの処理のため、一気に7.30までバージョンアップしたところ、いくつか(私にとっての)問題点が出たので、ご報告します。
以下3点、長くなるので分割して投稿します。
1.音声の外部エンコーダ使用について
4.69のころ、WOWOW等のnon-DualMonoな複数音声トラックのあるtsファイルやスタチャンの英語/吹き替えの2本のtsファイルから音声多重化mp4を作るため、編集中のtsファイルからの生のfaw出力を外部音声とmuxする処理をバッチで書いてbin to exe変換ツールでエンコーダとして登録して(仮にhogehoge.exeとします)使用していました。これは、muxする時にwavpathやsavfile、mode等の実際のファイルやパラメータを使いたかったためです(エンコ後では全部きれいに消えているので、エンコ後バッチでは対応できないのです)。
ところが、7.30で同じようにNVEnc.iniを編集して実行したところ、(外部エンコーダとして)「hogehoge.exeを使用します」、とログ画面に表示されるものの、次の行で「faw2aacでエンコードを行います」、と表示されてエンコードするtsファイルをaacfaw.aui経由で取り込んだfawだけがエンコードされてしまいます。
試しにNVEnc.iniに以下のメニューを追加して音声のみ出力の指定で実行したところ、下記のようなログとなり、fawcl.exeが使われた形跡がありません。
当然のことながら、FAWCheckのチェックボックスはOFFにしてあります。
4.xxから仕様が変わった部分で違いが出ていると思われますので、調べていただけませんでしょうか。
外部と内部の音声エンコーダの切り替えは、確か5.xxから導入されたと思いますので、古い話で恐縮ですがお願いします。
=====NVEnc.iniの追加分=====
[AUDIO]
;音声エンコーダリスト 音声エンコーダのセクション名になります。[SETTING_xxx]みたいな感じ
count=19 <---この行を修正
audio_encoder_1=AAC_NERO
audio_encoder_2=AAC_FAW
audio_encoder_3=AAC_QTAAC
audio_encoder_4=MP3_LAME
audio_encoder_5=AAC_EXT_BS
audio_encoder_6=AC3_FFMPEG
audio_encoder_7=OGG_VORBIS
audio_encoder_8=WAV
audio_encoder_9=AAC_QAAC
audio_encoder_10=ALAC_REFALAC
audio_encoder_11=MP4ALSRM23
audio_encoder_12=AAC_FDKAAC_FFMPEG
audio_encoder_13=FLAC
audio_encoder_14=AAC_FDKAAC
audio_encoder_15=OGG_OPUS
audio_encoder_16=AAC_FFMPEG
audio_encoder_17=ALAC_FFMPEG
audio_encoder_18=MP3_FFMPEG
audio_encoder_19=TEST_FAWCL <---この行を追加
(中略)
[SETTING_TEST_FAWCL]
dispname="FAWCLで(FAW)"
codec="fawcl"
filename="fawcl.exe"
aud_appendix="_audio.aac"
pipe_input=0
base_cmd=" "%{wavpath}" "%{savfile}" "
[MODE_TEST_FAWCL]
count=1
;AAC_FAWのフルサイズ用を1番目、ハーフサイズ用を2番目に書きます。
;入れ替えたりしないでください。壊れます。
mode_1=" FAW解除(full size)"
mode_1_cmd=""
=====4.69の実行ログ=====
auo [info]: 音声のみ出力を行います。
auo [info]: FAWCLで(FAW) で音声エンコードを行います。 FAW解除(full size)
auo [info]: "..\aviutl\fawcl\fawcl.exe" "(tsファイル名).tmp.wav" "(tsファイル名)"
FAWCLで(FAW) [info]: FakeAacWav Command Line Version 0.11 (FakeAacWav ver0.28)
FAWCLで(FAW) [info]: 入力サイズ:1,058,869,056 Bytes, サンプリング周波数:48000 Hz, チャンネル数:2
FAWCLで(FAW) [info]: 処理状況 : 10%
FAWCLで(FAW) [info]:
auo [info]: FAWCLで(FAW) CPU使用率: 15.70%
auo [info]: 総エンコード時間 : 0時間 0分10.4秒
2023年8月22日 17時01分 エンコード終了
=====7.30の実行ログ=====
auo [info]: 音声のみ出力を行います。
auo [info]: FAWCLで(FAW)として "H:\aviutl\aviutl\fawcl\fawcl.exe" を使用します。
auo [info]: faw2aac で音声エンコードを行います。
auo [info]: 総エンコード時間 : 0時間 0分 7.8秒
2.vpp-nnedi vpp-afs vpp-yadifについて
aviutlやNVEncの追加コマンド枠でcropを使って上下をクロップした動画をエンコードすると、再生時に画面の上端や下端に緑やピンク(?)の横線が入る場合があります(potplayerの内蔵エンコーダとLAV Video Decorderで確認)。
クロップした結果が4の倍数でない場合に起きるようです。
仕様のような気もしますが、ドキュメントには特に制限が書かれていないので…
NVEncのオプションは
auo [info]: NVEnc options...
-d 0 -c hevc -u quality --interlace tff --cqp 20:23:25 --qp-init 20:23:25 --lookahead 32 --gop-len auto --bref-mode each
--weightp --aq --aq-temporal --aq-strength 7 --profile main10 --output-depth 10 --no-mp4opt --vpp-nnedi quality=slow
--log-level debug -o "(出力ファイル名).mp4" --sm --parent-pid 00001c70 -i -
nnediのパラメータは
nnedi: nnedi: field auto, nns 32, nsize 32x4, quality fast, prec fp16
pre_screen new_block, errortype abs, weight "internal"
ちなみに、clfilter.aufのnnediでクロップ後の動画を処理した場合は、クロップ結果が偶数であれば、線無しで問題なくエンコードできているようです。
※当初vpp-nnediで発生したのを確認していたのですが、その後vpp-afsとvpp-yadifでも確認したところ、同じように横線が入りました。インタレ解除用のフィルタに受け渡されるときに、何か問題があるようにも思われます。
3.vpp-decimateについて
明らかにファイル依存なのですが(20ファイルエンコードして1件だけ発生しました)、NVEncでnnediを掛けて、追加コマンド枠で--vpp-decimateを追加したところ、以下のエラーでエンコードできませんでした。
decimate: Unexpected frame duration -42545 for frame = 42550.
decimate: Unexpected frame duration -42545 for frame = 42551.
decimate: Unexpected frame duration -42545 for frame = 42552.
decimate: Unexpected frame duration -42545 for frame = 42553.
Sending frame #42550 to encoder: timestamp 170200, duration -42545
Sending frame #42551 to encoder: timestamp 127655, duration -42545
Sending frame #42552 to encoder: timestamp 85110, duration -42545
Sending frame #42553 to encoder: timestamp 42565, duration -42545
avout: Error: Failed to write video frame: Invalid argument.
Error occurred in ProcessOutput: 20
avout: Error: Failed to write video frame: Invalid argument.
Error occurred in ProcessOutput: 20
Error FlushEncoder: 20.
avout: Closing...
avout: Error: Failed to write video frame: Invalid argument.
avout: closed audio process thread default.
avout: closed audio encode thread default.
avout: closed output thread...
avout: closed queues...
avout: Closed avformat context.
avout: Closed File Pointer.
avout: Closed format.
avout: Closed video context.
avout: Closed video.
avout: Closed.
sm: Closing...
sm: Close...
encoded 34044 frames, 132.58 fps, 700.51 kbps, 118.57 MB
encode time 0:04:16, CPU: 6.8, GPU: 56.1, VE: 38.6, GPUClock: 1927MHz, VEClock: 1781MHz
frame type IDR 280
frame type I 280, avgQP 20.00, total size 11.96 MB
frame type P 9258, avgQP 23.00, total size 71.16 MB
frame type B 24506, avgQP 25.00, total size 35.45 MB
avout: Closing...
avout: closed output thread...
avout: closed queues...
avout: Closed format.
avout: Closed video.
avout: Closed.
Released IO Buffers.
gpuinfo: Closing device #0: NVIDIA GeForce GTX 1660...
gpuinfo: Closing Encoder...
nvenc : nvEncDestroyEncoder...
nvenc : nvEncDestroyEncoder: success.
gpuinfo: Closed Encoder.
gpuinfo: Closed cuvid Ctx Lock...
gpuinfo: Closed cuvid Ctx Lock.
gpuinfo: Closed CUDA Context...
gpuinfo: Closed CUDA Context.
gpuinfo: Closed device #0: NVIDIA GeForce GTX 1660.
Closing EncodeStatus...
Closed EncodeStatus.
Closing perf monitor...
perf monitor: Closing thread...
perf monitor: Closed thread.
perf monitor: Closing perf counter...
perf monitor: Closed perf counter.
Closing logger...
[hevc @ 00000226824599c0] ignoring invalid SAR: 0/0
Output #0, mp4, to '(出力ファイル名).0.mp4':
Metadata:
encoding_tool : NVEncC (x64) 7.30
encoder : Lavf59.37.100
Stream #0:0, 0, 1/120000: Video: hevc (Main 10), 1 reference frame (hev1 / 0x31766568), yuv420p10le(progressive), 1280x720
(0x0), 0/1, q=2-31, 200 kb/s, 23.98 fps, 120k tbn
[mp4 @ 0000022682459040] Packet with invalid duration -42587545 in stream 0
[mp4 @ 0000022682459040] Packet with invalid duration -42587545 in stream 0
[mp4 @ 0000022682459040] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 170360190 >= 42607565
[mp4 @ 0000022682459040] Packet with invalid duration -42587545 in stream 0
[mp4 @ 0000022682459040] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 170360190 >= 127782655
[mp4 @ 0000022682459040] Packet with invalid duration -42587545 in stream 0
[mp4 @ 0000022682459040] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 170360190 >= 85195110
auo [info]: CPU使用率: Aviutl: 35.08% / NVEnc: 6.83%
auo [info]: Aviutl 平均フレーム取得時間: 5.264 ms
auo [info]: NVEncエンコード時間 : 0時間 4分18.9秒
vpp-decimateのログをとって実行した結果も取れたので、以下に示します(冒頭と、異常が発生した部分近傍のみ抜粋)
[S ] 0: 0: diff total 9223372036854775807, max 9223372036854775807
[ ] 1: 5: diff total 83048029, max 523298
[ PDL1] 2: -1: diff total 77069073, max 487925
[ ] 3: 10: diff total 79241973, max 578286
[ ] 4: 15: diff total 86706917, max 535530
[ PDL1] 5: -1: diff total 23741512, max 105560
[ ] 6: 20: diff total 93098701, max 531590
[ ] 7: 25: diff total 99573919, max 556367
[ ] 8: 30: diff total 95558937, max 508610
[ ] 9: 35: diff total 91072936, max 551692
[ PDL1] 10: -1: diff total 44590123, max 105321
[ ] 11: 40: diff total 100386355, max 556527
[ ] 12: 45: diff total 89331953, max 485587
[ ] 13: 50: diff total 100029895, max 567066
[ ] 14: 55: diff total 98332637, max 526755
[ PDL1] 15: -1: diff total 22851575, max 96591
[ ] 16: 60: diff total 107732814, max 458789
[ ] 17: 65: diff total 101013008, max 549989
[ ] 18: 70: diff total 101591192, max 527337
[ ] 19: 75: diff total 104226923, max 467462
[ PDL1] 20: -1: diff total 41716767, max 72354
(中略)
[ ] 42500: 170000: diff total 21333621, max 78449
[ ] 42501: 170005: diff total 22268852, max 85395
[ PDL1] 42502: -1: diff total 15119799, max 68356
[ ] 42503: 170010: diff total 16286698, max 87228
[ ] 42504: 170015: diff total 18201224, max 93810
[ PDL1] 42505: -1: diff total 13355222, max 60979
[ ] 42506: 170020: diff total 34980438, max 90103
[ ] 42507: 170025: diff total 23052032, max 63072
[ ] 42508: 170030: diff total 30406326, max 70974
[ ] 42509: 170035: diff total 25102327, max 65690
[ ] 42510: 170040: diff total 12454698, max 58208
[ ] 42511: 170045: diff total 14258963, max 50276
[ PDL1] 42512: -1: diff total 16481255, max 50101
[ ] 42513: 170050: diff total 19534690, max 57018
[ ] 42514: 170055: diff total 15420256, max 52156
[ ] 42515: 170060: diff total 21848105, max 83114
[ ] 42516: 170065: diff total 22334166, max 89392
[ ] 42517: 170070: diff total 14852024, max 91089
[ PDL1] 42518: -1: diff total 15796729, max 66733
[ ] 42519: 170075: diff total 18728030, max 94448
[ ] 42520: 170080: diff total 13687043, max 90151
[ ] 42521: 170085: diff total 33903283, max 75042
[ ] 42522: 170090: diff total 21824992, max 67627
[ ] 42523: 170095: diff total 28955197, max 74388
[ PDL1] 42524: -1: diff total 25165156, max 64432
[ PDL1] 42525: -1: diff total 11847556, max 47758
[ ] 42526: 170100: diff total 13720893, max 54224
[ ] 42527: 170105: diff total 14466689, max 60476
[ ] 42528: 170110: diff total 20340349, max 58186
[ ] 42529: 170115: diff total 15652338, max 64510
[ ] 42530: 170120: diff total 20861842, max 88452
[ ] 42531: 170125: diff total 22807352, max 97430
[ ] 42532: 170130: diff total 16023668, max 89294
[ PDL1] 42533: -1: diff total 15652787, max 83056
[ ] 42534: 170135: diff total 18838105, max 90417
[ ] 42535: 170140: diff total 13779221, max 77529
[ ] 42536: 170145: diff total 32795849, max 78903
[ ] 42537: 170150: diff total 22877045, max 76636
[ ] 42538: 170155: diff total 29640421, max 72565
[ PDL1] 42539: -1: diff total 25955884, max 66250
[ ] 42540: 170160: diff total 10646215, max 62699
[ PDL1] 42541: -1: diff total 12909630, max 54972
[ ] 42542: 170165: diff total 15041129, max 58947
[ ] 42543: 170170: diff total 20056703, max 66649
[ ] 42544: 170175: diff total 15593596, max 58528
[ ] 42545: 170180: diff total 20659602, max 64326
[ ] 42546: 170185: diff total 22477782, max 75870
[ PDL1] 42547: -1: diff total 15277669, max 62912
[ ] 42548: 170190: diff total 16462982, max 72904
[ ] 42549: 170195: diff total 19041732, max 75478
[ ] 42550: 170200: diff total 14853565, max 98752
[ ] 42551: 127655: diff total 34547334, max 83179
[ ] 42552: 85110: diff total 21992771, max 71008
[ ] 42553: 42565: diff total 32809359, max 79829
[ PDL1] 42554: -1: diff total 20833668, max 64449
該当ファイルはアニメの録画で、エンコード対象フレームはaviutlでカット後で0~42554、エラーが起きているのはエンディングテーマのドンケツで、見た目で静止画が100フレーム強連続している部分です。
NVEncのオプションは
auo [info]: NVEnc options...
-d 0 -c hevc -u quality --interlace tff --output-res 1280x720 --cqp 20:23:25 --qp-init 20:23:25 --lookahead 32 --gop-len
auto --bref-mode each --weightp --aq --aq-temporal --aq-strength 7 --profile main10 --output-depth 10 --no-mp4opt --vpp-nnedi
quality=slow --log-level debug --vpp-decimate log=on -o "(出力ファイル名).0.mp4" --sm --parent-pid 00001c70 -i -
nnedi,decimateのパラメータは以下の通りでした。
nnedi: field auto, nns 32, nsize 32x4, quality slow, prec fp16
pre_screen new_block, errortype abs, weight "internal"
decimate: cycle 5, drop 1, threDup 1.10, threSC 15.00
block 32x32, chroma on, log on
これは、vpp-yadifとの組み合わせでも全く同じ個所でエラーが発生しています。
auo [info]: NVEnc options...
-d 0 -c hevc -u quality --interlace tff --output-res 1280x720 --cqp 20:23:25 --qp-init 20:23:25 --lookahead 32 --gop-len
auto --bref-mode each --weightp --aq --aq-temporal --aq-strength 7 --profile main10 --output-depth 10 --no-mp4opt --vpp-yadif
--log-level debug --vpp-decimate -o ""(出力ファイル名).0.mp4" --sm --parent-pid 00001c70 -i -
yadif,decimateのパラメータは
yadif: mode auto
decimate: cycle 5, drop 1, threDup 1.10, threSC 15.00
block 32x32, chroma on, log off
また、同じtsファイルで後ろを少し余分にエンコードした場合(追加部分はCMの頭で、白地に濃紺文字でKAD〇KAWAと書かれているモノ、当然静止画状態)は、上記のエラーが出ていたフレームで3列目の数値が急に減少することもなくエラーなしで完了しました。
一体全体何が起きているのか、また発生した場合有効な回避手段はあるのか、分かれば助かります。
以上3点、追加で必要な作業や情報がありましたらご指示ください。
ちなみに環境は
4.69環境
NVEncC (x64) 4.69 (r1409) by rigaya, Mar 25 2020 22:42:16 (VC 1924/Win/avx2)
OS Version Windows 10 x64 (19045)
CPU Intel Core i5-8500 @ 3.00GHz [TB: 3.91GHz] (6C/6T)
GPU #0: NVIDIA GeForce GTX 1660 (1408 cores, 1830 MHz)[PCIe3x16][536.99]
NVENC / CUDA NVENC API 9.1, CUDA 12.2, schedule mode: auto
7.30環境
NVEncC (x64) 7.30 (r2572) by rigaya, Jun 24 2023 02:43:35 (VC 1929/Win)
OS Version Windows 10 x64 (19045) [UTF-8]
CPU Intel Core i5-8500 @ 3.00GHz [TB: 3.92GHz] (6C/6T)
GPU #0: NVIDIA GeForce GTX 1660 (1408 cores, 1830 MHz)[PCIe3x16][536.99]
NVENC / CUDA NVENC API 12.1, CUDA 12.2, schedule mode: auto
です。
1.
5.xx以降のFAW処理は特殊処理になっていて、現状は組み込み処理になっており、外部エンコーダを使用しません。
これは3つ理由があって
- faw2aac.auoの入手性が悪くなった
- 今後は内蔵muxerを主体に考え、外部muxerを使用しないようにすることで実装を簡素化したい
- 問題の生じることの多い一時ファイル関連の処理をスキップしたい
ためです。
組み込み処理実行のトリガーとしては、codecに "faw" という文字列が含まれること(大文字小文字問わない)としており、
この条件を満たすときは必ず組み込み処理に移行します。
したがって、独自処理を行いたい場合には codec に "faw" を含まない形にしてください。
(FakeAACWaveなどにすればよいのではないかと思います)
2.
結論から言うと仕様です。4の倍数でないと、正常に処理できません。
NVEnc内ではYUV420処理になりますが、このとき色成分(UV)に関しては実効解像度が半減しています。
インタレは2lineでペアで、これは色成分に関しても同じですから、輝度(Y)の解像度に換算すると4の倍数でないと成立しないことになります。
4の倍数になるほうな解像度は多く知られていると思いますので、そのなかから選択するようにしてください。
clfilter.aufのnnediはYUV444処理のため、4の倍数制限ではなく、2の倍数制限となります。NVEncではYUV420出力時はフィルタもYUV420で処理します。簡略化のため、フィルタ部のみのYUV444への変更はサポートしません。
3. > 一体全体何が起きているのか
あまりこうした症状が出たことがないので、わたしもよくわからないです…
rigaya様
回答ありがとうございます。
お礼が遅くなりすみません。何度やっても「もう一度やり直してください」が出てしまって…
1は、エンコーダの名前が鍵だったんですね。修正して無事動きました。
5.xx以降の変更で一時ファイル名が4.xxと違う(ファイル名の後ろに「.0」がくっついていた)のが分かり少し手直しが必要でしたが、7.30で無事に動いています。
2は仕様、というより原理から推測可能なレベルのお話だったようで、未だ色空間とかインタレ解除の話とか表面しかなぞっていない自分が少々情けない感もあります。解説ありがとうございました。
3は…まぁ、今回は後ろ5フレームくらい全く影響がないからカットで逃げてもいいし、実は再放送枠での同じ話数の回ではエラーが発生していないというのもあって今回は回避できそうです。
一応
Application provided invalid, non monotonically increasing dts to muxer in stream 0:
のメッセージをググってみたんですが、ffmpegでDTSがおかしいときに起きるとか書いてあるのを見つけて、TSファイル用のDTS再構築のperlスクリプトとか入手してみたんですが、このスクリプトがうまく動かなくて。
他にも行き当たりばったりでaviutl側でバンディング低減を掛けると通ったりして…とよくわからなくなってます(^^;)
1. ".0" では一時ファイルで既存のファイルを上書きしないように追加するものです。(エラーが発生する可能性もあるので、エンコードに成功するまでは、既存ファイルを消してしまわないほうが無難と判断して変更しました)
そのため、".0"のファイルがあるい場合は".1"になるかもしれません。
2. NVEnc 7.31では、--vpp-afs等のインタレ解除フィルタについてYUV420で4の倍数でない場合は、エラーを出して修正するように変更しました。
3. --vpp-decimateの件は、いろいろなファイルを試してやっと発生させることに成功(?)したので、NVEnc 7.31で修正を試みましたので、一度お試しください。
https://rigaya34589.blog.fc2.com/blog-entry-1722.html