I am new in Python and I am trying to get the duration (in seconds) of a file video by using ffprobe. Calling the following instruction
ffprobe -i video.mp4 -show_entries format=duration -v quiet -of csv="p=0"
on the CMD, I get the right result in seconds but if I call the same instruction in python by using:
import subprocess
duration = subprocess.call(['ffprobe', '-i', 'video.mp4', '-show_entries', 'format=duration', '-v', 'quiet', '-of', 'csv="p=0"'])
print duration
it returns 1. Is there a way to get the right result also through Python? Thank you in advance.
The problem is with the double quote argument
p=0
, format it using%
, also i changedsubprocess.call
tosubprocess.check_output
to store output of the command in a string :Output:
or you can otherwise do this: