HandBrake

From Indie IT Wiki
Jump to: navigation, search

Movie Qualities

  • 576p x264 aac (2 channels 160 kbps)
  • 720p x264 ac3 (6 channels 384 kbps)
  • 1080p x265 dts (6 channels 1500 kbps)

Picture Quality

https://handbrake.fr/docs/en/latest/workflow/adjust-quality.html

Capture Log

To capture HandBrake’s log messages to a file, simply redirect stderr:

HandBrakeCLI ... 2> hb-log.txt

HEVC H.265 X265

https://www.techspot.com/article/1131-hevc-h256-enconding-playback/page7.html

Single AC3 audio 1080p...

"/usr/local/bin/HandBrakeCLI" --input "input.mkv" --main-feature --crop 0:0:0:0 --encoder x265 --encoder-preset medium --quality 22 --audio-lang-list eng --first-audio --aencoder ac3 --ab 384 --mixdown 5point1 --output "output hb x265 1080p ac3.mp4"

Dual audio 720p...

/usr/bin/HandBrakeCLI --input "input.mkv" --main-feature --chapters 1 --maxWidth 1280 --maxHeight 720 --crop 0:0:0:0 --markers --encoder x265 --encoder-preset medium --audio 1,1 --aencoder faac,ac3 --ab 160,384 --output "output.mp4"

Single AAC audio 720p...

/usr/bin/HandBrakeCLI --input "input.mkv" --main-feature --chapters 1 --maxWidth 1280 --maxHeight 720 --crop 0:0:0:0 --markers --encoder x265 --encoder-preset medium --audio 1 --aencoder av_aac --ab 384 --output "output.mp4"

Possible --encopts ...

pmode:rd=4:tu-intra-depth=3:rdoq-level=2:early-skip:b-intra:limit-modes:aq-mode=2:aq-strength=1.0:qg-size=16:ipratio=1.38:pbratio=1.28:me=3:max-merge=3:weightb:bframes=6:rc-lookahead=50:ref=6:psy-rdoq=1.38:no-sao
X264 X265 TIMINGS AND SIZES
ENCODER CPU ASM * NVENC ** SOURCE DISC PRESET RESOLUTION QUALITY AUDIO SIZE TIME
x265 25% no no 21Gb BD medium 1080p 22 ac3 1.9Gb 86 hours
x264 25% no no 21Gb BD veryslow 720p 22 ac3 1.4Gb 18 hours
x264 50% no no 21Gb BD veryslow 720p 22 ac3 1.4Gb 6 hours
x264 50% no no 6Gb DVD veryslow 576p 22 ac3 1.0Gb 4 hours
x265 50% no no 21Gb BD medium 1080p 22 ac3 1.9Gb 43 hours
x265 50% no no 22Gb BD medium 1080p 22 dts 2.2Gb 43 hours
x265 75% yes no 26Gb BD medium 1080p 22 dts 4.1Gb 14 hours
h265 75% yes yes 26Gb BD medium 1080p 22 dts 19Gb 1 hour

* ASM is the technology which uses the CPU's built-in features and flags such as MMX, etc. I realised that I was not using them!

** NVENC - NVidiaENCoding using a GTX1050 graphics video card... TO COME ;-)

HOW TO FIX CPU CAPABILITIES NONE

x265 [info]: using cpu capabilities: none!

https://bitbucket.org/multicoreware/x265/src/tip/build/README.txt?at=default&fileviewer=file-view-default

UPDATE - 20181006 - After recompiling nasm 2.13.03 by hand, and recompiling x265 it now shows the correct CPU flags which it detects...

x265 --version
x265 [info]: HEVC encoder version 2.9
x265 [info]: build info [Linux][GCC 5.4.0][64 bit] 8bit
x265 [info]: using cpu capabilities: MMX2 SSE2Fast LZCNT SSSE3 SSE4.2 AVX XOP FMA4 FMA3 BMI1

HOW TO NVENC

Blacklist the built-in Ubuntu Nouveau driver...

sudo rmmod nouveau
sudo echo "blacklist nouveau" >>/etc/modprobe.d/blacklist.conf

Download and install the latest official stable Nvidia drivers for Linux...

Latest Long Lived Branch version: 390.87

sudo -i
wget http://us.download.nvidia.com/XFree86/Linux-x86_64/390.87/NVIDIA-Linux-x86_64-390.87.run
sh ./NVIDIA-Linux-x86_64-390.87.run
exit

Change the encoder option for HandBrake...

