用于将图像和深度保存和加载为H.264视频的模块
videoio的Python项目详细描述
视频:将图像序列保存/加载为H.264视频
一个小Python模块,用于将RGB和uint16(深度)帧保存和加载为H.264编码的视频
快速启动
保存/加载RGB帧:
importnumpyasnpfromvideoioimportvideosave,videoreadframes=np.random.random((20,200,400,3))#[framesNr, height, width, RGB]# Save to videovideosave("out.mp4",frames)# Load from videoframes=videoread("out.mp4")
按顺序读取帧:
^{pr2}$按顺序写入帧:
fromvideoioimportVideoWriterwriter=VideoWriter("out.mp4",resolution=(400,200))#[width, height]foriinrange(100):frame=get_frame()writer.write(frame)writer.close()
或者
withVideoWriter("out.mp4",resolution=(400,200))aswriter:foriinrange(100):frame=get_frame()writer.write(frame)
uint16 3D阵列的无损写入/读取(有助于保存以毫米为单位存储的深度帧,例如Kinect数据):
importnumpyasnpfromvideoioimportuint16save,uint16read# Generate 20 random depth framesdepth_frames=(np.random.random((20,200,400))*65535).astype(np.uint16)# Saveuint16save("out_depth.mp4",depth_frames)# Loaddepth_frames=uint16read("out_depth.mp4")
使用不同的压缩预设和不同的FPS以无损模式保存RGB帧:
videosave("out.mp4",frames,lossless=True,preset="veryfast",fps=10.5)
读取RGB帧并将其缩放到目标分辨率:
frames=videoread("in.mp4",output_resolution=(100,250))
先决条件
ffmpeg
启用libx264和ffprobe
(通常随ffmpeg一起提供)numpy
ffmpeg-python
安装
来自pip:
pip install videoio
来源:
git clone https://github.com/vguzov/videoio.git
python setup.py install
- 项目
标签: