先在 rosbag2video.py 脚本中修改相关配置参数.
然后运行脚本: python mp4_2_jpg.py
代码如下:
import cv2
vc = cv2.VideoCapture('/home/wsy/data/20220705/2022-07-05-10-53-31__camera0.mp4') # 读入视频文件,命名cv
n = 1 # 计数
if vc.isOpened(): # 判断是否正常打开
rval, frame = vc.read()
else:
rval = False
timeF = 50 # 视频帧计数间隔频率
i = 1
while rval: # 循环读取视频帧
rval, frame = vc.read()
if (n % timeF == 0 or n == 1): # 每隔timeF帧进行存储操作
frame = cv2.resize(frame, (1280, 720))
#frame = cv2.resize(frame, (800, 288))
#cv2.imwrite('./720P/2022-06-22-17-47-17_image{}.jpg'.format(i), frame) # 存储为图像
cv2.imwrite('./202207051053/202207051053-{}.jpg'.format(i), frame) # 存储为图像
print(i)
i += 1
n = n + 1
cv2.waitKey(1)
vc.release()