Last active
May 20, 2018 22:26
-
-
Save nyanshiba/cf9f2a4a073e191ad589bf24bec0ab7e to your computer and use it in GitHub Desktop.
最小構成
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 _EDCBX_DIRECT_ | |
rem _EDCBX_DONTHIDE_ | |
rem 視聴予約なら終了 | |
if "%RecMode%" == "4" ( | |
goto :eof | |
) | |
rem ファイル名をタイトルバーに表示 | |
title %~nx0:%FileName%.ts | |
rem ====================環境変数設定==================== | |
rem 一時的にmp4を吐き出すフォルダのパス | |
set "tmp_folder_path=C:\DTV\tmp" | |
rem backup and sync用フォルダのパス | |
set "bas_folder_path=C:\DTV\backupandsync" | |
rem エンコしたファイルが10GBより大きい、処理に25回失敗した場合にts、ts.program.txt、mp4を退避するフォルダのパス | |
set "err_folder_path=C:\Users\Shibanyan\Desktop" | |
rem ====================デュアルモノの判別==================== | |
rem 番組情報の中に"デュアルモノ"という文字列があれば環境変数"audio_option"に"-filter_complex channelsplit"を加え、音声ビットレートを半分にする | |
findstr "デュアルモノ" "%FilePath%.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 ====================エンコード==================== | |
rem ループ処理用 | |
set cnt=0 | |
:encode | |
rem 録画の開始終了でビジーなので負荷を減らすためにちょっと待つ | |
timeout /t 10 /nobreak | |
rem エンコ(%quality%は使用不可) | |
ffmpeg -y -hide_banner -nostats -init_hw_device qsv:hw -fflags +discardcorrupt -i "%FilePath%" %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 27 -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 -map 0:p:%SID10%:0 -map 0:p:%SID10%:1 -map 0:p:%SID10%:2 -sn -dn -ignore_unknown -movflags +faststart "%tmp_folder_path%\%FileName%.mp4" | |
rem 終了コードが1且つループカウントが25以下までの間、エンコードを試みる | |
if "%errorlevel%" equ "1" ( | |
if "%cnt%" leq "25" ( | |
set /a cnt+=1 | |
goto :encode | |
) else ( | |
goto :err | |
) | |
) | |
rem ====================mp4ファイルサイズ判別==================== | |
rem エンコ後mp4のサイズを環境変数"mp4_size"に指定 | |
for %%i in ("%tmp_folder_path%\%FileName%.mp4") do ( | |
set mp4_size=%%~zi | |
) | |
rem 10GB=10737418240byte以下ならbackup and sync用フォルダ、より大きいなら10GB以上用フォルダへ(mp4が約40GBを超える場合は想定していない) | |
if %mp4_size:~0,-1% leq 1073741824 ( | |
move "%tmp_folder_path%\%FileName%.mp4" "%bas_folder_path%" | |
) else if %mp4_size:~0,-1% gtr 1073741824 ( | |
goto :err | |
) | |
rem 正常終了 | |
exit | |
:err | |
rem ffmpegによるエラーのみ対応、シンタックスエラーやコマンドプロンプトの不具合はここに到達しないのでログを参照されたし | |
rem エンコしたファイルが10GBより大きい、処理に25回失敗した場合にts、ts.program.txt、mp4を退避する | |
move "%FilePath%" "%err_folder_path%" | |
move "%FilePath%.program.txt" "%err_folder_path%" | |
move "%tmp_folder_path%\%FileName%.mp4" "%err_folder_path%" | |
rem 異常終了 | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment