Extract Video Frames In Python

前端 未结 6 1224
别那么骄傲
别那么骄傲 2020-12-13 09:59

I want to extract video frames and save them as image.

import os, sys
from PIL import Image

a, b, c = os.popen3(\"ffmpeg -i test.avi\")
out = c.read()
dp =          


        
6条回答
  •  余生分开走
    2020-12-13 10:37

    import numpy as np
    import cv2
    
    
    capture = cv2.VideoCapture(0)
    size = (int(capture.get(3)),int(capture.get(4)))
    fourcc = cv2.VideoWriter_fourcc(*'XVID')
    video = cv2.VideoWriter('output.avi',fourcc,30,size)
    print capture.isOpened()
    num=0
    
    while True:
        ret, img = capture.read()
        video.write(img)
        cv2.imshow('video',img)
        cv2.imwrite("image" + str(num) + ".jpg",img)
        num = num + 1
        key= cv2.waitKey(1)
        if  key == ord('q')
            num=0
            break
    
    video.release()
    capture.release()
    cv2.destroyAllWindows() 
    

提交回复
热议问题