/usr/local/bin/HandBrakeCLI --input input.mkv --main-feature --no-markers --crop 0:0:0:0 --encoder nvenc_h265 --encoder-preset medium --quality 22 --audio 2 --aencoder copy:dts --subtitle none --output output.mp4

Subtitles

To add all the English subtitles...

HandBrakeCLI --input /dev/dvd --main-feature --audio-lang-list eng --aencoder faac,ac3 --ab 160,384 --subtitle-lang-list eng --all-subtitles --output "movie.mp4"

To add just the forced subtitles for the foreign speaking parts of a movie...

HandBrakeCLI --input /dev/dvd --main-feature --audio-lang-list eng --aencoder faac,ac3 --ab 160,384 --subtitle scan --subtitle-forced --native-language eng --output "movie.mp4"

Multiple Audio Tracks

If you transcode your movie with multiple audio tracks, then it will solve the problem of missing audio... because the old TV you are using with automatically use AAC Stereo 2 Channels, rather than AC-3 Surround 6 Channels. This works very well with Plex.

Below is an example which reads the DVD, selects the movie, makes sure we have the English audio track, create multiple audio tracks in AAC Stereo 2 Channels + copy the AC-3 (lossless) and output the file name with the correct naming format for Plex...

HandBrakeCLI --input /dev/dvd --main-feature --audio-lang-list eng --aencoder faac,copy:ac3 --output "Quantum Of Solace (2008).mp4"

Command Line Interface CLI

https://trac.handbrake.fr/wiki/CLIGuide

https://forum.handbrake.fr/viewforum.php?f=10

Script to Cycle Through Folder

