I'm very new
So this getLength function will run fine in python 2.7 but I can't get it to work in 3.10. Was wondering if anyone could suggest what may need to be changed because I am at a loss. When I try to print the return there is nothing there. I am 95% sure the issue is with the result = subprocess.Popen() line but I include the entire function for completeness
#function... returns the duration HH:MM:SS of a video file
def getLength(filename):
#uses ffprobe to get info about the video file
result = subprocess.Popen(["ffprobe", filename],
stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
#finds the info that has the word "Duration"
y = [x for x in result.stdout.readlines() if "Duration: " in x]
#get the location of the "Duration: " phrase
loc = y[0].find("Duration: ")
#assuming we find the location of that phrase..
if loc != -1:
#cut out everything before and everything more than 10 characters later
print ( y[0][loc+10:loc+18] )
return y[0][loc+10:loc+18]
else:
#if we don't find anything then set it to be 2 seconds of nothing...
print ( y[0][loc+10:loc+18] )
return '00:00:02'