Where's the CLI and other questions

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
normie100
Posts: 12
Joined: Thu Mar 23, 2023 5:54 am

Where's the CLI and other questions

Post by normie100 »

First question: I can't find the CLI in MacOS. Some code examples show it in a subdirectory to Handbrake (the GUI version), but on the Mac, Handbrake is a package that I put into Applications. When I look at the Package Contents, I don't see the CLI. Am I looking incorrectly? In the CLI documentation, there are hints that the CLI is DL'd separately, but I may be misinterpreting that, AND I don't see anyplace to DL the CLI for MacOS. Again, could be my error

PROBLEM STATEMENT: Ultimately what I'm trying to do is convert a bunch of WMVs to H264 MP4s with the same names (different extensions, of course) that are all in one folder. Using the GUI, I have to open one source at a time and then just hit Add to Queue. So much work.

So I want to use the CLI with wildcards, such as

HandbrakeCLI -i *.wmv --preset-import-gui -Z RK-WMV2MP4

Logically, this would process all files that have the WMV extension in the current directory (maybe I could say ./*.wmv). Since destination is not specified, the CLI simply uses the title of the input(s)--theoretically, this is in the indicated preset I imported from the GUI.

Should this work? Is there a way to do this through the GUI?

HandBrake version (e.g., 1.0.0): 1.6.X (latest)

Operating system and version : 13.5 Ventura

Thanks. BTW, I did a search for CLI on Mac to see if I could find where it's located, and I read the first three pages of CLI comments.

-normie-
User avatar
Ritsuka
HandBrake Team
Posts: 1659
Joined: Fri Jan 12, 2007 11:29 am

Re: Where's the CLI and other questions

Post by Ritsuka »

The CLI is a separate download, see the cli section on handbrake.fr Downloads page.
Deleted User 11865

Re: Where's the CLI and other questions

Post by Deleted User 11865 »

normie100 wrote: Sat Jul 29, 2023 2:18 am So I want to use the CLI with wildcards, such as

HandbrakeCLI -i *.wmv --preset-import-gui -Z RK-WMV2MP4

Logically, this would process all files that have the WMV extension in the current directory (maybe I could say ./*.wmv). Since destination is not specified, the CLI simply uses the title of the input(s)--theoretically, this is in the indicated preset I imported from the GUI.

Should this work?
No. HandBrakeCLI doesn't understand wildcards, and it doesn't have to, as the shell (e.g. bash or zsh) already has all the tools required and we're not going to re-invent the wheel.

Code: Select all

for i in *.wmv; do /path/to/HandBrakeCLI --preset-import-gui -Z RK-WMV2MP4 -i "$i" -o "${i%.wmv}.mp4" 2> "${i%.wmv}.log.txt"; done
For each file with extension wmv in the current directory, run HandBrakeCLI on said file with preset RK-WMV2MP4 imported from the GUI, output to a file with the same name but an mp4 extension and redirect the standard error stream (in the case of HandBrake, contains the encode log) to a file with the same name but extension log.txt

You can use HandBrakeCLI without the full path if it's in a folder that's in your PATH: https://en.wikipedia.org/wiki/PATH_(variable)

If it's in the same folder as the input, "./HandBrakeCLI" without quotes.

Redirection of standard error stream to a file: https://en.wikipedia.org/wiki/Redirecti ... le_handles

See "Substring Removal" section of https://tldp.org/LDP/abs/html/string-manipulation.html for how my example removes the .wmv extension and appends a new one.
rollin_eng
Veteran User
Posts: 4859
Joined: Wed May 04, 2011 11:06 pm

Re: Where's the CLI and other questions

Post by rollin_eng »

Or just open the folder in the GUI :wink:
normie100
Posts: 12
Joined: Thu Mar 23, 2023 5:54 am

Re: Where's the CLI and other questions

Post by normie100 »

Ritsuka wrote: Sat Jul 29, 2023 6:57 am The CLI is a separate download, see the cli section on handbrake.fr Downloads page.
THANK YOU. Normally, handbrake.fr takes me to the Mac OS DL so I didn't go to the DOWNLOADS page and see the CLI link. Very helpful.
normie100
Posts: 12
Joined: Thu Mar 23, 2023 5:54 am

Re: Where's the CLI and other questions

Post by normie100 »

rollin_eng wrote: Sat Jul 29, 2023 3:20 pm Or just open the folder in the GUI :wink:
This would be the magic I was looking for to use the GUI. Thanks tons. Having come from BAT files and unix wildcards, that was my first thought. I hope this works ;-)
normie100
Posts: 12
Joined: Thu Mar 23, 2023 5:54 am

Re: Where's the CLI and other questions

Post by normie100 »

@Rodeo

Thanks for teaching me how to fish. And it's nice to see that some of my assumed parameters were correct (i.e., getting the GUI preset).
normie100
Posts: 12
Joined: Thu Mar 23, 2023 5:54 am

Re: Where's the CLI and other questions

Post by normie100 »

Thanks for the pointer! Really drives home the usefulness of reading ALL of the documentation...
Deleted User 11865

Re: Where's the CLI and other questions

Post by Deleted User 11865 »

normie100 wrote: Sat Jul 29, 2023 8:12 pm @Rodeo

Thanks for teaching me how to fish. And it's nice to see that some of my assumed parameters were correct (i.e., getting the GUI preset).
TBH I didn't double-check, I copied it because it looked correct. If it doesn't work you'll at least have a log.txt file with hopefully some helpful message in it.
mduell
Veteran User
Posts: 8207
Joined: Sat Apr 21, 2007 8:54 pm

Re: Where's the CLI and other questions

Post by mduell »

rollin_eng wrote: Sat Jul 29, 2023 3:20 pm Or just open the folder in the GUI :wink:
But then you have to deal with the angry spaghetti.
Post Reply