Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert videos with all contained subtitles and audio into mp4 via commandline using handbrake

I'd like to convert my videos with Handbrake from mkv to mp4. But I want all audio files and subtitles contained in the mkv into the new mp4 container!

I use Handbrake 0.9.9 GUI because in this version you can predefine the amount of audio tracks and subtitles per default under preferences ('Add all remaining' / 'Add all'. Now i'd like to achive the same via HandBrakeCLI.

like image 815
MarcelHodan Avatar asked Mar 17 '23 05:03

MarcelHodan


1 Answers

Update: with Version 1.0.4 there are flags for that matter: --all-audio and --all-subtitles. See this link

The -a and --subtitle parameters don't have an option for all tracks, but extra tracks get ignored. So, to append (nearly) all contained audio tracks and subtitles from the source, you can just list more tracks than you'd expect to ever find in a source. The following CLI command does the trick for me.

HandBrakeCLI.exe -i <Path>\Episode01.mkv -o <Path>\Episode01.mp4 --preset Normal 
--subtitle scan,1,2,3,4,5,6,7,8,9,10 -a 1,2,3,4,5,6,7,8,9,10

This CLI command works with the presumption that my source files won't have more than 10 subtitles or audio files. I know that mine don't have more than 4 so I'm sure to include all.

I always use the --preset Normal to convert my videos. It suites my personal needs and came with HandBrake by default :) .The encode log file shows the following CLI command.

CLI Query:  -i "<PATH>\Episode01.mkv" -t 1 --angle 1 -c 1-12 -o "<PATH>\Episode01.mp4"  
-f mp4  -4  -w 720 --loose-anamorphic  --modulus 2 -e x264 -q 20 --vfr -a 1,2 -E faac,faac 
-6 dpl2,dpl2 -R Auto,48 -B 160,160 -D 0,0 --gain 0,0 --audio-fallback ffac3 
--subtitle scan,1,2 --markers="<AppData>\Local\Temp\Episode010-1-chapters.csv" 
--x264-preset=veryfast  --x264-profile=main  --h264-level="4.0"  --verbose=1

This CLI command contains the necessary -i (input) and -o (output) arguments and the rest are defined by --preset Normal

like image 77
MarcelHodan Avatar answered Apr 28 '23 20:04

MarcelHodan