Thread Rating:
  • 2 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Guide] How to create animegrimoire encoding quality using HandBrakeCLI
#1
Information 
Show Contenttl;dr:

Gitlab: //gitlab/initramfs-0/animegrimoire

  1. Prepare your handbrake with fdk-aac included.
    Follow guidelines from handbrake documentation and see the gitlab link.
  2. clone animegrimoire.sh, +x it and put (or symlink) in your binary folder.
    mine was in ~/.local/bin/animegrimoire
  3. clone x264_Animegrimoire.json, put it somewhere and then copy it's path and put it inside animegrimoire.sh
    mine was in ~/.local/preset/x264_Animegrimoire.json
  4. download this font pack and extract it in your ~/.fonts folder and then run
    $ fc-cache -f -v
  5. Start encoding

How-to-use:

For normal Ongoing-type occasion, use:
     ./animegrimoire.sh [Ayylmaosubs] This anime title - 01 [720p].mkv

On BDs or if source file also have [CRC32] tag on it use:

     ./animegrimoire.sh [Ayylmaosubs] This anime title - 01 [720p][12345678].mkv NUM
=>./animegrimoire.sh [Ayylmaosubs] This anime title - 01 [720p][12345678].mkv 42

so the script only read character number 1-42 while ignoring CRC32 tag.


for other case, such as encoding whole folder with Fumikiri Jikan episode 1 to 12, you only need to do:

$ls -l
----------------------------------------------
[HorribleSubs] Fumikiri Jikan - 01 [720p].mkv
[HorribleSubs] Fumikiri Jikan - 02 [720p].mkv
[HorribleSubs] Fumikiri Jikan - 03 [720p].mkv
[HorribleSubs] Fumikiri Jikan - 04 [720p].mkv
[HorribleSubs] Fumikiri Jikan - 05 [720p].mkv
[HorribleSubs] Fumikiri Jikan - 06 [720p].mkv
[HorribleSubs] Fumikiri Jikan - 07 [720p].mkv
[HorribleSubs] Fumikiri Jikan - 08 [720p].mkv
[HorribleSubs] Fumikiri Jikan - 09 [720p].mkv
[HorribleSubs] Fumikiri Jikan - 10 [720p].mkv
[HorribleSubs] Fumikiri Jikan - 11 [720p].mkv
[HorribleSubs] Fumikiri Jikan - 12 [720p].mkv
--------------------------------------------------

use a for loops:
Code:
$ for FILE in *.mkv; do animegrimoire $FILE; done


This json is also usable if you prefer to stay in GUI, just clone and import it to your HandBrake
The script is also can be used to upload file output once it's finished encoding using rclone. just define your rclone.conf and you're set.


Important: preset reference
[OK] make sure Handbrake has identical bitrate output to MeGUI preset 
[OK] make sure progressive deinterlacing works fine
[OK] make sure x264 animation tuning works fine 
[OK] make sure it has 2 pass, speeding up in first pass is acceptable without Fast decode / fast 1-st pass 
[OK] make sure it could handle subtitle nicely, include multi-layer subtitle with color effects (happens often in BD sources)
[OK] make sure it's x264 doesn't do 10-bit by accident, it's ever happens and really slow down encoding process 
[OK] make sure watermarking works fine (like, the old cyber12.ass to put animegrimoire.org)
[OK] make sure chapter embedding works fine, again for BD cases 
[OK] make sure force-stereo works fine, BD sometimes has 5.1 and you need nobrain workaround with native tools 
[OK] make sure it doesn't use hardware (GPU) acceleration is pure CPU encoding
[OK] make sure picture filtering works

Show ContentFAQ:

Show Contentspecial thanks for:
Reply
#2
DL: Magenta
passwd: EeaImhxa208qMSQxMy5f


I tried this script. works nice
Show Content:

Result:

Code:
General
Complete name                  : [HandBrakeCLI] Azur Lane - 04 [720p][39DF8F14].mp4
Format                        : MPEG-4
Format profile                : Base Media / Version 2
Codec ID                      : mp42 (isom/iso2/avc1/mp41)
File size                      : 101 MiB
Duration                      : 23 min 58 s
Overall bit rate              : 588 kb/s
Encoded date                  : UTC 2019-10-25 09:38:26
Tagged date                    : UTC 2019-10-25 09:38:26
Writing application            : HandBrake 20191024185003-401f7a3-master 2019102501

