HandBrakeCLI Batch File Issues

Discussion of the HandBrake command line interface (CLI)
Forum rules
An Activity Log is required for support requests. Please read How-to get an activity log? for details on how and why this should be provided.
Post Reply
Julamin
Posts: 2
Joined: Fri Nov 13, 2020 12:34 am

HandBrakeCLI Batch File Issues

Post by Julamin »

Description of problem or question:
So, I'm fairly new to HandbrakeCLI format and batch files, though I'm fairly experienced with coding in general. I have a bunch of TV shows that I would like to batch convert, and I thought that a batch file paired with HandbrakeCLI would be perfect. However, I'm being hit with an absolute mountain of errors. To start, here is my batch file script:

Code: Select all

FOR /F %%F IN ("%CD%") DO (
"C:\Program Files\Handbrake\HandBrakeCLI.exe" --preset-import-file "C:\Program Files\HandBrake\PresetList\presets.json" -Z "DS9 BTS" -i "%%F" -o "converted\%%F" -s "2" -S "English"
)
In my mind, this should do the following:

1) Iterate through all the files in the directory of the .bat file
2) For each file in the directory, run Handbrake with my custom preset, imported from a JSON (since for some reason Handbrake wasn't recognizing it, even though it is on the same computer), with the 2nd subtitle track and renaming it to English.

However, it does NOT do that at all.

First off, the current directory's path is "R:\Content\Star Trek\Shows\Deep Space Nine\Season 4\2 - Bonus Features", which should be grabbed by the %CD%. However, when the batch file tries to use it, it shows in CommandPrompt as "R:\Content\Star," meaning it is only grabbing the directory path up to the first space, even though I have enclosed it in double quotes. And since this isn't a valid directory, it breaks everything. It just errors out, says "No title found" and then "HandBrake has exited."

Second, I am also seeing a ton of "Incorrect value type" errors. Most of them are either "Incorrect value type for key PictureRotate. Converting.", "Incorrect value type for key AudioDitherMethod. Converting.", or "Incorrect value type for key x264Option. Converting." How do I fix these?

Between these two errors, I am unable to get any farther with the process, and any help would be very much appreciated. Thanks!


HandBrake version (e.g., 1.0.0):
HandBrake 1.3.3 (2020061300) - MinGW x86_64


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


HandBrake Activity Log ***required***
Since HandBrake isn't even getting started, there was no activity log to post.
Woodstock
Veteran User
Posts: 3843
Joined: Tue Aug 27, 2013 6:39 am

Re: HandBrakeCLI Batch File Issues

Post by Woodstock »

Ah, the joys of trying to get Windows shell scripting to work the way you think it should work. Or bash, for that matter.

The problem usually is that you're losing the quotes to take care of the spaces embedded in the paths.

I'd start with making sure your command line is working, and picking up the correct preset. Personally, I don't do the presets, I run all the settings as part of the command line, which eliminates one possible issue that you're seeing. I also put the paths in explicitly, so only the spaces in the file names have to be escaped properly. Examples here.

It's not so universal as what you're attempting to do, but easily editable for various series.
Julamin
Posts: 2
Joined: Fri Nov 13, 2020 12:34 am

Re: HandBrakeCLI Batch File Issues

Post by Julamin »

Thanks for the tips! I got some help from the FreeNode webchat (thanks BradleyS!), and I've managed to fix the problem. It was a whole lot of things in the end, but the important thing is that it all works properly now. Thanks to everyone that helped!
Post Reply