subprocess.Popen
을 사용하여 비디오 파일의 길이를 얻기 위해 시퀀스를 구성하려고합니다. 나는 3 일을 찾고 있었고,이 코드가 작동하지 않는 이유에 온라인 어떤 이유를 찾을 수 있지만, 그것은 나에게 빈 결과 제공 유지 : 마술를 연결하지 않습니다 subprocess.PIPE
를 사용python에서 subprocess.PIPE를 올바르게 사용하고 있습니까?
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()
왜 잘라 GREP을 사용하는 대신 내장 파이썬 함수를 사용하는 출력을 구문 분석 나오지입니까? –
[subprocess.PIPE] (http://thraxil.org/users/anders/posts/2008/03/13/Subprocess-Hanging-PIPE-is-your-enemy/)는 적입니다. – ldgorman