HandbrakeCLI on Ubuntu with Python Errors

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
andreid
Posts: 2
Joined: Sat Apr 17, 2021 6:03 pm

HandbrakeCLI on Ubuntu with Python Errors

Post by andreid »

Description of problem or question:

I'm trying to write a program in python3 that uses handbrakecli on my ubuntu machine to recode some video.

I'm missing something stupid but I cannot for the life of me figure this out, and I've been at it for countless hours.
and no matter how I rearrange the " I get one of two errors, either handbrake says file not found or it cannot find my preset.

This exact command works perfectly from the command line.

Steps to reproduce the problem (If Applicable):

Here's the code:

Code: Select all

def convertvideo(input_file):
    hb_args = (" -i " + input_file + " -o " + handbraketempspace + " --preset-import-file "+handbrake_json_file_location + " -Z " + handbrake_profile_name)
    print (hb_args) # for debug only
    subprocess.Popen(handbrake + hb_args)
    return()
HandBrake version (e.g., 1.0.0):
1.3.0



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

Ubuntu 18.04 LTS


HandBrake Activity Log ***required*** (see How-to get an activity log)
Here's the specific error:

Code: Select all

Traceback (most recent call last):
  File "SubProcessing.py", line 161, in <module>
    finalvideo = convertvideo(sys.argv[2])
  File "SubProcessing.py", line 82, in convertvideo
    subprocess.Popen(handbrake + hb_args)
  File "/usr/lib/python3.8/subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.8/subprocess.py", line 1702, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: "/usr/bin/HandBrakeCLI -i /root/Alone-S02E01-Once_More_Unto_the_Breach_HDTV-720p.mkv -o /root/tmp/tempvideo.mkv --preset-import-file /mnt/media/PlexTestFiles/handbrake_presets.json -Z 'h.265_Hardware'"
mduell
Veteran User
Posts: 7439
Joined: Sat Apr 21, 2007 8:54 pm

Re: HandbrakeCLI on Ubuntu with Python Errors

Post by mduell »

Double check where you have HB installed.
User avatar
Rodeo
HandBrake Team
Posts: 12759
Joined: Tue Mar 03, 2009 8:55 pm

Re: HandbrakeCLI on Ubuntu with Python Errors

Post by Rodeo »

https://docs.python.org/3/library/subprocess.html#popen-constructor wrote:
On POSIX, if args is a string, the string is interpreted as the name or path of the program to execute. However, this can only be done if not passing arguments to the program.

Note: It may not be obvious how to break a shell command into a sequence of arguments, especially in complex cases. shlex.split() can illustrate how to determine the correct tokenization for args:
Post Reply