使用python进行视频图片提取

操作系统 : Windows 10 [版本 10.0.19043.1165]

Python 版本 : 3.9.2_x64

可以借助python代码使用opencv实现,命令行示例代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# python3
# pip install opencv-python numpy
 
import os,cv2
import numpy as np
 
def save_img(img,addr,num):
        naddr = "%s/%d.jpg" % (addr,num)
        ret = cv2.imwrite(naddr,img)
        #print("ret :",ret)
        return ret
 
srcFile = "./1.mp4"
dstDir = "./output"
 
if not os.path.isdir(dstDir):
        os.mkdir(dstDir)
 
videoCapture = cv2.VideoCapture(srcFile)
isOK,frame = videoCapture.read()
i=0
while isOK :
        = + 1
        if not save_img(frame,dstDir,i) :
                print("error occur!")
                break
        if (i+1)%100 == 1 :  print('save img:',i)
        isOK,frame = videoCapture.read()

  

也可以借助python的界面实现,具体代码见共享的资源文件。

转:https://www.cnblogs.com/MikeZhang/archive/2021/10/16/pythonConvertVedioToImages.html

posted @ 2023-02-28 15:39  rmticocean  阅读(125)  评论(0)    收藏  举报