decord 视频加载库;读取及保存帧
作者:互联网
参考:https://github.com/dmlc/decord
https://www.bilibili.com/video/av843220125/
****安装: pip install decord
1、读取使用
from decord import VideoReader
from decord import cpu, gpu
vr = VideoReader('D:\clip4clip\msvd_data\YouTubeClips\_1vy2HIN60A_32_40.avi', ctx=cpu(0))
print('video frames:', len(vr))
加载指定帧
frames = vr.get_batch([1, 3, 5, 7, 9])
print(frames.shape)
2、保存帧为图片
plt.axis(‘off’) 去掉坐标
bbox_inches=‘tight’ 去掉左右空白
frame1 = vr[1].asnumpy()
from matplotlib import pyplot as plt
plt.imshow(frame1)
plt.axis('off')
plt.savefig("111.jpg", bbox_inches='tight')
标签:plt,读取,vr,video,decord,frames,import,加载 来源: https://blog.csdn.net/weixin_42357472/article/details/122808840