Video
ID                            : 1
Format                        : AVC
Format/Info                    : Advanced Video Codec
Format profile                : High@L4.1
Format settings, CABAC        : Yes
Format settings, RefFrames    : 10 frames
Codec ID                      : avc1
Codec ID/Info                  : Advanced Video Coding
Duration                      : 23 min 58 s
Bit rate                      : 550 kb/s
Width                          : 1 280 pixels
Height                        : 720 pixels
Display aspect ratio          : 16:9
Frame rate mode                : Variable
Frame rate                    : 23.976 (24000/1001) FPS
Minimum frame rate            : 23.974 FPS
Maximum frame rate            : 23.981 FPS
Color space                    : YUV
Chroma subsampling            : 4:2:0
Bit depth                      : 8 bits
Scan type                      : Progressive
Bits/(Pixel*Frame)            : 0.025
Stream size                    : 94.4 MiB (94%)
Writing library                : x264 core 157 r2980 34c06d1
Encoding settings              : cabac=1 / ref=10 / deblock=1:0:0 / analyse=0x3:0x133 / me=umh / subme=7 / psy=1 / psy_rd=0.40:0.00 / mixed_ref=1 / me_range=24 / chroma_me=1 / trellis=1 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=-2 / threads=12 / lookahead_threads=3 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=5 / b_pyramid=2 / b_adapt=2 / b_bias=0 / direct=3 / weightb=1 / open_gop=0 / weightp=2 / keyint=240 / keyint_min=24 / scenecut=40 / intra_refresh=0 / rc_lookahead=60 / rc=2pass / mbtree=1 / bitrate=550 / ratetol=1.0 / qcomp=0.60 / qpmin=10 / qpmax=51 / qpstep=4 / cplxblur=20.0 / qblur=0.5 / vbv_maxrate=62500 / vbv_bufsize=78125 / nal_hrd=none / filler=0 / ip_ratio=1.40 / aq=2:0.60
Encoded date                  : UTC 2019-10-25 09:38:26
Tagged date                    : UTC 2019-10-25 09:38:26
Color range                    : Limited
Color primaries                : BT.709
Transfer characteristics      : BT.709
Matrix coefficients            : BT.709

Audio
ID                            : 2
Format                        : AAC
Format/Info                    : Advanced Audio Codec
Format profile                : HE-AACv2 / HE-AAC / LC
Codec ID                      : 40
Duration                      : 23 min 58 s
Bit rate mode                  : Constant
Bit rate                      : 32.0 kb/s
Channel(s)                    : 2 channels / 2 channels / 2 channels
Channel positions              : Front: L R / Front: L R / Front: L R
Sampling rate                  : 48.0 kHz / 48.0 kHz / 24.0 kHz
Frame rate                    : 23.438 FPS (1024 SPF)
Compression mode              : Lossy
Stream size                    : 5.49 MiB (5%)
Title                          : Stereo
Language                      : Japanese
Default                        : Yes
Alternate group                : 1
Encoded date                  : UTC 2019-10-25 09:38:26
Tagged date                    : UTC 2019-10-25 09:38:26

Soon i'll be uploading premade VM for this stuff. it uses XCP-ng as host, also usable in XenServer. you only need to import it, power it on, go to build-handbrake from home directory and compile your handbrake-cli. all dependencies already installed, it's ready to go.

Code:
# xe vm-import filename="Fedora 30 Server x64.xva"

"Fedora 30 Server x64.xva" SHA-1 = "3BAEFC67E7ABF689CDD8F8E07467E1948D0D62C8"

[!] Found a dead lynx link? Report!
Todo:
[1] see known ded links here
[2] we gonna kill download link every 29days and regenerate it later. this fucking dead forum doesn't need perma link and we need more user interaction
Reply
#3
[Image: Animegrimoire-Handbrake.png]
(click img to see full size)
Reply
#4
Do you want windows bat file version of your script?
¯\_(ツ)_/¯
Reply
#5
(24 October 2019, 01:42 AM)Lynx Wrote: Do you want windows bat file version of your script?

Sure

does windows has rename and rhash native tool though

edit: as long as it has same result it's ok i guess
Reply
#6
(24 October 2019, 02:59 AM)Internet Explorer Wrote: Sure

does windows has rename and rhash native tool though

edit: as long as it has same result it's ok i guess
I will edit it for now to match your results
¯\_(ツ)_/¯
Reply
#7
if you don't find any of those native functionality in batch, consider looking up Powershell scripting, iirc the even have alternative for sed awk grep

[!] Found a dead lynx link? Report!
Todo:
[1] see known ded links here
[2] we gonna kill download link every 29days and regenerate it later. this fucking dead forum doesn't need perma link and we need more user interaction
Reply
#8
(25 October 2019, 05:54 AM)Lynx Wrote:
(24 October 2019, 02:59 AM)Internet Explorer Wrote: Sure

does windows has rename and rhash native tool though

edit: as long as it has same result it's ok i guess
I will edit it for now to match your results

for now make the basic function works first (encoding with preset quality and watermark), once you make a draft for the batch we could look on it together


(25 October 2019, 05:58 AM)Legendary Aurora Wrote: if you don't find any of those native functionality in batch, consider looking up Powershell scripting, iirc the even have alternative for sed awk grep



i ever saw portable executable version of gnu coreutils, but i forgot the name smh
imo we're better to use batch first while using additional portable .exe is okay, then powershell as alternative for later.
Reply
#9
I'm done!
This is the basic version on windows, using BAT file
animegrimoire.bat
Code:
@echo off

set filename=%~n1
set fullpath=%~f1

REM END FILE
set watermarkedFilename=[animegrimoire]%filename%

REM VARIABLE NAME
set underscoreFilename=%filename: =_%
set underscoreFilename=%underscoreFilename:[=%
set underscoreFilename=%underscoreFilename:]=%

set subtitle=%underscoreFilename%_subtitle
set subtitleTemp=%underscoreFilename%_temp_subtitle
set videoNoSubtitle=%underscoreFilename%_no_sub

REM WATERMARK
set watermarkStyle=Style: Watermark,Cambria,12,^^^&H00FFFFFF,^^^&H000000FF,^^^&H00000000,^^^&H00000000,0,1,0,0,100,100,0,0,1,2,1.2,9,10,10,10,1
set watermarkText=Dialogue: 0,0:00:00.00,0:00:02.00,Watermark,,0000,0000,0000,,animegrimoire.org

REM FOR SEARCHING LINE IN TEXT
set line1find=Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
set line2find=Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text

REM LIBRARY POSITIONS
set ffmpeg=.\lib\ffmpeg
set preset=.\lib\x264_animegrimoire.json
set handbrakeCLI=.\lib\HandBrakeCLI


REM ADD DIRECTORY FOR OUTPUT
if not exist .\temp mkdir .\temp
if not exist .\watermarked mkdir .\watermarked
if not exist .\encoded mkdir .\encoded

REM extract subtitle
%ffmpeg% -i "%fullpath%" -map 0:s .\temp\%subtitle%.ass -y

REM demux file, remove original subtitle
%ffmpeg% -i "%fullpath%" -map 0 -map 0:s -codec copy .\temp\%videoNoSubtitle%.mkv -y

REM add watermark, using powershell
@powershell -Command "get-content .\temp\%subtitle%.ass | %%{$_ -replace \"%line1find%\",\"%line1find%`r`n%watermarkStyle%\"}" >> .\temp\%subtitleTemp%01.ass
@powershell -Command "get-content .\temp\%subtitleTemp%01.ass | %%{$_ -replace \"%line2find%\",\"%line2find%`r`n%watermarkText%\"}" >> .\temp\%subtitleTemp%02.ass

REM send back watermark to mkv
%ffmpeg% -i .\temp\%videoNoSubtitle%.mkv  -i .\temp\%subtitleTemp%02.ass -c:v copy -c:a copy -c:s copy -map 0:0 -map 0:1 -map 1:0 -metadata:s:s:0 language=eng ".\watermarked\%watermarkedFilename%.mkv" -y

REM encode file
%handbrakeCLI% --preset-import-file %preset% -Z "x264_Animegrimoire" -i ".\watermarked\%watermarkedFilename%.mkv" -o ".\encoded\%watermarkedFilename%.mp4"

REM remove unnecessary file
del .\temp\%subtitle%.ass
del .\temp\%subtitleTemp%01.ass
del .\temp\%subtitleTemp%02.ass
del .\temp\%videoNoSubtitle%.mkv
del %fullpath%

for_all_file_in_folder_source_do_animegrimoire_script.bat
Code:
@echo off

for /f "delims=|" %%f in ('dir /b .\source\') do start cmd /k .\animegrimoire.bat ".\source\%%~nxf"

exit

this is the structure of the file
Code:
your_encoding_folder/
├── lib/
│   ├── ffmpeg.exe
│   ├── HandBrakeCLI.exe
│   └── x264_animegrimoire.json
├── source/
│   ├── file that you wanted to encode [01].mkv
│   └── [fansub] file that you wanted to encode - 02.mkv
├── animegrimoire.bat
└── for_all_file_in_folder_source_do_animegrimoire_script.bat

and to run that just double click that for_all_file_in_folder_source_do_animegrimoire_script.bat

do note that they encode parallel (AKA run for all file in source folder at the same time)

to run single file
Code:
animegrimoire.bat ".\source\file that you wanted to encode [01].mkv"
¯\_(ツ)_/¯
Reply
#10
(28 October 2019, 03:25 PM)Lynx Wrote: (...)

done adding them to gitl. if it's possible could you attach a short vid where you do a single encode on it?
even a cut one as long as it shows how to start it, in middle of process, and in end of encode is dine
Reply




Users browsing this thread: 1 Guest(s)