前回の記事から半年経ち、最近のモダン(?)なエンコ環境に慣れてきたので再度まとめてみる。

前提

  • Avisynth+ r2455
  • x264 r2762 x64

プラグインなど諸々全て64bit版を用意できるようになったので、avs4x26xなどのパイプツールは使いません。x264.exeは自ビルドしました。

BS11などの横1920ソースは、インタレを保持したまま横1440にリサイズします。横1920で製作されているアニメは数も少ないので、ファイルサイズを抑えるためにもリサイズしています。

CMカットを真面目にやるようになりました。自動CMカットツール、いくつか試してみましたが調整が結構面倒なので、結局今では目視でやっています。目視でも1分もかからないですし、誤爆の心配もありません。

.avs

SetFilterMTMode("DEFAULT_MT_MODE", MT_SERIALIZED)SetFilterMTMode("LWLibavVideoSource", MT_SERIALIZED)SetFilterMTMode("NNEDI3", MT_MULTI_INSTANCE)SetFilterMTMode("eedi3", MT_MULTI_INSTANCE)SetFilterMTMode("TDeint", MT_MULTI_INSTANCE)SetFilterMTMode("TFM", MT_MULTI_INSTANCE)SetFilterMTMode("TDecimate", MT_MULTI_INSTANCE)SetFilterMTMode("FluxSmoothST", MT_SERIALIZED)SetFilterMTMode("f3kdb", MT_MULTI_INSTANCE)video="___video___"audio="___audio___"v = LWLibavVideoSource(video, cache=true, dr=true, repeat=true, dominance=1).AssumeFPS(30000, 1001)v = v.AssumeTFF()v = (v.height() == 1088) ? v.Crop(0, 0, 0, -8) : vAudioDub(v, WAVSource(audio))# Trim# from 1920*1080 to 1440*1080#Resize4Interlaced(1440, 1080)# to progressive#TIVTC24PMod()# NR#FluxSmoothST(7, 7)# debanding#f3kdb(range=15, Y=96, Cb=64, Cr=64, sample_mode=2, blur_first=true, dynamic_grain=false, opt=-1, mt=true, dither_algo=3, keep_tv_range=true, input_mode=0, input_depth=8, output_mode=0, output_depth=8)#Histogram(mode="luma")#Info()Prefetch(4)return lastfunction Resize4Interlaced(clip clip, int width, int height, float "src_left", float "src_top", float "src_width", float "src_height"){src_left = default(src_left, 0)src_top = default(src_top, 0)src_width = default(src_width, 0)src_height = default(src_height, 0)clip = clip.TDeint(mode=1, order=1)clip = clip.Spline64Resize(width, height, src_left, src_top, src_width, src_height)clip = clip.AssumeTFF().SeparateFields().SelectEvery(4, 0, 3).Weave()return clip}function TIVTC24PMod(clip clip){src = clip.nnedi3(field=-1)interp = clip.eedi3(field=-1, sclip=src)deinted = clip.TDeint(order=-1, field=-1, edeint=interp)clip = clip.TFM(mode=6, order=-1, pp=7, slow=2, mChroma=true, clip2=deinted)clip = clip.TDecimate(mode=1)return clip}

バッチファイル

