I am trying to run a ffprobe command using a pre-defined by the user input file in Python. And then I will use the generated file by this command to report some parameters in a more organized view. My code is:
import subprocess
import json
cmd = "ffprobe -v quiet -print_format -show_format -show_streams /path/to/input/file.mp4 > output.json"
subprocess.call(cmd.split())
with open('output.json') as json_data:
data = json.load(json_data)
json_data.close()
d = float((data["streams"][0]["duration"]))
t = (data["streams"][0]["time_base"])
fps = [float(x) for x in t.split('/')]
print "==========================General=========================="
print "Name of the File: %s" %(data["format"]["filename"])
print "Duration: %.2f minutes" %(d/60)
print "Frame Rate: %d fps" %fps[1]
print "Bitrate: %.2f Mbps" %(float(data["format"]["bit_rate"])/1000000)
I was thinking to use: input_file = ("Please enter the path to your input file: ")
and then use the input_file in the ffprobe command on the second line of my code. But I am not sure how I can do it within the quotes. Please also note that the file name should also include an extension like input.mp4.