使用python进行视频图片提取

Python75

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

Python 版本 : 3.9.2_x64

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

```python;gutter:true;

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 :
i = i + 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的界面实现,具体代码见共享的资源文件。

附图:

文件列表:

使用python进行视频图片提取

命令行模式效果:

使用python进行视频图片提取

图形模式效果:

使用python进行视频图片提取

提取效果:

使用python进行视频图片提取

本文涉及资源下载地址:https://pan.baidu.com/s/1xhBxGnc8akC3UH70CyIDdw

可关注微信公众号(聊聊博文)后回复 2021101601 获得提取码。

Original: https://www.cnblogs.com/MikeZhang/p/pythonConvertVedioToImages.html
Author: Mike_Zhang
Title: 使用python进行视频图片提取