#!/bin/bash
SRC="/path/to/source/files/"
DEST="/path/to/destination/files/"
DEST_EXT=mp4
HANDBRAKE_CLI=HandBrakeCLI
for FILE in "$SRC"/*
do
   filename=$(basename "$FILE")
   extension=${filename##*.}
   filename=${filename%.*}
   $HANDBRAKE_CLI -i "$FILE" -o "$DEST"/"$filename".$DEST_EXT
done

Latest Goalpost Moving X264 Command Line Settings

February 2017

/usr/bin/HandBrakeCLI --input "input.mkv" --maxWidth 1280 --maxHeight 720 --crop 0:0:0:0 --markers --encoder x264 --encoder-preset veryslow --encoder-tune film --encoder-profile high --encoder-level 3.1 --audio 1,1 --aencoder faac,ac3 --ab 160,384 --output "output.mp4"

https://handbrake.fr/docs/en/1.0.0/cli/cli-guide.html

Logging

HandBrakeCLI commands and options 2>/tmp/hb.log

https://trac.handbrake.fr/wiki/ActivityLogCLI

ffmpeg avconv CheatSheet

http://www.rodrigopolo.com/ffmpeg/cheats.php

DVD Transcode

Converting an ISO file to a standard definition 720x576 Matroska video file, keeping the 1024x576 display aspect, chapters and subtitles.

time HandBrakeCLI --input ~/Videos/Film.iso --encoder x264 --quality 18 --title 1 --audio 1 --aencoder copy --subtitle 1 --crop 0:0:0:0 --markers --custom-anamorphic --keep-display-aspect --output ~/Videos/Film.mkv

Blu-Ray Transcode

Find the correct (probably AC-3) audio track...

HandBrakeCLI --input "Movie.mkv" --title 0

Converting a Full HD Matroska video file to an Normal HD 1280x720 MP4 video file, x264 slow speed, no subtitles, with dual audio tracks from the first (and possibly only) audio track, tuned for an normal live action movie. This will take about 8 hours to encode...

HandBrakeCLI --input "movie.mkv" --main-feature --maxWidth 1280 --maxHeight 720 --crop 0:0:0:0 --markers --x264-preset slow --x264-tune film --audio 1,1 --aencoder faac,ac3 --ab 160,384 --subtitle none --output "movie.mp4"

Converting a Full HD Matroska video file to an Normal HD 1280x720 MP4 video file, x264 medium speed, no subtitles, with dual audio tracks, tuned for an animated movie. This will take about 6 hours to encode...

HandBrakeCLI --input "movie.mkv" --main-feature --maxWidth 1280 --maxHeight 720 --crop 0:0:0:0 --markers --x264-preset medium --x264-tune animation --audio 2,2 --aencoder faac,ac3 --ab 160,384 --subtitle none --output "movie.mp4"

The slower you can go, the better.

--x264-preset slowest

...will probably take about 12 hours to encode... but be stunning.

If you went one stage further and did 2-pass, then it would probably take about 24 hours to encode!

--two-pass --x264-preset slowest

Fix Missing Fribidi Libraries

HandBrake now requires the Fribidi Libraries, and so you need to install them in order to compile HandBrake.

Ubuntu

sudo apt-get install libfribidi-dev

Gentoo

emerge dev-libs/fribidi

Keeping Up To Date

NEWER

sudo add-apt-repository ppa:stebbins/handbrake-git-snapshots
sudo apt-get update
sudo apt-get install handbrake-cli

Thanks - https://handbrake.fr/docs/en/1.0.0/get-handbrake/download-and-install.html

NEW

NOW USING SELF COMPILED X264, X265, FDK-AAC LIBARIES

https://handbrake.fr/docs/en/latest/developer/build-linux.html

sudo apt-get install autoconf automake build-essential cmake git libass-dev libbz2-dev libfontconfig1-dev libfreetype6-dev libfribidi-dev libharfbuzz-dev libjansson-dev liblzma-dev libmp3lame-dev libogg-dev libopus-dev libsamplerate-dev libspeex-dev libtheora-dev libtool libtool-bin libvorbis-dev libxml2-dev m4 make nasm patch pkg-config python tar yasm zlib1g-dev
cd ~/Downloads
git clone https://github.com/HandBrake/HandBrake
cd HandBrake/
git pull
sudo ldconfig
make clean
./configure --force --verbose --launch-jobs=$(nproc) --launch --disable-gtk --enable-x265 --enable-fdk-aac --enable-nvenc
sudo make --directory=build install
HandBrakeCLI --help
HandBrakeCLI --version

To uninstall...

cd ~/Downloads/HandBrake
sudo make --directory=build uninstall

OLD

The wonderful software HandBrake only gets official releases once a year. In computing terms, this is a lifetime and all those marvellous advances in video jiggerypokery will be lost.

So, we install the latest SVN version that the programmers are working on today!

**UPDATE** But first we need some development libraries from the Ubuntu repositories:-

sudo apt-get install --yes libass-dev libtheora-dev libvorbis-dev libsamplerate0-dev

Now, we can install HandBrake...

cd ~/Downloads
rm -rf hb-trunk
svn checkout svn://svn.handbrake.fr/HandBrake/trunk hb-trunk
cd hb-trunk
rm -rf build/
./configure --force --launch --disable-gtk
cd build/
sudo make install

That's it! This will install the 12Mb binary file into /usr/local/bin/HandBrakeCLI

To test you have it working...

HandBrakeCLI --update

...and you will see the SVN version number...

[22:51:04] hb_init: checking for updates
[22:51:04] Using http://handbrake.fr/appcast_unstable.xml
[22:51:04] latest: 0.9.8 i686, build 2012071700
[22:51:05] hb_init: starting libhb thread
HandBrake svn5086 (2012112801) - Linux x86_64 - http://handbrake.fr
Your version of HandBrake is up to date.

Enjoy!

Gentoo Linux Installation

su - root
cd
emerge -q dev-libs/fribidi
svn checkout svn://svn.handbrake.fr/HandBrake/trunk hb-trunk
cd hb-trunk
WANT_AUTOMAKE="1.11" ./configure --launch --disable-gtk --force
cd build/
sudo make install

Limit CPU Usage On HandBrake

Install the package cpulimit...

sudo apt-get install cpulimit

Now you can limit the cpu usage by specifying the exact program name and the total percentage amount of all cores. The example below limits the cpu to a total usage of 80% (which is 20% each x 4 cores) for the program called HandBrakeCLI...

sudo cpulimit -e HandBrakeCLI -l80

Note this will dramatically increase the time for transcoding - instead of taking 2 minutes it took 10 minutes... but at least it kept the cpu from overheating!  :-)

paully@mythbuntu-server3:~$ cat /etc/init.d/cpulimit.sh 
#!/bin/bash
/usr/bin/cpulimit -b -e HandBrakeCLI -l 80 &>/dev/null
/usr/bin/cpulimit -b -e avconv -l 80 &>/dev/null
/usr/bin/cpulimit -b -e mencoder -l 80 &>/dev/null

/etc/rc2.d/S10cpulimit.sh -> /etc/init.d/cpulimit.sh*

Make Movies Louder

Use the new --gain option to increase the volume during transcoding...

HandBrakeCLI --help
       --gain <float>      Amplify or attenuate audio before encoding.  Does
                           NOT work with audio passthru (copy). Values are in
                           dB.  Negative values attenuate, positive values
                           amplify. A 1 dB difference is barely audible.