1

我正在使用 python 的 subprocess.popen 来获取视频文件的信息。

output = Popen('ffmpeg -i "'+avifile+'" -dframes 0 -vframes 0', 
    executable="/bin/bash", stdout=PIPE, stderr=STDOUT,
    shell=True).communicate()[0]

问题是每当我运行它时,当我知道应该有一些东西时,输出变量就是一个空字符串。我可以手动运行ffmpeg。

我在想这可能是管道和重定向的问题。想知道是否有人可以解决这个问题。

4

3 回答 3

0

我将变量 output 更改为 video_output 并且由于某种原因它起作用了。我完全没有为什么。

于 2013-05-20T05:49:04.287 回答
0
cmd = ['ffmpeg','-i',avifile,'-dframes','0','-vframes', '0']

output = Popen(cmd, 
    #executable="/bin/bash", ive never seen this used ... you may not need it
    stdout=PIPE, stderr=PIPE,
    shell=True).communicate()

试试吧,也许...

于 2013-05-20T05:25:47.370 回答
0

将组合的 stdout/stderr 读取为字符串并获取非零返回状态的异常:

from subprocess import STDOUT, check_output as qx

output = qx(['ffmpeg', '-i', avifile] + '-dframes 0 -vframes 0'.split(),
            stderr=STDOUT)

shell=True除非你需要,否则不要使用。

于 2013-05-20T05:36:07.983 回答