コードにはいくつかの問題があります。
- Popen への args リストには最後の引数
-i filename
があります。これは構文エラーであるため、'-i '+filename
代わりに使用します
shell=True
通常は不要であり、不必要な負担です。
それ以外は動作しているようですが、 #1 を修正した後に出力が表示されませんか?
編集:ffprobeコマンドラインに問題があるように見えるので、インストールして必要な変更は次のとおりです:
- 私の ffprobe (ffprobe 0.7.3-4:0.7.3-0ubuntu0.11.10.1) はフラグを受け入れないようです
-i
。入力ファイルは最後の引数として渡されます。
-loglevel
loglevel のオプションをquiet
個別の引数として渡す必要があります。[..., '-loglevel', 'quiet',..]
これらの変更後のサンプル スクリプトは次のとおりです。
#!/usr/bin/python
import os, sys, subprocess, shlex, re
from subprocess import call
def probe_file(filename):
cmnd = ['ffprobe', '-show_format', '-pretty', '-loglevel', 'quiet', filename]
p = subprocess.Popen(cmnd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print filename
out, err = p.communicate()
print "==========output=========="
print out
if err:
print "========= error ========"
print err
probe_file('drop.avi')
そして、正しい出力が表示されます。
==========output==========
[FORMAT]
filename=drop.avi
nb_streams=1
format_name=avi
format_long_name=AVI format
start_time=0:00:00.000000
duration=0:00:06.066667
size=660.000 Kibyte
bit_rate=891.217 Kbit/s
[/FORMAT]
========= error ========
ffprobe version 0.7.3-4:0.7.3-0ubuntu0.11.10.1, Copyright (c) 2007-2011 the Libav developers
built on Jan 4 2012 16:08:51 with gcc 4.6.1
configuration: --extra-version='4:0.7.3-0ubuntu0.11.10.1' --arch=amd64 --prefix=/usr --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --enable-zlib --enable-libvpx --enable-runtime-cpudetect --enable-vaapi --enable-gpl --enable-postproc --enable-swscale --enable-x11grab --enable-libdc1394 --enable-shared --disable-static
libavutil 51. 7. 0 / 51. 7. 0
libavcodec 53. 6. 0 / 53. 6. 0
libavformat 53. 3. 0 / 53. 3. 0
libavdevice 53. 0. 0 / 53. 0. 0
libavfilter 2. 4. 0 / 2. 4. 0
libswscale 2. 0. 0 / 2. 0. 0
libpostproc 52. 0. 0 / 52. 0. 0
Unsupported codec with id 114 for input stream 0