python video2ppt

Posted by XiLock on August 24, 2021

安装

install from pypi

pip install extract-video-ppt

or local

python ./setup.py install

or local user

python ./setup.py install --user

使用

evp --help
evp --similarity 0.6 --pdfname hello.pdf --start_frame 0:00:09 --end_frame 00:00:30 ./ ./test.mp4
  1. similarity: The similarity between this frame and the previous frame is less than this value and this frame will be saveed, default: 0.6
  2. pdfname: the name for export pdf
  3. start_frame: start frame time point, default = ‘00:00:00’
  4. end_frame: end frame time point, default = ‘INFINITY’

convert to exe

为了方便使用,使用pyinstaller转化成了exe文件,在转换过程中遇到以下问题:

提示ImportError: OpenCV loader: missing configuration file: ['config.py']. Check OpenCV installation

Solution:在pyinstaller时添加一下opencv的路径即可:pyinstaller -w xxx.py --paths="xxx\Lib\site-packages\cv2"

打包matplotlib出现RuntimeError: Could not find the matplotlib data files

现在的 matplotlib 版本都高于 3.2,而打包工具 pyinstaller需要低于 3.2 的版本,所以需要卸载 matplotlib,然后再安装低版本。

Solution:

pip uninstall matplotlib
pip install matplotlib==3.1.1
pyinstaller -F XXX.py

找到.spec文件(配置文件),将其中的hiddenimports=[]修改为hiddenimports=['matplotlib'],然后:

pyinstaller -F XXX.spec

此时再运行就可以了,虽然运行时会有Warning,但不影响。

参考资料

  1. github:extract ppt from a video
  2. Python pyinstaller打包opencv程序出错
  3. 打包matplotlib出现RuntimeError: Could not find the matplotlib data files

批处理

有时候视频比较多,需要批处理,用下面的代码批量转换:

import os

path = 'D:\Desktop\Captures video'
for root,dirs,names in os.walk(path):
	for name in names:
		ext = os.path.splitext(name)[1]
		nnn = os.path.splitext(name)[0]
		if ext == '.mp4':
			oName = name
			NName = nnn + '.pdf'
			s = "evp --similarity 0.8 --pdfname {0}.pdf --start_frame 0:00:00 --end_frame INFINITY ./ ./{1}.mp4".format(nnn,nnn)
			os.system(s)

有时候转换了一部分就因为别的事情要把程序停掉,这样的话,如果下次直接继续转换就会有重复,所以要先把已经转换完的pdf和mp4文件移到另一个文件夹里,可以用下面的代码:

import os
import shutil

path = 'D:\Desktop\Captures video'
npath = 'D:\Desktop\Captures video\converted'
if not os.path.exists(npath)
	os.makedirs(npath)
for root,dirs,names in os.walk(path):
	for name in names:
		ext = os.path.splitext(name)[1]
		nnn = os.path.splitext(name)[0]
		if ext == '.pdf':
			src = os.path.join(root,name)
			dst = os.path.join(npath,name)
			print('src',src)
			print('dst',dst)
			vname = nnn + '.mp4'
			src2 = os.path.join(root,vname)
			dst2 = os.path.join(npath,vname)
			print('src2',src2)
			print('dst2',dst2)
			shutil.move(src,dst)
			shutil.move(src2,dst2)


手机版“神探玺洛克”请扫码