Page 1 of 1

Automate re-encoding numerous videos in a folder

Posted: Tue Aug 07, 2018 10:10 pm
by imthenachoman
Description of problem or question:
I have a folder with a lot videos. I want to use HandBrakeCLI to re-encode all of them using the "H.265 MKV 720p30" preset. I also want to:
  • include all of the audio tracks in the source video and, if necessary, down-mixed them to Stereo
  • include all of the sub-title tracks in the video and, if there is an SRT file in the folder with the same name as the source, then add that as an English subtitle track
I am looking through the command line options but not able to figure out which ones I need. Any help is greatly appreciated.

HandBrake version (e.g., 1.0.0):
1.0.1

Operating system and version (e.g., Ubuntu 16.04 LTS, macOS 10.13 High Sierra, Windows 10 Creators Update):
Ubuntu 18.04

Re: Automate re-encoding numerous videos in a folder

Posted: Sun Aug 12, 2018 4:10 am
by BradleyS
You'll probably want to bash script this since HandBrake won't automatically detect an SRT sidecar. Something like:

Code: Select all

for FILE in *.mkv; do
    SRT=""
    if [[ -e "${FILE%mkv}srt" ]]; then
        SRT="--srt-file=${FILE%mkv}srt --srt-codeset=utf-8 --srt-lang=eng"
    fi
    HandBrakeCLI -i "${FILE}" --preset-import-gui --preset="H.265 MKV 720p30" --audio-lang-list=und --all-audio --audio-copy-mask=mp3 --audio-fallback=mp3 "${SRT}" -o "${FILE%mkv}-encoded.mkv"
done
Untested, but should get you started.

Re: Automate re-encoding numerous videos in a folder

Posted: Wed Aug 15, 2018 2:06 am
by imthenachoman
Thank you. This worked for the most part. Goal was to have 2 hour movies be roughly 2 GB and it worked for like 70% of the videos. Need to figure out why the rest are still like 4-6 gigs.

I wish there were some documented "best" settings for HandBrakeCLI to get ~2 GB videos for archival purposes. :/

Re: Automate re-encoding numerous videos in a folder

Posted: Wed Aug 15, 2018 3:23 am
by BradleyS
Quality-based encoding causes the bit rate to vary, sometimes dramatically increasing in the case of complex, high motion, and/or noisy/grainy video. Most likely your larger encodes could benefit from some noise reduction.

You can also specify a target bit rate and 2-pass encoding if you want to achieve a specific size, but we generally do not recommend this except in limited scenarios. Storage is cheap.

Re: Automate re-encoding numerous videos in a folder

Posted: Thu Aug 16, 2018 1:59 am
by imthenachoman
How do I do noise reduction?

And I know storage is cheap but I'm trying to keep some very special videos as backup in a limited storage area as a worst-case scenario in case all my main backups fail.

Re: Automate re-encoding numerous videos in a folder

Posted: Thu Aug 16, 2018 2:03 am
by BradleyS
I'm working on a restoration section for the documentation, but it's going to be awhile. In the meantime, check the CLI --help: https://handbrake.fr/docs/en/1.1.0/cli/cli-guide.html

Probably want something like --nlmeans=light --nlmeans-tune=film (or tune high motion / animation / whatever your source content is).

Re: Automate re-encoding numerous videos in a folder

Posted: Thu Aug 16, 2018 2:08 am
by imthenachoman
Thank you. I will give it a try. Thanks!

Re: Automate re-encoding numerous videos in a folder

Posted: Thu Dec 27, 2018 4:57 pm
by cerickso88
I'm confused about the loop. What is the *.mkv?

My ISO rips are all in my z: drive. This scripts just drops out and does nothing.

Thanks

Re: Automate re-encoding numerous videos in a folder

Posted: Thu Dec 27, 2018 7:13 pm
by imthenachoman
The script loops through all of the mkv files in a folder. If all of your movies are in Z then you'll either need to update the script to look in Z or change to Z before you run the script.

Also, this script is for Linux and it sounds like you're on Windows. It won't work on Windows.

Re: Automate re-encoding numerous videos in a folder

Posted: Thu Dec 27, 2018 9:31 pm
by Woodstock
If you're dealing with ISO files of DVD or Bluray disks, they contain multiple titles on each, which will make it harder for a script to "just" do the "important" files. That is why most people extract the important video to other containers, with MKV being rather popular.

On the MakeMKV forum, users have contributed scripts to read ISO files and create MKV files, which would probably be the best first step in your process. You can specify a minimum length for titles to convert.