python3--ffmpeg视频转换工具(一),,windows版本下
python3--ffmpeg视频转换工具(一),,windows版本下
windows版本下需要先安装ffmpeg工具:
1:先下载指定(https://ffmpeg.zeranoe.com/builds/) 有Static,Shared,Dev三个版本,
可以下载了static版本(是个zip压缩包),解压到指定目录,去配置环境变量,比如d:\ffmpeg\bin,这样bin下面的ffmpeg.exe就可以在命令行中使用了,可以用ffmpeg -version测试一下:2:安装ffmpeg的python扩展,该扩展可以让你直接在python脚本中直接调用,而不需要单独运行命令: pip install ffmpeg-python3:需要注意一点的是,有的情况调用该库会报错(‘ffmpeg‘ 不是内部或外部命令,也不是可运行的程序 或批处理文件。),这时需要将python安装目录下Lib文件夹的subprocess.py文件中大概656行中的shell参数改为True4:假如提示ffmpeg为外部命令错误时,将ffmpeg的路径带上:
代码如下:
def getImage(video_path):
base_path = os.path.join(os.path.join(os.getcwd(), "mp4"), video_path)
img_count = 1
crop_time = 0.0
try:
while crop_time <= 22.0: #转化22s的视频
os.system(‘D:\\ffmpeg-20191210-e73688e-win64-static\\bin\\ffmpeg -i %s -y -f image2 -ss %s %s.jpg‘% (base_path, str(crop_time), str(img_count)))
img_count += 1
crop_time += 0.01 #每0.01秒截取一张照片
print(‘视频转化完成!!!‘)
except Exception as e:
print(e)
def save():
dir_s = os.path.join(os.getcwd(), "image")
if os.path.exists(dir_s):
shutil.rmtree(dir_s)
os.mkdir(dir_s)
for root, dirs, tmps in os.walk(os.getcwd()):
for file in tmps:
if file.endswith("jpg") and os.path.exists(os.path.join(dir_s, file)) is False:
shutil.move(file, dir_s)
video_path = "of2.mp4"
getImage(video_path)
save()
python3--ffmpeg视频转换工具(一)
相关内容
- 在CentOS7中安装Python3,,查看系统原有Pyth
- python_封装redis_list方法,,xshell 进入
- python的list和数组的区别,,list不是数组(额
- python3发送邮件,,#163邮箱发送邮件
- Python3基础 filter与lambda表达式配合 筛选出1-100之间的奇
- 【PY】没有电影看?来教你用Python爬取电影天堂最新电
- pycharm默认的模板修改python script,,#!/usr/bin
- 在sublime编辑器中安装python,,了解如何在subli
- 准备工作——安装python和解析器,,1、安装python
- Pyton项目打包成exe文件,,Python项目打包
评论关闭