Tôi đang cố gắng sử dụng subprocess.Popen
để tạo chuỗi để lấy thời lượng của tệp video. Tôi đã tìm kiếm trong 3 ngày, và không thể tìm thấy bất cứ lý do trực tuyến là tại sao mã này không hoạt động, nhưng nó giữ cho tôi một kết quả trống:Sử dụng đúng subprocess.PIPE trong 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()
Tại sao bạn đang sử dụng grep, cắt và sed để phân tích đầu ra thay vì sử dụng các chức năng Python BUILTIN? –
[subprocess.PIPE] (http://thraxil.org/users/anders/posts/2008/03/13/Subprocess-Hanging-PIPE-is-your-enemy/) là kẻ thù của bạn – ldgorman