python中ffmpeg的管道输入和输出

python中ffmpeg的管道输入和输出,python,ffmpeg,Python,Ffmpeg,我正在使用ffmpeg从我导入ffmpeg的base64编码图像列表创建视频 输出到文件(使用下面附带的代码)非常有效,但我想实现的是将输出转换为Python变量——这意味着管道输入和管道输出,但我似乎无法让它工作 我当前的代码: output = os.path.join(screenshots_dir, 'video1.mp4') cmd_out = ['ffmpeg', '-y', # (optional) overwrite output file if it

我正在使用
ffmpeg
从我导入
ffmpeg
的base64编码图像列表创建视频

输出到文件(使用下面附带的代码)非常有效,但我想实现的是将输出转换为Python变量——这意味着管道输入和管道输出,但我似乎无法让它工作

我当前的代码:

output = os.path.join(screenshots_dir, 'video1.mp4')

cmd_out = ['ffmpeg',
           '-y',  # (optional) overwrite output file if it exists
           '-f', 'image2pipe',
           '-vcodec', 'png',
           '-r', str(fps),  # frames per second
           '-i', '-',  # The input comes from a pipe
           '-vcodec', 'png',
           '-qscale', '0',
           output]

pipe = sp.Popen(cmd_out, stdin=sp.PIPE)

for screenshot in screenshot_list:
    im = Image.open(BytesIO(base64.b64decode(screenshot)))
    im.save(pipe.stdin, 'PNG')

pipe.stdin.close()
pipe.wait()
这将导致mp4正常工作,但我希望避免保存到本地

输出
更改为
'-'
'pipe:1'
并添加
stdout=sp.pipe
时运行相同的代码会导致错误

[NULL@0x2236000]无法为“管道:”找到合适的输出格式


FFmpeg通过检查输出扩展来猜测输出复用器。对于管道,这是不存在的,因此必须明确设置。在输出之前添加
'-f',image2pipe'

尝试在
sp.Popen
之后添加以下命令:

output, _ = pipe.communicate()
我认为您需要与开放的流程进行沟通。之后,您可以打印它以确保它工作正常:

print(_)

无法帮助您完成python部分。只有ffmpeg。不管怎样,谢谢你,因为现在似乎正在工作。我会看看我是否真的捕捉到了它,并验证它是视频,如果是的话,我会接受它似乎永远卡在“流映射:流0:0->”0:0(png(本机)->png(本机))部分需要查看完整的ffmpeg控制台。您的输入终止了吗?