从视频解码成图片-python小程序

import cv2
import os
import pdb
cap = cv2.VideoCapture('/data/geguojing/tracking/videos/19.mp4')
image_dir ='/data/geguojing/tracking/images/19'
fps =cap.get(cv2.CAP_PROP_FPS)
size = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)), int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
fourcc = cv2.VideoWriter_fourcc(*'XVID')
  

ii=0
while(cap.isOpened()):
    ret, frame = cap.read()   
    #ii=ii+1

    aa =str(ii)
    s = aa.zfill(6)
    image_name=os.path.join(image_dir+'/'+s+'.jpg')
    print(image_name)
    if ret==True:
       #cv2.imwrite(frame,image_name)
        cv2.imwrite(image_name,frame)

    else:
        break
    ii=ii+1
cap.release()


 

你可能感兴趣的:(python,小程序)