I’m relatively new to python and obviously new to stackoverflow. My goal is to create a file containing information about video files in my library: codecs, size, bitrate, and resolution, that I can easily parse. I plan to use this information to determine which video files are low enough quality to warrant replacement with better-looking encodes.
I found MediaInfo on sourceforge. My script recursively traverses a given directory and calls MediaInfo via subprocess. I resolved an earlier bug thanks to this thread on stackoverflow describing how to work around Windows permission errors. I also implemented code from this thread to hide the windows command prompt console, which was instantiated with every call to subprocess.
Currently, my code fails with the following error:
returned non-zero exit status 1
The current state of my script is below. Thanks in advance!
import os, subprocess
I speculate that the issue may lie with how i’ve formatted the strings which are passed to subprocess
types = [".avi", ".mp4", ".mkv"]
app = "MediaInfo.exe"
app_path = os.path.join("C:\Program Files\MediaInfo\MediaInfo_CLI_0.7.61_Windows_x64", app)
movie_dir = "L:\Movies"
current_file = ""
The below code launches subprocess without console windows
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
Recursively examine directories for media and analyze matching files
for root, dirs, files in os.walk(movie_dir):
for filename in files:
for extension in types:
if (filename.endswith(extension)):
current_file = '"' + os.path.join(root, filename) + '"'
output = subprocess.check_output([app, current_file],
executable=app_path,
stderr=subprocess.STDOUT,
startupinfo=startupinfo)
print app_path, current_file, output #debug
with open("out.txt", "a") as f:
f.write(output)
If you are on python 3 (and windows) and above, try using raw strings (or escaping backslashes on windows), OR use forward slashes in forming path! So instead of
Try using
And similarly ahead also in your script. I have also faced a lot of trouble with spaces in the string ‘C:\Program Files..’ and by not escaping the backslashes.