如何将与索引并行创建的多个图像传送到ffmpeg,使其与图像创建的速度相匹配?

问题描述

我们有一个系统逐帧输出4通道png图像(我们也控制这些图像的输出格式,因此我们可以使用其他东西,只要它支持透明度) 。目前,我们正在等待所有图像,然后使用ffmpegwebm编码器)将vp8编码为libvpx视频文件。但是,现在我们希望将这些图像通过管道传输到FFmpeg,以便在图像被喷出时同时编码为WebM视频,这样我们就不必等待ffmpeg之后对所有图像进行编码。

这是使用Python语法的当前命令:

['/usr/bin/ffmpeg','-hide_banner','-y','-loglevel','info','-f','rawvideo','-pix_fmt','bgra','-s','1573x900','-framerate','30','-i','-','audio.wav','-c:v','libvpx','-b:v','0','-crf','-tile-columns','2','-quality','good','-speed','4','-threads','16','-auto-alt-ref','-g','300000','-map','0:v:0','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来使这项工作并行化-我们正在考虑的一些选择:>

  • 以某种方式将其馈送到不同的管道并从其中读取ffmpeg。
  • 将新图像添加到ffmpeg而不重新编码整个视频,但是我们找不到直接提供输入图像的方法

但是我们还无法使其中任何一个正常工作,也无法接受任何其他解决方案。非常感谢您的帮助。谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)