我们有一个系统可以输出 4 channel png
逐帧图像(我们也控制这些图像的输出格式,所以只要它支持透明度,我们就可以使用其他东西)。现在,我们正在等待所有图像,然后使用 ffmpeg
对它们进行编码。变成 webm
带有 vp8
的视频文件(libvpx
编码器)。但是我们现在希望将这些图像通过管道传输到 FFmpeg 以在图像被喷出的同时编码到 WebM 视频中,这样我们就不必等待 ffmpeg
之后对所有图像进行编码。
这是当前命令,使用 python 语法:
['/usr/bin/ffmpeg', '-hide_banner', '-y', '-loglevel', 'info', '-f', 'rawvideo', '-pix_fmt', 'bgra', '-s', '1573x900', '-framerate', '30', '-i', '-', '-i', 'audio.wav', '-c:v', 'libvpx', '-b:v', '0', '-crf', '30', '-tile-columns', '2', '-quality', 'good', '-speed', '4', '-threads', '16', '-auto-alt-ref', '0', '-g', '300000', '-map', '0:v:0', '-map', '1:a:0', '-shortest', 'video.webm']
# for ease of read:
# /usr/bin/ffmpeg -hide_banner -y -loglevel info -f rawvideo -pix_fmt bgra -s 1573x900 -framerate 30 -i - -i audio.wav -c:v libvpx -b:v 0 -crf 30 -tile-columns 2 -quality good -speed 4 -threads 16 -auto-alt-ref 0 -g 300000 -map 0:v:0 -map 1:a:0 -shortest video.webm
proc = subprocess.Popen(args, stdin=subprocess.PIPE)
以下是将图像传递给 FFMPEG proc stdin 的示例示例:# wait for the next frame to get ready
for frame_path in frame_path_list:
while not os.path.exists(frame_path):
time.sleep(0.25)
frame = cv2.imread(frame_path, cv2.IMREAD_UNCHANGED)
# put the frame in stdin so that it gets ready
proc.stdin.write(frame.astype(np.uint8).tobytes())
这个过程的当前速度约为 0.135 倍,这对我们来说是一个巨大的瓶颈。早些时候,当我们将输入设为 -pattern_type glob -i images/*.png
时我们在单核上得到了大约 1x-1.2x。因此,我们的结论是,我们正受到标准输入的限制,因此正在寻找通过多个来源传递输入或以某种方式帮助 ffmpeg
的方法。并行化这项工作 - 我们正在考虑的几个选项:但是我们无法让这些工作中的任何一个工作,也无法接受任何其他解决方案。将非常感谢这方面的帮助。谢谢!
最佳答案
你可以使用ffmpeg的-f image2pipe
选项,正如我发现的 here .例子:
cat frames/{0000..0512}.png | ffmpeg -f image2pipe -r 60 -i - -c:v libx265 video.mkv
关于python - 如何将与索引并行创建的多个图像通过管道传输到 ffmpeg,以便它可以匹配图像创建的速度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64025844/