-
-
Save nyanshiba/2da5f41550fd5e0d57d8ace7bed025a1 to your computer and use it in GitHub Desktop.
D&Dしたtsファイルorフォルダ内のtsファイルをエンコするバッチ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo on | |
rem 180521 | |
rem tsもフォルダ内のtsもD&Dでエンコするバッチ | |
rem ====================環境変数設定==================== | |
rem 出力フォルダのパス | |
set "optout_folder_path=C:\Users\sbn\Desktop" | |
rem ====================ファイルかフォルダを判別==================== | |
rem ファイル名の後ろ3文字が.tsならばファイル、それ以外ならばフォルダとみなす | |
set "FilePath=%~1" | |
if "%FilePath:~-3%" == ".ts" ( | |
rem ファイル名をタイトルバーに表示 | |
title ファイル:"%~nx1" | |
call :main "%~1" | |
) else ( | |
rem ファイル名をタイトルバーに表示 | |
title フォルダ:"%~nx1" | |
rem D&Dしたフォルダ内のTSファイルを順次処理するよう呼ぶ | |
for %%a in ("%~1\*.ts") do ( | |
call :main "%%a" | |
) | |
) | |
set /p hoge=ウィンドウを閉じるには何かキーを押してください . . . | |
exit | |
:main | |
rem ====================デュアルモノの判別==================== | |
rem 番組情報の中に"デュアルモノ"という文字列があれば環境変数"audio_option"に"-filter_complex channelsplit"を加え、音声ビットレートを半分にする | |
findstr "デュアルモノ" "%~1.program.txt" | |
if %errorlevel% equ 0 ( | |
set "audio_option=-c:a aac -b:a 128k -filter_complex channelsplit" | |
) else if %errorlevel% equ 1 ( | |
rem set "audio_option=-c:a copy -bsf:a aac_adtstoasc" | |
set "audio_option=-c:a aac -b:a 256k" | |
) | |
rem ====================ServiceIDの判別==================== | |
rem 番組情報ファイルからServiceIDのある行を抜き出し、区切り文字":""("で2番目のトークンを環境変数SID10に格納 | |
rem ServiceID:211(0x00D3)から211だけを抜き出す | |
for /f "tokens=2 delims=:(" %%a in ('findstr ServiceID "%~1.program.txt"') do ( | |
set SID10=%%a | |
) | |
rem ServiceIDが取得できなかった場合 | |
if not defined SID10 ( | |
set /p SID10=ServiceID^(10進数^)を入力: | |
) | |
rem ====================tsファイルサイズ判別==================== | |
rem TSファイルのサイズを環境変数"ts_size"に指定 | |
for %%i in ("%~1") do ( | |
set ts_size=%%~zi | |
) | |
rem 20GB=21474836480byte以下ならquality 26、より大きいなら28 | |
if %ts_size:~0,-1% leq 2147483648 ( | |
set quality=27 | |
) else if %ts_size:~0,-1% gtr 2147483648 ( | |
set quality=29 | |
) | |
rem ====================エンコード==================== | |
rem ループ処理用 | |
set cnt=0 | |
:encode | |
rem 録画の開始終了でビジーなので負荷を減らすためにちょっと待つ | |
timeout /t 10 /nobreak | |
rem エンコ | |
ffmpeg -y -hide_banner -fflags +discardcorrupt -i "%~1" %audio_option% -vf yadif=0:-1:1,hqdn3d=4.0,scale=1280:720:flags=lanczos+accurate_rnd,unsharp=3:3:0.5:3:3:0.5:0 -global_quality %quality% -c:v h264_qsv -preset:v veryslow -g 300 -bf 16 -refs 9 -b_strategy 1 -look_ahead 1 -look_ahead_downsampling off -pix_fmt nv12 -bsf:v h264_metadata=colour_primaries=1:transfer_characteristics=1:matrix_coefficients=1 -map 0:p:%SID10%:0 -map 0:p:%SID10%:1 -map 0:p:%SID10%:2 -sn -dn -ignore_unknown -movflags +faststart "%optout_folder_path%\%~n1_tsenc.mp4" | |
rem 終了コードが1且つループカウントが25以下までの間、エンコードを試みる | |
if "%errorlevel%" equ "1" ( | |
if "%cnt%" leq "25" ( | |
set /a cnt+=1 | |
goto :encode | |
) else ( | |
echo "%~1":25回ループしても終了コードが1でした | |
) | |
) | |
exit /b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment