Sto provando a usare subprocess.Popen
per costruire una sequenza per afferrare la durata di un file video. Ho cercato per 3 giorni, e non riesco a trovare alcun motivo in linea sul motivo per cui questo codice non funziona, ma continua a darmi un risultato vuoto:Utilizzare correttamente subprocess.PIPE in python?
import sys
import os
import subprocess
def main():
the_file = "/Volumes/Footage/Acura/MDX/2001/Crash Test/01 Acura MDX Front Crash.mov"
ffmpeg = subprocess.Popen(['/opt/local/bin/ffmpeg', '-i', the_file], stdout = subprocess.PIPE,)
grep = subprocess.Popen(['grep', 'Duration'], stdin = subprocess.PIPE, stdout = subprocess.PIPE,)
cut = subprocess.Popen(['cut', '-d', ' ', '-f', '4'], stdin = subprocess.PIPE, stdout = subprocess.PIPE,)
sed = subprocess.Popen(['sed', 's/,//'], stdin = subprocess.PIPE, stdout = subprocess.PIPE,)
duration = sed.communicate()
print duration
if __name__ == '__main__':
main()
perché stai usando grep, sed tagliare e per analizzare l'output invece di utilizzare le funzioni di Python built? –
[subprocess.PIPE] (http://thraxil.org/users/anders/posts/2008/03/13/Subprocess-Hanging-PIPE-is-your-enemy/) è il tuo nemico – ldgorman