3

I have ffmpeg and ffprobe installed on my mac (macOS Sierra), and I have added their path to PATH. I can run them from terminal.

I am trying to use ffprobe to get the width and height of a video file using the following code:

import subprocess import shlex import json # function to find the resolution of the input video file def findVideoResolution(pathToInputVideo): cmd = "ffprobe -v quiet -print_format json -show_streams" args = shlex.split(cmd) args.append(pathToInputVideo) # run the ffprobe process, decode stdout into utf-8 & convert to JSON ffprobeOutput = subprocess.check_output(args).decode('utf-8') ffprobeOutput = json.loads(ffprobeOutput) # find height and width height = ffprobeOutput['streams'][0]['height'] width = ffprobeOutput['streams'][0]['width'] return height, width h, w = findVideoResolution("/Users/tomburrows/Documents/qfpics/user1/order1/movie.mov") print(h, w) 

I am sorry I cannot provide a MCVE, as I didn't write this code, and I don't really know how it works.

It gives the following error:

Traceback (most recent call last): File "/Users/tomburrows/Dropbox/Moviepy Tests/get_dimensions.py", line 21, in <module> h, w = findVideoResolution("/Users/tomburrows/Documents/qfpics/user1/order1/movie.mov") File "/Users/tomburrows/Dropbox/Moviepy Tests/get_dimensions.py", line 12, in findVideoResolution ffprobeOutput = subprocess.check_output(args).decode('utf-8') File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 626, in check_output **kwargs).stdout File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 693, in run with Popen(*popenargs, **kwargs) as process: File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 947, in __init__ restore_signals, start_new_session) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 1551, in _execute_child raise child_exception_type(errno_num, err_msg) FileNotFoundError: [Errno 2] No such file or directory: 'ffprobe' 

If python is not reading from the PATH file, how can I specify where ffprobe is?

Edit: It appears the python path is not aligned with my shell path. Using os.environ["PATH"]+=":/the_path/of/ffprobe/dir" at the beginning of each program allows me to use ffprobe, but why might my python path not be the same as my shell path?

1
  • To verify that it's indeed a $PATH related problem, why not give the full path instead of relying on the shell environment to do it for you? E.g. use cmd = "/full/path/to/ffprobe -v quiet -print_format json -show_streams" Commented Dec 22, 2016 at 22:14

1 Answer 1

2

You may use

import os print os.environ['PATH'] 

to verify/validate that ffprobe is in your python environment. According to the error you have, it is likely not.

Sign up to request clarification or add additional context in comments.

3 Comments

Yes, the output of your code does not have the path to ffmpeg that appears when I run 'echo $PATH' from the terminal. How do I update the python path then?
to temporary solve the issue, add the ffprobe path to the python environment, that is, add os.environ["PATH"]+=":/the_path/of/ffprobe/dir". However, you should consider why the python path is not aligned with your shell path.
@Burns: System PATH and Python PYTHONPATH have absolutely nothing to do with each other. You need to change PATH so that your command (ffmpeg) can be run from any directory. Google 'how to change PATH' for your particular shell.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.