From Indie IT Wiki

Adding Chapter Names Markers

Create a text CSV file with the lines as below...

2,Question Time
3,Gerald The Gorilla
4,Game For A Laugh
5,Are You A Gay Christian
6,Baronet Oswald Ernald Mosley
8,The Devil - Is He All Bad
9,Kinda Lingers
10,The Two Ninnies
11,Cut Off Their Goolies
12,Supa Dupa

Run the command line to include the markers option as below...

HandBrakeCLI --input input.mkv --markers="input.csv" --preset 'Fast 480p30' --non-anamorphic --encoder-preset slow --quality 22 --deinterlace --lapsharp --chapters 1-2 --output 'output.mp4'

This will give you a mediainfo output like the following...

ID                                       : 4
Codec ID                                 : text
Duration                                 : 1 h 38 min
Language                                 : English
Encoded date                             : UTC 2021-01-04 01:59:04
Tagged date                              : UTC 2021-01-04 01:59:04
Menu For                                 : 1,2,3
00:00:00.000                             : Darts
00:04:38.240                             : Question Time
00:16:43.520                             : Gerald The Gorilla
00:25:33.760                             : Game For A Laugh
00:32:50.400                             : Are You A Gay Christian
00:35:06.240                             : Baronet Oswald Ernald Mosley
00:52:01.440                             : Origami
01:00:50.880                             : The Devil - Is He All Bad
01:10:40.320                             : Kinda Lingers
01:15:09.440                             : The Two Ninnies
01:23:06.080                             : Cut Off Their Goolies
01:35:19.200                             : Supa Dupa

Then you will able to jump to a particular chapter with a better idea of what is chosen.

This is particularly good for music videos, with the chapter names as the song titles :-)

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


Capture Log

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

HandBrakeCLI ... 2> hb-log.txt

HEVC H.265 X265


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 ...

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 ;-)


x265 [info]: using cpu capabilities: none!


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


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

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


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



Script to Cycle Through Folder

This will cyle through the MKV files in a folder and output MP4 files. Just remove the .mkv if you have different sorts of files to batch process.

SRC="/path/to/input folder"
DEST="/path/to/output folder"
HANDBRAKE_OPTIONS="--width 720 --height 576 --non-anamorphic --crop 0:0:0:0 --encoder x264 --encoder-preset veryslow --deinterlace --no-markers"
for FILE in "$SRC"/*.mkv
   filename=$(basename "${FILE}")
   echo "${HANDBRAKE_CLI} --input \""${FILE}"\" "${HANDBRAKE_OPTIONS}" --output \""${DEST}"/"${filename}".${DEST_EXT}\""
   #{HANDBRAKE_CLI} --input "${FILE}" ${HANDBRAKE_OPTIONS} --output "${DEST}"/"${filename}".${DEST_EXT}

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"



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


ffmpeg avconv CheatSheet


DVD Deinterlacing

Some of the older DVDs have the Interlacing scan type.

Scan type                                : Interlaced

When you use HandBrake to convert them in to smaller files, they will need to be run through the 'deinterlace' filter first otherwise you will get horrible combing effects.

HandBrakeCLI --input "file.mkv" --width 720 --height 576 --non-anamorphic --crop 0:0:0:0 --encoder x264 --encoder-preset placebo --deinterlace --no-markers --output "file.mp4"

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.


sudo apt-get install libfribidi-dev


emerge dev-libs/fribidi

Keeping Up To Date

sudo apt-get install snapd
sudo snap install cmake --classic

ERROR: Could not detect Ninja v1.5 or newer

sudo -i
pip3 install --upgrade ninja




sudo -i
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 libturbojpeg0-dev libjpeg-turbo8 libjpeg-turbo8-dev libvpx5 libvpx-dev
apt-get install python3
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py
pip3 install --upgrade pip
pip3 install --upgrade ninja
ninja --version
pip3 install --upgrade meson
meson --version
apt-get -y install libnuma1 libnuma-dev numactl
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
sudo make --directory=build install
HandBrakeCLI --version
HandBrakeCLI --help

To uninstall...

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


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


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.


Gentoo Linux Installation

su - root
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 
/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.