2

Here is the Python code:

import subprocess 

cmnd = ["ffmpeg", "-i", "/home/xincoz/test/connect.flv", "-acodec", "copy", "-ss", "00:00:00", "-t", "00:00:30", "/home/xincoz/test/output.flv"]

subprocess.call(cmnd)

Here I get the 30sec long video output file output.flv from connect.flv video. But i want to store that 30sec long binary data in a variable instead of copying that into an output file. How can I able to do that?

Please help me. Thanks a lot in advance.

4

1 回答 1

3

您必须告诉 ffmpeg 输出到 stdout 并告诉是否输出格式。然后从 python,正如@matino 所说,使用 Popen 读取写入标准输出的内容:

cmnd = ["ffmpeg", "-i", "/your/file.avi", "-acodec", "copy", "-ss", "00:00:00", "-t", "00:00:30", "-f", "avi", "pipe:1"]

p = subprocess.Popen(cmnd, stdout=subprocess.PIPE)

out, err = p.communicate()

print len(out) # print the length of the data received
于 2013-06-25T10:03:02.240 回答