@echo offcd /d %~dp0echo.echo アニメエンコードバッチecho.rem ### 作業フォルダなど ###rem ====================================================set programPath=E:\Encode\set tempPath=F:\tmp_result\set completePath=Y:\video\rem ====================================================rem ### プログラムのパス ###rem ====================================================rem ### wavi.exe ###set wavi="%programPath%wavi106m\wavi.exe"rem ### fawcl.exe ###set fawcl="%programPath%FakeAacWav_0.28\fawcl.exe"rem ### x264.exe ###set x264="%programPath%x264\x264_2762_x64.exe"rem ### muxer.exe ###set muxer="%programPath%l-smash_r1450\muxer.exe"rem ### remuxer.exe ###set remuxer="%programPath%l-smash_r1450\remuxer.exe"rem ====================================================echo エンコード対象一覧echo ===================================================for %%f in (%*) do (  echo %%~nf)echo ===================================================echo.echo x264コンフィグ作成echo ===================================================set config=--min-keyint 1 --bframes 3 --b-adapt 2 --ref 3 --deblock 1:1 --rc-lookahead 40 --vbv-maxrate 40000 --vbv-bufsize 30000 --qpstep 12 --aq-mode 1 --aq-strength 0.6 --qcomp 0.80 --direct auto --me umh --psy-rd 0.4:0.0 --trellis 2 --no-fast-pskip --no-dct-decimate --range tv --nal-hrd vbr --input-range tv --level 4.1 --threads 0 --thread-inputset crf=23set /P crf="crf値を入力してください。デフォルトは「23」です。:"set /a isNumeric=%crf% * 1if not "%crf%"=="%isNumeric%" goto exceptionset config=%config% --crf %crf%set resolution=HDset /P resolution="解像度タイプを入力してください。デフォルトは「HD」です。(SD / HD):"if "%resolution%" == "SD" (set config=%config% --merange 16 --subme 7 --colorprim smpte170m --transfer smpte170m --colormatrix smpte170m) else if "%resolution%" == "HD" (set config=%config% --merange 24 --subme 6 --colorprim bt709 --transfer bt709 --colormatrix bt709) else (goto exception)set width=1440set /P width="横解像度を入力してください。デフォルトは「1440」です。(640 / 720 / 1440 / 1920):"if "%width%" == "640" (if "%resolution%" == "HD" goto exceptionset sar=1:1) else if "%width%" == "720" (if "%resolution%" == "HD" goto exceptionset sar=32:27) else if "%width%" == "1440" (if "%resolution%" == "SD" goto exceptionset sar=4:3) else if "%width%" == "1920" (if "%resolution%" == "SD" goto exceptionset sar=1:1) else (goto exception)set config=%config% --sar %sar%set framerate=30iset /P framerate="フレームレートを入力してください。デフォルトは「30i」です。(24p / 30i):"if "%framerate%" == "24p" (set config=%config% --keyint 240) else if "%framerate%" == "30i" (set config=%config% --keyint 300 --tff --weightp 0) else (goto exception)goto :continue:exceptionecho.echo 例外が発生しました。echo.pausegoto :eof:continueecho ===================================================echo.echo 内容の確認echo ===================================================echo 一時フォルダ:%tempPath%echo 保存フォルダ:%completePath%echo.echo x264:%x264%echo.echo config:%config%echo.set isOnlyVideo=set /P isOnlyVideo="映像のみをエンコードしますか?(y):"echo.set isShutdown=set /P isShutdown="終了後にシャットダウンしますか?(y):"echo.set isReady=set /P isReady="以上の内容でエンコードを開始します。キャンセルする場合は何かキーを押してください。"if not "%isReady%" == "" goto :eofecho ===================================================echo.rem ### ループ開始 ###:loopif "%~1" == "" goto endset name=%~n1set wav="%tempPath%%name%.wav"set aac="%tempPath%%name%.aac"set m4a="%tempPath%%name%.m4a"set avs="%tempPath%%name%.avs"set raw="%tempPath%%name%.264"set mp4="%tempPath%%name%.mp4"set complete="%completePath%%name%.mp4"echo wav抽出echo ====================================================if not "%isOnlyVideo%" == "y" (%wavi% %avs% %wav%)echo ====================================================echo.echo wav偽装解除echo ====================================================if not "%isOnlyVideo%" == "y" (%fawcl% %wav% %aac%)echo ====================================================echo.echo 音声muxecho ====================================================if not "%isOnlyVideo%" == "y" (%muxer% -i %aac% -o %m4a%)echo ====================================================echo.echo x264エンコードecho ====================================================%x264% %config% -o %raw% %avs%echo ====================================================echo.echo 動画muxecho ====================================================%muxer% -i %raw% -o %mp4%echo ====================================================echo.echo remuxecho ====================================================if not "%isOnlyVideo%" == "y" (%remuxer% -i %mp4% -i %m4a% -o %complete%)echo ====================================================echo.shiftgoto :loop:endif "%isShutdown%" == "y" shutdown -s -t 30pause