Skip to content

Instantly share code, notes, and snippets.

@oflow
Last active August 29, 2015 14:22
Show Gist options
  • Save oflow/50c5bc2f95d712dd3f94 to your computer and use it in GitHub Desktop.
Save oflow/50c5bc2f95d712dd3f94 to your computer and use it in GitHub Desktop.
フォルダに突っ込んだ *.ts ファイルをHandBrake (x264)でエンコードするやつ
@echo off
setlocal enabledelayedexpansion
rem set CLIPATH=C:\Program Files\Handbrake\HandBrakeCLI.exe
set CLIPATH=D:\bin\Handbrake\HandBrakeCLI.exe
set TSDIR=F:\ts
set MP4DIR=F:\ts\mp4
set ENDDIR=F:\ts\encoded_ts
set C2A=D:\bin\Caption2Ass\Caption2Ass_PCR.exe
set C2AOPT=-format srt -srtornament -delay -300
set NKF=D:\bin\nkf\nkf.exe
set NKFOPT=-wX --overwrite
rem nkf -wX (UTF-8, 半角カナ→全角カナ)
rem x264 preset faster: mixed-refs=0:ref=2:subme=4:weightp=1:rc-lookahead=20
rem fast: ref=2:subme=6:rc-lookahead=30
rem --encoder-tune="animation": ref*=2:deblock=1,1:psy-rd=0.4:aq-strength=0.6:bframes+=2
set X264OPT=--encopts me=umh:merange=32:ref=5:mixed-refs=1:subme=9:chroma-me=1:bframes=3:b-adapt=2:b-pyramid=2:b-bias=0:cabac=1:direct=auto:ipratio=1.4:qpmin=0:qpmax=69:qcomp=0.7:qpstep=12:trellis=2:mbtree=1:deblock=0,0:8x8dct=1:partitions=i8x8,p8x8,b8x8,i4x4:rc-lookahead=40:weightp=0:psy-rd=0.4:aq-mode=2:aq-strength=0.70:cqm=jvt:colorprim=bt709:transfer=bt709:colormatrix=bt709:fast-pskip=0:dct-decimate=0:min-keyint=4:keyint=300:scenecut=60:threads=8
rem --aencoder av_aac | fdk_aac
set VENCODE=--encoder x264 --encoder-preset=fast --encoder-level=4.1 --encoder-profile=high
rem set AENCODE=--aencoder fdk_aac --audio 1 --mixdown stereo -D 0 --gain 0 --audio-fallback ac3
set AENCODE=--aencoder fdk_aac --audio 1 --mixdown stereo --audio-fallback ac3
rem set VQ=--vb 1500
set VQ=--vb 1500 --two-pass --turbo
rem set VQ=--quality 19
set AQ=--arate Auto --ab 192
rem -U, --use-hwd (Use DXVA2) | --no-hwd
rem -P, --use-opencl (Use OpenCL) | --no-opencl
set OPT=--format mp4 --decomb --width 1280 --height 720 --non-anamorphic --crop 0:0:0:0 --modulus 16 --cfr --no-dvdnav --no-opencl --no-hwd --verbose=0
for %%f in (%TSDIR%\*.ts) do (
rem ファイル名(拡張子なし)
set name=%%~nf
set srtname=Z:\temp
set srtfile=!srtname!.srt
set tsfile=%TSDIR%\!name!.ts
"%C2A%" %C2AOPT% "!tsfile!" "!srtname!"
rem srtfileのファイルサイズみて小さかったら読み込まない
call :getFilesize "!srtfile!"
if !size! lss 1000 (
set srtopt=
set ext=.mp4
echo "no-subtitle"
) else (
"%NKF%" %NKFOPT% "!srtfile!"
set ext= [字].mp4
set srtopt=--srt-file "!srtfile!" --srt-codeset UTF-8 --srt-offset 0 --srt-lang jpn --srt-default 1
)
echo !srtopt!
"%CLIPATH%" -i "!tsfile!" -o "%MP4DIR%\!name!!ext!" %OPT% %VENCODE% %VQ% %X264OPT% %AENCODE% %AQ% !srtopt!
del "!srtfile!"
if !ERRORLEVEL! equ 0 (
echo Encoded: !tsfile!
move "!tsfile!" "%ENDDIR%\"
)
)
endlocal
exit /b 0
:getFilesize
if exist "%~1" (
set size=%~z1
) else (
set size=-1
)
exit /b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment