我正在使用ffmpeg从管道导入的base64编码图像列表创建视频ffmpeg。
输出到文件(使用下面的附加代码)可以完美地工作,但是我想实现的是将输出改为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()
Run Code Online (Sandbox Code Playgroud)
这会导致mp4正常工作,但我想避免保存到本地。
更改output为'-'或'pipe:1'添加并运行相同代码会stdout=sp.PIPE导致错误
[NULL @ 0x2236000]无法为'pipe:'找到合适的输出格式