【发布时间】:2014-10-12 20:07:32
【问题描述】:
我正在使用 ffmpeg 将视频转换为图像。这些图像然后由我的 Python 程序处理。本来我是用ffmpeg先把图片保存到磁盘,然后用Python一一读取。
这很好用,但为了加快程序速度,我试图跳过存储步骤,只处理内存中的图像。
我使用以下 ffmpeg 和 Python subproccesses 命令将输出从 ffmpeg 通过管道传输到 Python:
command = "ffmpeg.exe -i ADD\\sg1-original.mp4 -r 1 -f image2pipe pipe:1"
pipe = subprocess.Popen(ffmpeg-command, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
image = Image.new(pipe.communicate()[0])
然后我的程序可以使用图像变量。问题是,如果我从 ffmpeg 发送超过 1 个图像,所有数据都存储在这个变量中。我需要一种分离图像的方法。我能想到的唯一方法是在文件末尾(0xff,0xd9)上分割 jpeg 标记。这有效,但不可靠。
关于带有子进程的管道文件,我错过了什么。有没有办法从管道中一次只读取一个文件?
【问题讨论】:
标签: python ffmpeg subprocess pipe