我们有一个系统,可以逐帧输出4通道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.135x,这对我们来说是一个巨大的瓶颈。早些时候,当我们将输入作为-pattern_type glob -i images/*.png
时,我们在单核上得到了大约1x-1.2x的输入。因此,我们的结论是,我们正受到stdin的制约,因此正在寻找通过多个来源传递输入的方法,或者以某种方式帮助ffmpeg
并行化这项工作-我们正在考虑的几个选项:
但我们无法让这两种方法都起作用,也无法接受任何其他解决方案。我会非常感谢你在这方面的帮助。谢谢
目前没有回答
相关问题 更多 >
编程相关推荐