【发布时间】:2017-05-16 09:11:45
【问题描述】:
我正在使用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,但我想避免保存到本地。
将output 更改为'-' 或'pipe:1' 并添加stdout=sp.PIPE 运行相同的代码会导致错误
[NULL @ 0x2236000] 无法为“管道:”找到合适的输出格式
【问题讨论】: