Using FFProbe in a Python script

I am new to python, this is my first real project, and I came to the checkpoint. I have a .wmv file, I use FFprobe to extract the duration in seconds from a .wmv file. When I run the following command in CMD:

ffprobe -i Video2.wmv -show_entries format=duration -v quiet -of csv="p=0" 

I get a successful exit.

However, when I use os.system, like this:

 os.system('ffprobe -i Video2.wmv -show_entries format=duration -v quiet -of csv="p=0"') 

I get the following output:

 'ffprobe' is not recognized as an internal or external command, operable program or batch file. 

This is very confusing, and I could not find a solution to this exact problem on the Internet, any input would be greatly appreciated.

0
source share
1 answer

Python cannot find ffprobe because it is not in your environment variables. This youtube video shows how to install it correctly, as well as this wikihow page (method 2), which I will give here:

Enabling FFmpeg on the command line

enter image description here Click the "Start" button and right-click "Computer." Select Properties from the context menu. In the "System" window, click the link "Advanced system settings" in the left frame.

enter image description here

Click the "Environmental Variables" button in the system properties window. It will be located at the bottom of the window.

enter image description here

Select the PATH entry in the "User Variables" section. This is located in the first frame in the "Environmental Variables" window. Click Change. In the "Variable Value" field, enter: c: \ ffmpeg \ bin after everything that is already written there. If you copied it to another drive, change the drive letter. Click OK to save the changes. If nothing is entered incorrectly on this screen, it may cause Windows to fail to boot correctly. If there is no PATH variables entry in the User record, click the Create button and create it. Enter PATH for the variable name. This method will allow FFmpeg for the current user. Other Windows users will not be able to run it from the line command. To enable it for of all, type: c: \ ffmpeg \ bin in the PATH entry in “System Variables.” Be very careful not to delete anything that is already in this variable.

enter image description here

Open a command prompt. Enter the command "ffmpeg -version". If the command line returns version information for FFmpeg, then the installation was successful, and FFmpeg can be obtained from anyone on the command line.

If you get "libstdc ++ -6" missing ", you may need to install the Microsoft Visual C ++ Redistributable Package, which is available for free to Microsoft.

I hope this helps.

Just a side note, I don’t think that os.system is the recommended way to invoke the command line, as it is no longer the case.

I would recommend something similar, using a subprocess instead (adapted from code here ):

 import subprocess import shlex import json def get_duration(file_path_with_file_name): cmd = 'ffprobe -show_entries format=duration -v quiet -of csv="p=0"' args = shlex.split(cmd) args.append(file_path_with_file_name) # run the ffprobe process, decode stdout into utf-8 & convert to JSON ffprobe_output = subprocess.check_output(args).decode('utf-8') ffprobe_output = json.loads(ffprobe_output) return ffprobe_output 
0
source

All Articles