Reputation: 21682
For example I'm trying to run some bash command from python:
from subprocess import run
command = f'ffmpeg -y -i "{video_path}" "{frames_path}/%d.png"'
run(command, shell=True, check=True)
but if it fails I just get subprocess.CalledProcessError: Command 'ffmpeg ...' returned non-zero exit status 127.
how can I get full ffmpeg error message?
Upvotes: 1
Views: 373
Reputation: 633
It's the check=True
kwarg that's causing it to throw a CalledProcessError
. Just remove check=True
, and it will stop throwing the error. If you want to print the STDERR printed by ffmpeg, you can use capture_output=True
. Then, the resulting CompletedProcess
object will have a .stderr
member that contains the STDERR of your command, encoded as a bytes-like string. Use str.decode()
to turn it into a normal string:
from subprocess import run
command = f'ffmpeg -y -i "{video_path}" "{frames_path}/%d.png"'
proc = run(command, shell=True, capture_output=True)
out = proc.stdout.decode() # stores the output of stdout
err = proc.stderr.decode() # stores the output of stderr
print(err)
Upvotes: 1