:GETTEMPNAME
set TMPID=%RANDOM%
set TMPFILE=%~dp0avtemp-%TMPID%
if exist "%TMPFILE%.mkv" GOTO :GETTEMPNAME
"%~dp0mplayer2-vo-lavc.exe" "%~s1" -vo lavc -ovc libx264 -ovcopts preset=ultrafast,qp=50,profile=baseline -vf crop=32:32:0:0 -ao lavc -oac aac -o "%TMPFILE%.mkv"
"%~dp0mkvextract.exe" timecodes_v2 "%TMPFILE%.mkv" 1:"%TMPFILE%.tcf.txt"

set OUTFILE=%~dpn1.console%~2.mp4
set OUTFILETMP=%OUTFILE%
set TMPREQUIRED=0
"%~dp0x264_32_tMod-8bit-all.exe"  --frames 1 --preset ultrafast --output "%OUTFILE%" "%TMPFILE%.mkv" 2>NUL || set TMPREQUIRED=1
if %TMPREQUIRED% == 1 set OUTFILETMP=%~dpns1.console%~2.mp4

set X264DEV=dxva,ps3,xbox360
if "%~2" == "bluray" set X264DEV=%X264DEV%,bluray

"%~dp0Namedpipe.exe" \\.\pipe\Temp%TMPID%.y4m "%~dp0x264_32_tMod-8bit-all.exe"  --audiofile "%TMPFILE%.mkv" --acodec copy --crf 14 --preset veryfast --tune animation --aq-strength 0.8 --tcfile-in "%TMPFILE%.tcf.txt" --ref 9 --device %X264DEV% --output-csp i420 --output "%OUTFILETMP%" --stdin y4m - | "%~dp0mplayer2-vo-lavc.exe" "%~s1" -speed 4 -noframedrop -ass -vo yuv4mpeg:file=\\.\pipe\Temp%TMPID%.y4m -ao null
if %TMPREQUIRED% == 1 ren "%OUTFILETMP%" "%~n1.console%~2.mp4"

del "%TMPFILE%.mkv"
del "%TMPFILE%.tcf.txt"
