这是Python代码:
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)
在这里,我从connect.flv视频获得30秒长的视频输出文件output.flv。但我想将30秒长的二进制数据存储在变量中,而不是将其复制到输出文件中。 我怎么能这样做?
请帮帮我。非常感谢。
答案 0 :(得分:1)
你必须告诉ffmpeg输出到stdout并告诉输出格式。然后从python中,如@matino所说,使用Popen来读取写入stdout的内容:
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