ffmpeg 管道从 numpy 数组或 bgr24 字节生成 h264 块

问题描述

如果有人可以帮助我使用 FFmpeg 管道从 NumPy 数组生成 h264 块,是否有可能

这就是我现在正在做的:

过程 = ( ffmpeg .input('pipe:',format='rawvideo',pix_fmt='bgr24',s='{}x{}'.format(self._deeptwin.image_width,self._deeptwin.image_height)) .output(path,pix_fmt='yuv420p',vcodec='libx264',r=25) .overwrite_output() .run_async(pipe_stdin=True) )

for res in response:
    st = datetime.datetime.Now()
    print(f'{res.status} image {res.id} rendered at {datetime.datetime.Now()}')
    img = np.frombuffer(res.image,dtype=np.uint8)
    img = img.reshape((int(self._deeptwin.image_height * 1.5),self._deeptwin.image_width))
    img = cv2.cvtColor(img,cv2.COLOR_YUV2BGR_I420)
    
    for frame in img:
        start = datetime.datetime.Now()
        process.stdin.write(
            frame
            .astype(np.uint8)
            .tobytes()
        )
        end = datetime.datetime.Now()
    stop = datetime.datetime.Now()
    print(f'{res.id} conversion done at {stop-st}')
process.stdin.close()
process.wait()

` 目前正在做的是生成一个 out.h264 文件。没问题,也能播放正确的视频。

但是,我需要实现的是:我想以下列方式生成h264帧块:1.h264,2.h264............n.h264

任何指导都会非常感谢和帮助。

提前致谢。

解决方法

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

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

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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...