Skip to content

Instantly share code, notes, and snippets.

@alemonmk
Last active January 14, 2016 16:35
Show Gist options
  • Save alemonmk/08c91d58251893f53198 to your computer and use it in GitHub Desktop.
Save alemonmk/08c91d58251893f53198 to your computer and use it in GitHub Desktop.
My x265 encoding batch script
mode con:cols=100 lines=30
rem static start
rem Required programs
set ffmpeg=
set vspipe=
set mkvmerge=
set mediainfo=
set x265=
set mkvd=
set vpy=encode.vpy
rem static end
rem EP1 start, copy this section as much as you need
rem This is your BDMV/ folder
set bdmv=
rem The encoded filename
set name=ep1
rem Use %bdmv% and refer to your m2ts file, watch out for slashes
set m2ts=
CALL :DoEncode
rem EP1 end
EXIT /B 0
:DoEncode
SETLOCAL
FOR /F %%i in ('%mediainfo% --Output^=Video^;%%FrameCount%% "%m2ts%"') do set vframes=%%i
%ffmpeg% -hide_banner -loglevel panic -stats -y -threads 8 -analyzeduration 100M -probesize 100M -i "%m2ts%" -map 0:1 -vn -sn ^
-ac 2 -ar 48000 -acodec pcm_s16le -map_metadata -1 "%mkvd%%name%.wav"
%ffmpeg% -hide_banner -loglevel panic -stats -y -threads 8 -i "%mkvd%%name%.wav" ^
-acodec flac -compression_level 5 -sample_fmt s16 -aq 5 -ac 2 -ar 48000 "%mkvd%%name%.flac"
%ffmpeg% -hide_banner -loglevel panic -stats -y -threads 8 -i "%m2ts%" -r 24000/1001 -an -sn -f rawvideo -vsync 0 -pix_fmt yuv420p "%mkvd%%name%.yuv"
rem Parameter extract from anime released by VCB-S
%vspipe% %vpy% --arg "srcpath=%mkvd%%name%.yuv" - | %x265% ^
--input - --pools 8 --frames %vframes% ^
--output-depth 10 --input-depth 10 --input-res 1920x1080 --fps 24000/1001 ^
--profile main10 --no-high-tier --level-idc 5.1 ^
--vbv-maxrate 30000 --vbv-bufsize 28000 ^
--crf 15.500 --crf-max=0.0 --qcomp 0.80 ^
--qg-size 32 --tu-intra-depth 3 --tu-inter-depth 3 ^
--me 3 --subme 5 --merange 44 --max-merge 4 ^
--bframes 10 --weightb --b-intra --ref 5 ^
--limit-modes --no-strong-intra-smoothing --no-open-gop ^
--rc-lookahead 80 --lookahead-slices 0 ^
--rd 5 --rdpenalty 2 --psy-rd 0.800 --rdoq-level 1 --psy-rdoq 4.000 --aq-strength 1.100 ^
--deblock=-2:-2 --no-sao --keyint=720 --min-keyint=1 ^
--output "%mkvd%%name%.265"
ENDLOCAL
rem You need to extract chapter manually first
%mkvmerge% --ui-language en -o "%mkvd%%name%.mkv" ^
--chapter-charset UTF-8 --chapters "%mkvd%%name%.chp" ^
-d 0 --default-track 0:yes --default-duration 0:24000/1001fps --aspect-ratio-factor 0:1/1 --compression -1:none --forced-track 0:yes --no-audio --no-subtitles "%mkvd%%name%.265" ^
-a 0 --language 0:jpn --default-track 0:yes --forced-track 0:no --compression -1:none --no-video --no-subtitles --no-chapters "%mkvd%%name%.flac"
cd %mkvd%
del *.wav *.yuv *.265 *.flac
cd ..
EXIT /B 0
@alemonmk
Copy link
Author

Install Hybrid helps get you many parameter about the film and required programs easily

@alemonmk
Copy link
Author

Updated to use with latest encode.vpy
Extracts raw YUV file for preprocessing, and add command prompt resizing to avoid ffmpeg stats filling the screen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment